Created
March 19, 2015 13:52
-
-
Save rizqidjamaluddin/5de7da8ae00e0956efc0 to your computer and use it in GitHub Desktop.
This file contains 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 characters
<?php | |
abstract class AbstractFactory { | |
public function getBindings() { | |
return [ | |
Foo::class, | |
Bar::class | |
]; | |
} | |
public function instantiate($binding) { | |
return new Whatever; | |
} | |
} |
This file contains 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 characters
<?php | |
class SomeServiceProvider extends ServiceProvider { | |
protected function bindFactory(AbstractFactory $f) { | |
foreach ($f->getBindings() as $binding) { | |
$this->app->bind($binding, function ($app) use ($f, $binding) { | |
return $f->instantiate($binding); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment