2 namespace Robo\Contract;
4 interface InflectionInterface
7 * Based on league/container inflection: http://container.thephpleague.com/inflectors/
9 * This allows us to run:
11 * (new SomeTask($args))
18 * (new SomeTask($args))
19 * ->setLogger($this->logger)
23 * The reason `inflect` is better than the more explicit alternative is
24 * that subclasses of BaseTask that implement a new FooAwareInterface
25 * can override injectDependencies() as explained below, and add more
26 * dependencies that can be injected as needed.
28 * @param \Robo\Contract\InflectionInterface $parent
30 public function inflect(InflectionInterface $parent);
33 * Take all dependencies availble to this task and inject any that are
34 * needed into the provided task. The general pattern is that, for every
35 * FooAwareInterface that this class implements, it should test to see
36 * if the child also implements the same interface, and if so, should call
37 * $child->setFoo($this->foo).
39 * The benefits of this are pretty large. Any time an object that implements
40 * InflectionInterface is created, just call `$child->inflect($this)`, and
41 * any available optional dependencies will be hooked up via setter injection.
43 * The required dependencies of an object should be provided via constructor
44 * injection, not inflection.
46 * @param InflectionInterface $child An object created by this class that
47 * should have its dependencies injected.
49 * @see https://mwop.net/blog/2016-04-26-on-locators.html
51 public function injectDependencies(InflectionInterface $child);