Skip to content

Instantly share code, notes, and snippets.

@rizqidjamaluddin
Created March 19, 2015 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizqidjamaluddin/5de7da8ae00e0956efc0 to your computer and use it in GitHub Desktop.
Save rizqidjamaluddin/5de7da8ae00e0956efc0 to your computer and use it in GitHub Desktop.
<?php
abstract class AbstractFactory {
public function getBindings() {
return [
Foo::class,
Bar::class
];
}
public function instantiate($binding) {
return new Whatever;
}
}
<?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