Return an extension from the given callables.

@param callable $factory
@param callable ...$extensions
@return callable
503691
private function extended(callable $factory, callable ...$extensions): callable
    {
        return array_reduce($extensions, function ($factory, $extension) {
            return new Extension($factory, $extension);
        }, $factory);
    }
921225
public function replaceExtension($extension)
    {
        $atoms = $this->nameAtoms();
        if (array('', '') === $atoms) {
            if (null === $extension) {
                return $this;
            }

            return $this->replaceName(
                static::EXTENSION_SEPARATOR . $extension
            );
        }

        $numAtoms = count($atoms);

        if ($numAtoms > 1) {
            if (null === $extension) {
                $replacement = array();
            } else {
                $replacement = array($extension);
            }

            array_splice($atoms, -1, $numAtoms, $replacement);
        } elseif (null !== $extension) {
            $atoms[] = $extension;
        }

        return $this->replaceName(implode(self::EXTENSION_SEPARATOR, $atoms));
    }
738100
public static function for_extension($extension)
    {
        $classes = ClassInfo::subclassesFor(DataFormatter::class);
        array_shift($classes);
        $sortedClasses = [];
        foreach ($classes as $class) {
            $sortedClasses[$class] = Config::inst()->get($class, 'priority');
        }
        arsort($sortedClasses);
        foreach ($sortedClasses as $className => $priority) {
            $formatter = new $className();
            if (in_array($extension, $formatter->supportedExtensions())) {
                return $formatter;
            }
        }
    }
1150169
public function getFileListByExtensions( $extensions )
	{
		$lister	= new FS_Folder_Lister( $this->folderName );
		$lister->setExtensions( $extensions );
		$lister->showFolders( FALSE );
		return $lister->getList();
	}
700131
public function bindCallback(string $scope, string $abstract, callable $factory)
    {
        $this->validateScope(__METHOD__, $scope);

        if ($scope === self::SCOPE_INSTANCE_PER_RESOLVE) {
            $this->container->bind($abstract, $factory);
        } else {
            $this->container->singleton($abstract, $factory);
        }
    }
1020200
public function addExtension(ExtensionInterface $extension)
    {
        if ($this->initialized) {
            throw new RuntimeException(sprintf('Unable to add extension "%s" as they have already been initialized.', $extension->getName()));
        }

        $this->extensions[$extension->getName()] = $extension;
    }
957866
private function resolveFactory(?array $factory): ?array
    {
        if ([] === $factory) {
            return [];
        }

        if (isset($factory[0]) && $factory[0] instanceof Reference) {
            $factory[0] = $this->resolveReference($factory[0]);
        }

        return $factory;
    }
644718
private function createGeneratorFactory($generatorClass, \Closure $factory = null)
    {
        return function ($sourceClass, $prefixClass) use ($factory, $generatorClass) {
            if ($factory) {
                return $factory($sourceClass, $prefixClass, $this->generationIo, $this->definedClasses, $generatorClass);
            }

            return new $generatorClass($sourceClass, $prefixClass, $this->generationIo, null, $this->definedClasses);
        };
    }
1124574
public function extension()
    {
        $atoms = $this->nameAtoms();
        $numParts = count($atoms);

        if ($numParts > 1) {
            return $atoms[$numParts - 1];
        }

        return null;
    }
267152
protected function _setFactory($factory)
    {
        if ($factory !== null && !($factory instanceof FactoryInterface)) {
            throw $this->_createInvalidArgumentException(
                $this->__('Argument is not a valid factory instance'),
                null,
                null,
                $factory
            );
        }
        $this->factory = $factory;
    }
408892
public function callExtension($name, array $params = [])
    {
        $extension = $this->getExtension($name);

        // call_user_func_array seems to be slow
        switch (count($params)) {
            case 0:
                $result = call_user_func($extension);
                break;
            case 1:
                $result = call_user_func($extension, $params[0]);
                break;
            case 2:
                $result = call_user_func($extension, $params[0], $params[1]);
                break;
            case 3:
                $result = call_user_func($extension, $params[0], $params[1], $params[2]);
                break;
            case 4:
                $result = call_user_func($extension, $params[0], $params[1], $params[2], $params[3]);
                break;
            default:
                $result = call_user_func_array($extension, $params);
                break;
        }

        $this->callListeners($name, $result);

        return $result;
    }
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;
    }
896066
public function generateReflector($type, $factory) {
		switch ($type) {
		case 'callback':
			return $this->generateCallbackReflector($factory);
		case 'class':
			return $this->generateClassReflector($factory);
		}
	}
204036
public static function getInstance($cloneInstance = false): Factory
	{	
		if ($cloneInstance === true || self::$cloneInstances === true)
		{
			return clone self::$sharedFactoryInstance;
		}

		return self::$sharedFactoryInstance;
	}
264571
public function extension($extension)
    {
        if (is_string($extension)) {
            $extension = new $extension;
        } elseif (!$extension instanceof AbstractExtension) {
            throw new \LogicException('Not an extension object or an extension class name.');
        }

        $this->addExtension($extension);
    }
1138632
protected function validateExtensions($extensions): Extensions
    {
        if (empty($extensions)) {
            $extensions = new Extensions(['']);
        }

        if (! $extensions instanceof Extensions) {
            $extensions = new Extensions((array)$extensions);
        }

        return $extensions;
    }
551014
private function extended(callable $previous = null, callable $current): callable
    {
        return is_null($previous) ? $current : new Extension($current, $previous);
    }