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

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

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

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

Avatar for yuuki takezawa

yuuki takezawa

July 31, 2017
Tweet

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); }