Upgrade to Pro — share decks privately, control downloads, hide ads and more …

5.5リリース直前 Laravel Container 使い方振り返り

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

5.5リリース直前 Laravel Container 使い方振り返り

Avatar for yuuki takezawa

yuuki takezawa

July 31, 2017

More Decks by yuuki takezawa

Other Decks in Technology

Transcript

  1. // Hogeͱॻ͍ͯ͋ͬͨΒHogeΛ͍ͩ͘͞ $this->app->bind(Hoge::class, function () { return new Hoge; });

    $this->app->bind(Hoge::class); // singletonͰ͍ͩ͘͞ $this->app->singleton(Hoge::class);
  2. class Piyo { private $hoge; private $fuga; public function __construct(Hoge

    $hoge, Fuga $fuga) { $this->hoge = $hoge; $this->fuga = $fuga; } }
  3. class HogeFugaPiyo { private $name = ‘’; public function __construct(Hoge

    $hoge) { $this->hoge = $hoge; } public function setName(string $name) { $this->name = $name; } }
  4. use Illuminate\Support\Manager; class StringManager extends Manager { protected $driver =

    ‘hoge’; public function getDefaultDriver() { return $this->driver; } protected function createHogeDriver() { return ‘hoge dayo’; } protected function createFugaDriver() { return ‘fuga dayo’; } }
  5. protected $manager; public function __construct(StringManager $manager) { $this->manager = $manager;

    } public function __invoke($id) { $manager = $this->manager->driver(‘hoge’); if($id === 1) { $manager = $this->manager->driver(‘fuga’); } dd($manager); }