5 * @link http://php-di.org/
6 * @copyright Matthieu Napoli (http://mnapoli.fr/)
7 * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
10 namespace DI\Definition\Helper;
12 use DI\Definition\DecoratorDefinition;
13 use DI\Definition\FactoryDefinition;
16 * Helps defining how to create an instance of a class using a factory (callable).
18 * @author Matthieu Napoli <matthieu@mnapoli.fr>
20 class FactoryDefinitionHelper implements DefinitionHelper
38 * @param callable $factory
39 * @param bool $decorate Is the factory decorating a previous definition?
41 public function __construct($factory, $decorate = false)
43 $this->factory = $factory;
44 $this->decorate = $decorate;
48 * Defines the scope of the entry.
50 * @param string $scope
52 * @return FactoryDefinitionHelper
54 public function scope($scope)
56 $this->scope = $scope;
61 * @param string $entryName Container entry name
62 * @return FactoryDefinition
64 public function getDefinition($entryName)
66 if ($this->decorate) {
67 return new DecoratorDefinition($entryName, $this->factory, $this->scope);
70 return new FactoryDefinition($entryName, $this->factory, $this->scope);