Last active
January 27, 2017 17:38
-
-
Save unstoppablecarl/e00ca4ceb4a60e505839155fa021d607 to your computer and use it in GitHub Desktop.
Revisions
-
unstoppablecarl revised this gist
Jan 27, 2017 . 1 changed file with 11 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,16 +2,16 @@ // 5.3 class Foo { protected $cache = false; protected $dep; public function __construct(Dep $dep, $cache = false) { $this->dep = $dep; $this->cache = $cache; } } app(Foo::class, ['cache' => true]); // 5.4 solution 1 @@ -24,20 +24,21 @@ public function __construct(Dep $dep, $cache = true) { // 5.4 solution 2 class Foo { protected $cache = false; protected $dep; public function __construct(Dep $dep, \Illuminate\Config\Repository $config) { $this->dep = $dep; $this->cache = $config->get('package.cache'); } } app(Foo::class); // 5.4 solution 3 class Foo { protected $cache = false; protected $dep; public function __construct(Dep $dep) { @@ -52,8 +53,9 @@ public function cache($value = null) { } } $this->app->bind(Foo::class, function ($app) { $obj = app(Foo::class); $cache = config('package.cache'); $obj->cache($cache); }); -
unstoppablecarl revised this gist
Jan 27, 2017 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,58 +2,58 @@ // 5.3 class Foo { protected $cache = true; protected $dep; public function __construct(Dep $dep, $cache = true) { $this->dep = $dep; $this->cache = $cache; } } app(Foo::class, ['cache' => false]); // 5.4 solution 1 $this->app->bind(Foo::class, function ($app) { $depClass = app(Dep::class); $cache = config('package.cache'); return new Foo($depClass, $cache); }); // 5.4 solution 2 class Bar { protected $cache = true; protected $dep; public function __construct(Dep $dep, \Illuminate\Config\Repository $config) { $this->dep = $dep; $this->cache = $config->get('package.cache'); } } // 5.4 solution 3 class Cam { protected $cache = true; protected $dep; public function __construct(Dep $dep) { $this->dep = $dep; } public function cache($value = null) { if ($value !== null) { $this->cache = $value; } return $this->cache; } } $this->app->bind(Cam::class, function ($app) { $obj = app(Cam::class); $cache = config('package.cache'); $obj->cache($cache); }); -
unstoppablecarl created this gist
Jan 27, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ <?php // 5.3 class Foo { protected $active = true; protected $dep; public function __construct(Dep $dep, $active = true) { $this->dep = $dep; $this->active = $active; } } app(Foo::class, ['active' => false]); // 5.4 solution 1 $this->app->bind(Foo::class, function ($app) { $depClass = app(Dep::class); $active = config('package.active'); return new Foo($depClass, $active); }); // 5.4 solution 2 class Bar { protected $active = true; protected $dep; public function __construct(Dep $dep, \Illuminate\Config\Repository $config) { $this->dep = $dep; $this->active = $config->get('package.active'); } } // 5.4 solution 3 class Cam { protected $active = true; protected $dep; public function __construct(Dep $dep) { $this->dep = $dep; } public function active($value = null) { if ($value !== null) { $this->active = $value; } return $this->active; } } $this->app->bind(Cam::class, function ($app) { $obj = app(Cam::class); $active = config('package.active'); $obj->active($active); });