Set a factory to generate a value when the container is read.

@param string   $name    The name of the value
@param callable $factory Factory for the value
@throws FactoryUncallableException
498830
public function setFactory($name, $factory)
    {
        if (!is_callable($factory, true)) {
            throw new FactoryUncallableException('$factory must appear callable');
        }

        unset($this->cache[$name]);
        $this->factories[$name] = $factory;
    }
811852
public function bindFactory(string $name, $definition)
    {
        $this->definitions[$name] = new Factory($name, $definition);
        return $this;
    }
176266
public function setFactory(\Elcodi\Component\Core\Factory\Abstracts\AbstractFactory $factory)
    {
        $this->factory = $factory;

        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;
    }
201675
protected function createFromFactory($factory)
    {
        try {
            if (is_string($factory) && class_exists($factory)) {
                $factory = new $factory();
            }

            if (is_callable($factory)) {
                $service  = $factory($this);
            } else {
                throw new ContainerException(
                    'Service could not be created: "There were incorrectly '
                        . 'transmitted data when registering the service".'
                );
            }
        } catch (ContainerException $e) {
            throw $e;
        } catch (\Throwable $e) {
            throw new ContainerException(
                'Service could not be created: "Service factory may be '
                    . 'callable or string (that can be resolving to an '
                    . 'invokable class or to a FactoryInterface instance).'
            );
        }

        return $service;
    }
1153058
public function factory($name, array $args = array())
    {
        foreach ($this->factories as $factory) {
            $command = $factory->factory($name, $args);
            if ($command) {
                return $command;
            }
        }
    }
973378
public function setEntityFactory(EntityFactory $factory = null)
    {
        if ($factory === null) {
            $factory = new Entity();
        }
        $this->factory = $factory;
        return $this;
    }
1133582
protected function createDatabase(string $name): void
    {
        $this->files->put($this->moduleName().'/'.$name.'/Database/Factories/UserFactory.php', $this->files->get(__DIR__.'/stubs/factory.stub'));
        $this->files->put($this->moduleName().'/'.$name.'/Database/Migrations/2014_10_12_000000_test_table.php', $this->files->get(__DIR__.'/stubs/migration.stub'));
        $this->files->put($this->moduleName().'/'.$name.'/Database/Seeds/DatabaseSeeder.php', $this->files->get(__DIR__.'/stubs/seed.stub'));
    }
1086876
public function create(string $name, callable $definition)
    {
        $this->_name = $name;
        $this->_definition = $definition;
    }
254390
public function load($name)
    {
        $factoryClass = ucfirst($name) . "Phactory";

        if (!class_exists($factoryClass)) {
            throw new \Exception("Unknown factory '$name'");
        }

        return new Factory($name, new $factoryClass);
    }
1187534
public function setName(string $name = '') : void
    {
        if (empty($name)) {
            throw new RuntimeException('Panel name not found therefore the object cannot be created');
        }
        $this->name = $name;
    }
414988
public static function SetFactory($Factory, $Override = TRUE) {
      if ($Override || is_null(self::$_Factory))
         self::$_Factory = $Factory;
   }
135129
public function getFactory($name)
    {
        if (!array_key_exists($name, $this->factories)) {
            throw new NotFoundException("No factory available for: $name");
        }

        return $this->factories[$name];
    }
754720
private function createServiceFromFactory(string $name, array $options = null)
    {
        $factory = $this->factories[$name] ?? null;

        if (is_string($factory) && class_exists($factory)) {
            $factory = new $factory();
            if ($factory instanceof FactoryInterface) {
                $this->factories[$name] = $factory;
                return $factory($this->creationContext, $name, $options);
            }
            throw InvalidArgumentException::fromInvalidFactory($factory);
        }

        if (is_callable($factory)) {
            return $factory($this->creationContext, $name, $options);
        } elseif (isset($this->invokables[$name])) {
            $invokable = $this->invokables[$name];
            return $options === null ? new $invokable() : new $invokable($options);
        }

        foreach ($this->abstractFactories as $idx => $abstractFactory) {
            if ($abstractFactory->canCreate($this->creationContext, $name)) {
                return $abstractFactory($this->creationContext, $name, $options);
            }
        }

        throw ServiceNotFoundException::fromUnknownService($name);
    }
755734
public function make($name, array $args = [])
    {
        if (! isset($this->classes[$name])) {
            throw new FactoryException('"' . $name . '" is not a registered class');
        }

        $class = new \ReflectionClass($this->classes[$name]);

        return $class->newInstanceArgs($args);
    }
764497
private function factory($name)
    {
        $factory = FabricateFactory::create(self::getInstance()->registry->find($name));
        $factory->setConfig(self::getInstance()->config);
        return $factory;
    }
1046089
public function add(string $name, RepositoryFactoryInterface $factory): void
    {
        $this->factories[$name] = $factory;
    }