# cookiebot/3.11.3/addons/inc/Dependencies/DI/Definition/Helper/FactoryDefinitionHelper.php

Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA &amp; Google Consent Mode, version 3.11.3. 73 lines.

- Page: https://pluginprobe.com/plugins/cookiebot/3.11.3/code/addons/inc/Dependencies/DI/Definition/Helper/FactoryDefinitionHelper.php
- Raw: https://pluginprobe.com/plugins/cookiebot/3.11.3/raw/addons/inc/Dependencies/DI/Definition/Helper/FactoryDefinitionHelper.php
- Modified: 2021-03-23T11:49:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/cookiebot/3.11.3/code/addons/inc/Dependencies/DI/Definition/Helper/FactoryDefinitionHelper.php#L10-L20`.

```php
<?php
/**
 * PHP-DI
 *
 * @link      http://php-di.org/
 * @copyright Matthieu Napoli (http://mnapoli.fr/)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
 */

namespace Cybot\Dependencies\DI\Definition\Helper;

use Cybot\Dependencies\DI\Definition\DecoratorDefinition;
use Cybot\Dependencies\DI\Definition\FactoryDefinition;

/**
 * Helps defining how to create an instance of a class using a factory (callable).
 *
 * @author Matthieu Napoli <matthieu@mnapoli.fr>
 */
class FactoryDefinitionHelper implements DefinitionHelper
{
    /**
     * @var callable
     */
    private $factory;

    /**
     * @var string|null
     */
    private $scope;

    /**
     * @var bool
     */
    private $decorate;

    /**
     * @param callable $factory
     * @param bool     $decorate Is the factory decorating a previous definition?
     */
    public function __construct($factory, $decorate = false)
    {
        $this->factory = $factory;
        $this->decorate = $decorate;
    }

    /**
     * Defines the scope of the entry.
     *
     * @param string $scope
     *
     * @return FactoryDefinitionHelper
     */
    public function scope($scope)
    {
        $this->scope = $scope;
        return $this;
    }

    /**
     * @param string $entryName Container entry name
     * @return FactoryDefinition
     */
    public function getDefinition($entryName)
    {
        if ($this->decorate) {
            return new DecoratorDefinition($entryName, $this->factory, $this->scope);
        }

        return new FactoryDefinition($entryName, $this->factory, $this->scope);
    }
}

```
