Register existing or lazy factory as factory method for adapter under specified key.

@param string $name
@param string|SimpleFactoryInterface $classOrFactory
430083
protected function registerFactoryMethod($name, $classOrFactory)
    {
        $this
            ->define($name, function($config = []) use($classOrFactory) {
                $factory = is_object($classOrFactory) ? $classOrFactory : new $classOrFactory();

                return new Filesystem(
                    $factory->create([ $config ])
                );
            })
        ;
    }
905555
public function registerFactory(string $produced_class, Factory $factory)
    {
        $this->factories[$produced_class] = $factory;
        return $this;
    }
107682
public static function registerEvent($name, $className)
    {
        if (isset(static::$eventList[$name]) === false) {
            static::$eventList[$name] = array();
        }
        static::$eventList[$name][$className] = $className;
    }
1160366
public static function factory($name)
    {
        if (!isset(self::$services[$name])) {
            throw new \RuntimeException("The service [$name] don't register.");
        }

        $service = self::$services[$name];

        if (\is_object($service) && method_exists($service, '__invoke')) {
            return $service();
        }

        return $service;
    }
1179
public function registerHelper($name, $helper = false)
    {
        if (is_array($name)) {
            foreach ($name as $n => $helper) {
                $this->registerHelper($n, $helper);
            }
        } elseif (is_object($name)) {
            $this->registerJavascriptObject('helper', $this->wrapHelperObject($name));
        } elseif ($helper === false) {
            $this->registerJavascriptObject('helper', $name);
        } elseif (is_callable($helper)) {
            $this->registerJavascriptFunction('helper', $name, $this->wrapHelperCallable($name, $helper));
        } else {
            $this->registerJavascriptFunction('helper', $name, $helper);
        }
    }
539598
public function addFactory($name, $factory, $shared = null)
    {
        return $this->add($name, $factory, self::ENTRY_TYPE_FACTORY, $shared);
    }
538402
public function register($name, $fieldClass = null)
    {
        if (new $fieldClass instanceof FormFieldInterface) {
            $this->registeredFields[$name] = $fieldClass;
        }
    }
444659
public static function registerEnumType($name, callable $constructor, callable $serializer = null)
    {
        if (static::hasType($name)) {
            return;
        }

        $serializer = $serializer ?? function ($value) { return ($value === null) ? null : (string)$value; };

        // Register and customize the type
        static::addType($name, static::class);

        /** @var EnumerationBridge $type */
        $type              = static::getType($name);
        $type->name        = $name;
        $type->constructor = $constructor;
        $type->serializer  = $serializer;
    }
172142
public function getInstanceFromClassName($className, $name)
    {
        if (false === class_exists($className)) {
            throw ClassNotFoundException::wrongFormClassName($className);
        }

        if (false === in_array(FormInterface::class, class_implements($className))) {
            throw InvalidArgumentTypeException::wrongFormType($className);
        }

        $cacheIdentifier = $this->getCacheIdentifier($className, $name);

        if (false === isset($this->instances[$cacheIdentifier])) {
            $cacheInstance = CacheService::get()->getCacheInstance();

            if ($cacheInstance->has($cacheIdentifier)) {
                $instance = $cacheInstance->get($cacheIdentifier);
            } else {
                $instance = $this->createInstance($className, $name);
                $cacheInstance->set($cacheIdentifier, $instance);
            }

            /** @var Configuration $formzConfigurationObject */
            $formzConfigurationObject = $this->configurationFactory
                ->getFormzConfiguration()
                ->getObject(true);

            if (false === $formzConfigurationObject->hasForm($instance->getClassName(), $instance->getName())) {
                $formzConfigurationObject->addForm($instance);
            }

            $this->instances[$cacheIdentifier] = $instance;
        }

        return $this->instances[$cacheIdentifier];
    }
811852
public function bindFactory(string $name, $definition)
    {
        $this->definitions[$name] = new Factory($name, $definition);
        return $this;
    }
289675
private function getFactoryMapping(ContainerInterface $serviceLocator, $name)
    {
        $matches = [];

        if (! preg_match(
            '/^doctrine\.((?<mappingType>orm|odm)\.|)(?<serviceType>[a-z0-9_]+)\.(?<serviceName>[a-z0-9_]+)$/',
            $name,
            $matches
        )) {
            return false;
        }

        $config      = $serviceLocator->get('config');
        $mappingType = $matches['mappingType'];
        $serviceType = $matches['serviceType'];
        $serviceName = $matches['serviceName'];

        if ($mappingType == '') {
            if (! isset($config['doctrine_factories'][$serviceType]) ||
                 ! isset($config['doctrine'][$serviceType][$serviceName])
            ) {
                return false;
            }

            return [
                'serviceType'  => $serviceType,
                'serviceName'  => $serviceName,
                'factoryClass' => $config['doctrine_factories'][$serviceType],
            ];
        } else {
            if (! isset($config['doctrine_factories'][$mappingType]) ||
                 ! isset($config['doctrine_factories'][$mappingType][$serviceType]) ||
                 ! isset($config['doctrine'][$mappingType][$serviceType][$serviceName])
            ) {
                return false;
            }
            return [
                'serviceType'  => $serviceType,
                'serviceName'  => $serviceName,
                'factoryClass' => $config['doctrine_factories'][$mappingType][$serviceType],
            ];
        }
    }
780838
public function registerInstance($name = null)
    {
        if ($name === null) {
            $name = 'default';
        }
        $this->instanceName($name);
        return $this;
    }
359508
public function register(string $name, string $class, string $description, array $options = [])
    {
        $name = strtolower($name);

        $this->app->getConfig()->write('collectors.' . $name, [
            'class' => $class,
            'description' => $description,
            'options' => $options,
        ]);
        $this->container->singleton($class);
        $this->container->alias($name, $class);
    }
1289429
@Override
    public Class<? extends ChannelFactory> lookupFactory(String name) {
        Class<? extends ChannelFactory> clazz = null;
        synchronized (this.factories) {
            clazz = this.factories.get(name);
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "lookupFactory: " + name + ": " + clazz);
        }
        if (null != clazz) {
            // if we found a registration and a provider, let it know
            ChannelFactoryProvider provider = this.providers.get(name);
            if (null != provider && !activatedProviders.contains(provider)) {
                this.activatedProviders.add(provider);
                provider.init();
            }
        }
        return clazz;
    }
1182965
private function createServiceFromDelegator(string $name, array $options = null)
    {
        // @todo: This selection is necessary only because lazy services
        // configuration currently requires an explicit Delegator definition
        if ($this->delegators[$name][0] === Proxy\LazyServiceFactory::class) {
            return $this->createServiceFromLazyServiceDelegator($name, $options);
        }

        $creationCallback = $this->delegatorCallbackCache[$name] ?? null;
        if ($creationCallback) {
            $object = $creationCallback($this->creationContext, $name, $creationCallback, $options);
            return $object;
        }

        $creationCallback = function () use ($name, $options) {
            return $this->createServiceFromFactory($name, $options);
        };

        foreach ($this->delegators[$name] as $index => $delegatorFactory) {
            if (is_string($delegatorFactory) && class_exists($delegatorFactory)) {
                $delegatorFactory = new $delegatorFactory();
                if ($delegatorFactory instanceof DelegatorFactoryInterface) {
                    $this->delegators[$name][$index] = $delegatorFactory;
                    $creationCallback = function () use ($delegatorFactory, $name, $creationCallback, $options) {
                        return $delegatorFactory($this->creationContext, $name, $creationCallback, $options);
                    };
                    continue;
                }
            }
            if (is_callable($delegatorFactory)) {
                $creationCallback = function () use ($delegatorFactory, $name, $creationCallback, $options) {
                    return $delegatorFactory($this->creationContext, $name, $creationCallback, $options);
                };
                continue;
            }
            if (is_string($delegatorFactory)) {
                throw InvalidArgumentException::fromInvalidDelegatorFactoryClass($delegatorFactory);
            }
            throw InvalidArgumentException::fromInvalidDelegatorFactoryInstance($delegatorFactory);
        }

        //cache the callback for later requests
        $this->delegatorCallbackCache[$name] = $creationCallback;
        return $creationCallback($this->creationContext, $name, $creationCallback, $options);
    }
1310112
private function createClientRetryMap(
        ContainerBuilder $container,
        string $name,
        array $repositoryConfiguration
    ) {
        if (!$this->repositoryIsHttp($repositoryConfiguration)) {
            return;
        }

        $clientRetryMapName = rtrim("apisearch.retry_map_$name", '.');
        $container
                ->register($clientRetryMapName, RetryMap::class)
                ->setFactory([
                    RetryMap::class,
                    'createFromArray',
                ])
                ->setArgument(0, $repositoryConfiguration['http']['retry_map']);
    }
1150425
public function addFactory(Name $contextName, Factory $transactionFactory)
    {
        $this->factories[(string) $contextName] = $transactionFactory;
    }