Sets a factory.

@param string|array $factory A PHP callable reference

@return $this
341254
final public function factory($factory)
    {
        if (\is_string($factory) && 1 === substr_count($factory, ':')) {
            $factoryParts = explode(':', $factory);

            throw new InvalidArgumentException(sprintf('Invalid factory "%s": the "service:method" notation is not available when using PHP-based DI configuration. Use "[ref(\'%s\'), \'%s\']" instead.', $factory, $factoryParts[0], $factoryParts[1]));
        }

        $this->definition->setFactory(static::processValue($factory, true));

        return $this;
    }
114012
public function addFactory(string $key, string $factory): FactoryResolver
    {
        if (is_subclass_of($factory, ServiceFactoryInterface::class, true) === false) {
            throw new InvalidFactoryType($factory);
        }

        $this->factories[$key] = $factory;

        return $this;
    }
526754
public function setTypeConverterFactory(TypeConverterFactory $factory): self
    {
        $this->converterFactory = $factory;
        $factory->setConnection($this);

        return $this;
    }
456094
def set_factory(self, thing: type, value, overwrite=False):
        
        if thing in self.factories and not overwrite:
            raise DiayException('factory for %r already exists' % thing)
        self.factories[thing] = value
1340915
public static function toObservable(callable $factory)
    {
        $observableFactory = function () use ($factory) {
            return Promise::toObservable($factory());
        };

        return Observable::defer($observableFactory);
    }
1133858
public function setURIFactory($factory)
    {
        $reflector = new \ReflectionClass($factory);
        if (!$reflector->implementsInterface('\\Erebot\\URIInterface')) {
            throw new \Erebot\InvalidValueException(
                'The factory must implement \\Erebot\\URIInterface'
            );
        }
        $this->uriFactory = $factory;
    }
1325770
public static function setPuliFactory($puliFactory)
    {
        if (!is_callable([$puliFactory, 'createRepository']) || !is_callable([$puliFactory, 'createDiscovery'])) {
            throw new \InvalidArgumentException('The Puli Factory must expose a repository and a discovery');
        }
        self::$puliFactory = $puliFactory;
        self::$puliDiscovery = null;
    }
254265
public function setImageFactory($imageFactory)
    {
        if ($imageFactory instanceof Imageoptim || $imageFactory instanceof Optimus) {
            $this->imageFactory = $imageFactory;
        }

        return $this;
    }
1059606
protected function createFactory()
    {
        if (!class_exists($this->factoryClass)) {
            throw new RuntimeException(sprintf(
                'Failed to create an instance of non-existing factory class "%s".',
                $this->factoryClass
            ));
        }

        $class = $this->factoryClass;

        switch (count($this->args)) {
            case 0:
                $factory = new $class();
                break;

            case 1:
                $factory = new $class($this->args[0]);
                break;

            case 2:
                $factory = new $class($this->args[0], $this->args[1]);
                break;

            case 3:
                $factory = new $class($this->args[0], $this->args[1], $this->args[2]);
                break;

            case 4:
                $factory = new $class($this->args[0], $this->args[1], $this->args[2], $this->args[3]);
                break;

            default:
                $reflection = new ClassReflection($class);
                $factory = $reflection->newInstanceArgs($this->args);
                break;
        }

        if (!$factory instanceof FactoryInterface) {
            throw new LogicException(sprintf(
                'Invalid service factory. Factory is expected to be an instance of %s, %s given.',
                'Zend\ServiceManager\FactoryInterface',
                get_class($factory)
            ));
        }

        return $factory;
    }
888088
public function setConfig($config)
    {
        $this->config = $config;
        $this->factory = new Factory($config);
        $this->AssetBuild->setConfig($config);
    }
1262336
public function addFactory()
    {
        $args = func_get_args();

        if(0 === count($args) or count($args) > 3) {
            throw new \InvalidArgumentException("incorrect number parameters");
        }

        $definitionName = (1 === count($args)) ? $args[0] : $args[1];
        $factoryName = (1 === count($args)) ? ($args[0] . "Factory") : $args[0];
        $factoryScope = (count($args) < 3) ? "prototype" : $args[2];

        $config = [
            FactoryBuilderExtension::FACTORY_NAME => $factoryName,
            FactoryBuilderExtension::DEFINITION_NAME => $definitionName,
            FactoryBuilderExtension::FACTORY_SCOPE => $factoryScope
        ];

        $this->container->loadFromExtension(
            FactoryBuilderExtension::ALIAS,
            [$config]
        );

        return $this;
    }
1190057
public function setConfig(array $config)
    {
        $this->config = $config;

        if (array_key_exists(static::CONFIG_VARIANT_FACTORY, $config)) {
            $this->strategyFactory->setConfig(
                $config[ static::CONFIG_VARIANT_FACTORY ]
            );
        }

        return $this;
    }
761984
function(name, factory, object) {

                        var that = this;
                        var objects = this._resolveObjects(name, factory, object);

                        _.each(objects, function(factoryObjects, factory) {
                            _.each(factoryObjects, function(object, name) {
                                that._setObjectCreator([name], that._createObjectCreator(factory, object));
                            });
                        });

                        return this;
                    }
958130
public function remove($factory = null)
    {
        if (!($factory instanceof FactoryInterface)) {
            $factory = $this->find($factory);
        }

        $this->factories = array_values(array_filter($this->factories, function($f) use ($factory) {
            return $f !== $factory;
        }));

        return $this;
    }
63201
public function getRedisFactory(): ?Factory
    {
        if (!$this->hasRedisFactory()) {
            $this->setRedisFactory($this->getDefaultRedisFactory());
        }
        return $this->redisFactory;
    }
810452
public function addStorageFactory(StorageFactoryInterface $factory)
    {
        $factoryName = $factory->getName();
        if (empty($factoryName)) {
            throw new InvalidArgumentException(sprintf('The storage factory %s has empty name', get_class($factory)));
        }
        if (array_key_exists($factoryName, $this->storagesFactories)) {
            throw new InvalidArgumentException(sprintf('The storage factory with such name %s already registered', $factoryName));
        }

        $this->storagesFactories[$factoryName] = $factory;
    }
446630
public function addTo(Extendable $factory)
    {
        foreach ($this->aliases as $typeName => $rules) {
            foreach ($rules as $alias => $rule) {
                $factory->extend($alias, [$this, 'toType']);
            }
        }
    }