Detects what metadata driver to use for the supplied directory.

@param string           $dir       A directory path
@param ContainerBuilder $container A ContainerBuilder instance

@return string|null A metadata driver short name, if one can be detected
334828
protected function detectMetadataDriver($dir, ContainerBuilder $container)
    {
        $configPath = $this->getMappingResourceConfigDirectory();
        $extension = $this->getMappingResourceExtension();

        if (glob($dir.'/'.$configPath.'/*.'.$extension.'.xml')) {
            $driver = 'xml';
        } elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.yml')) {
            $driver = 'yml';
        } elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.php')) {
            $driver = 'php';
        } else {
            // add the closest existing directory as a resource
            $resource = $dir.'/'.$configPath;
            while (!is_dir($resource)) {
                $resource = \dirname($resource);
            }
            $container->fileExists($resource, false);

            return $container->fileExists($dir.'/'.$this->getMappingObjectDefaultName(), false) ? 'annotation' : null;
        }
        $container->fileExists($dir.'/'.$configPath, false);

        return $driver;
    }
1163390
protected static function getViaPath($path, $container)
    {
        $default = null;

        $current = $container;
        $p       = strtok($path, '.');

        while ($p !== false) {
            if (!isset($current[ $p ])) {
                return $default;
            }
            $current = $current[ $p ];
            $p       = strtok('.');
        }

        return $current;
    }
1101805
protected function doChangeDir($dir)
    {
        $connection = $this->connection;

        return $this->retry(function () use ($connection, $dir) {
            $res = @ftp_chdir($connection, $dir);

            if (false === $res) {
                throw new \RuntimeException("Changing directory failed: ".$dir);
            }
        });
    }
986568
public static function locateResource($path, ContainerBuilder $container)
    {
        if (0 === stripos($path, '@')) {
            // Treat as a bundle path, e.g. @SomeBundle/path/to/something.

            // Correct backslashed paths.
            $path = str_replace('\\', '/', $path);

            $parts = explode('/', $path);
            $bundle = array_shift($parts);

            $bundleName = str_replace('@', '', $bundle);
            $bundleClass = null;
            foreach ($container->getParameter('kernel.bundles') as $name => $class) {
                if ($name === $bundleName) {
                    $bundleClass = $class;
                    break;
                }
            }

            if (null === $bundleClass) {
                throw new \RuntimeException(sprintf('Unable to find a bundle named "%s" for resource path "%s"', $bundleName, $path));
            }

            $refl = new \ReflectionClass($bundleClass);
            $bundleDir = dirname($refl->getFileName());
            return sprintf('%s/%s', $bundleDir, implode('/', $parts));
        }
        return $path;
    }
31406
static public function getParentThemeFilePath($name, $container = '', $extension = ''){
		return get_template_directory() . self::getRelativePath($name, $container, $extension);
	}
261432
public static function inspect($dir)
    {
        if (!is_dir($dir)) {
            throw new FileNotFoundException(sprintf('Directory "%s" does not exist.', $dir));
        }

        foreach (self::getStacks() as $stack) {
            if ($stack->inspect($dir) === true) {
                return $stack;
            }
        }

        // Stacks were not able to identify the structure.
        return new Stacks\NullStack();
    }
673079
public function findStructureManifest($directory = null)
    {
        $returnValue = null;

        
        if ($directory == null) {
        	$actionsDir = $this->options['input'] . '/actions';	
        } else {
        	$actionsDir = $directory . '/actions';
        }
        
        $dirEntries = scandir($actionsDir);
        
        if ($dirEntries === false) {
        	$returnValue = false;	
        } else {
        	$structureFile = null;
        	foreach ($dirEntries as $f) {
				if (preg_match("/(.*)structure\.xml$/", $f)) {
					$structureFile = $f;
					break;
				}
        	}
        	
        	if ($structureFile === null) {
        		$returnValue = false;
        	} else {
        		$returnValue = $structureFile;
        	}
        }
        

        return $returnValue;
    }
51203
protected function registerMappingDrivers($objectManager, ContainerBuilder $container)
    {
        // configure metadata driver for each bundle based on the type of mapping files found
        if ($container->hasDefinition($this->getObjectManagerElementName($objectManager['name'].'_metadata_driver'))) {
            $chainDriverDef = $container->getDefinition($this->getObjectManagerElementName($objectManager['name'].'_metadata_driver'));
        } else {
            $chainDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.driver_chain.class%'));
            $chainDriverDef->setPublic(false);
        }

        foreach ($this->drivers as $driverType => $driverPaths) {
            $mappingService = $this->getObjectManagerElementName($objectManager['name'].'_'.$driverType.'_metadata_driver');
            if ($container->hasDefinition($mappingService)) {
                $mappingDriverDef = $container->getDefinition($mappingService);
                $args = $mappingDriverDef->getArguments();
                if ('annotation' == $driverType) {
                    $args[1] = array_merge(array_values($driverPaths), $args[1]);
                } else {
                    $args[0] = array_merge(array_values($driverPaths), $args[0]);
                }
                $mappingDriverDef->setArguments($args);
            } elseif ('annotation' == $driverType) {
                $mappingDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%'), [
                    new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
                    array_values($driverPaths),
                ]);
            } else {
                $mappingDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%'), [
                    array_values($driverPaths),
                ]);
            }
            $mappingDriverDef->setPublic(false);
            if (false !== strpos($mappingDriverDef->getClass(), 'yml') || false !== strpos($mappingDriverDef->getClass(), 'xml')) {
                $mappingDriverDef->setArguments([array_flip($driverPaths)]);
                $mappingDriverDef->addMethodCall('setGlobalBasename', ['mapping']);
            }

            $container->setDefinition($mappingService, $mappingDriverDef);

            foreach ($driverPaths as $prefix => $driverPath) {
                $chainDriverDef->addMethodCall('addDriver', [new Reference($mappingService), $prefix]);
            }
        }

        $container->setDefinition($this->getObjectManagerElementName($objectManager['name'].'_metadata_driver'), $chainDriverDef);
    }
1221364
protected function resolveServiceId(ContainerBuilder $container, array $attr): ?string
    {
        return isset($attr[$this->attrName]) ? $this->resolveParam($container, $attr[$this->attrName]) : null;
    }
696854
protected function registerElfinderServices(Container $container)
    {
        /**
         * Configure the "config.admin.elfinder" dataset.
         *
         * @param  AdminConfig $adminConfig The admin configset.
         * @return AdminConfig
         */
        $container->extend('admin/config', function (AdminConfig $adminConfig) {
            $adminConfig['elfinder'] = new Config($adminConfig['elfinder']);

            return $adminConfig;
        });

        /**
         * The elFinder configset.
         *
         * @param  Container $container The Pimple DI Container.
         * @return ConfigInterface
         */
        $container['elfinder/config'] = function (Container $container) {
            return $container['admin/config']['elfinder'];
        };
    }
596531
private function findTemplatesInFolder($dir)
    {
        $templates = array();

        if (is_dir($dir)) {
            $finder = new Finder();
            foreach ($finder->files()->followLinks()->in($dir) as $file) {
                $template = $this->parser->parse($file->getRelativePathname());
                if (false !== $template) {
                    $templates[] = $template;
                }
            }
        }

        return $templates;
    }
1109205
public function getRendererManager(Container $container)
    {
        if ($this->rendererManager) {
            return $this->rendererManager;
        }

        return $container->get(RendererManager::class);
    }
475442
public function ls($dir = '')
    {
        if ($dir == '' || substr($dir, 0, 1) !== '/') {
            $dir = $this->dir . '/' . $dir;
        }

        if ($this->driver->sftpIsDir($this->resource, $dir)) {
            $handle = $this->driver->sftpOpenDir($this->resource, $dir);
            $files = array();
            while (false !== ($file = $this->driver->sftpReadDir($handle))) {
                if (substr("$file", 0, 1) != '.') {
                    $files[] = $file;
                }
            }

            //finished searching the directory
            return $files;
        }

        //if IsDir fails that means its either not a directory or doesnt exist
        if (!$this->driver->sftpFileExists($this->resource, $dir)) {
            $this->errorHandler->register("$dir does not exist.", 0);

            return false;
        }

        $this->errorHandler->register("$dir is not a directory", 0);

        return false;
    }
138499
private function rrmdir($dir)
    {
        // protect from something bad happening
        if (0 !== strpos($dir, $this->storagePath)) {
            return false;
        }

        foreach (glob($dir . DIRECTORY_SEPARATOR . '*') as $file) {
            if (is_dir($file)) {
                $this->rrmdir($file);
            } else {
                unlink($file);
            }
        }

        return rmdir($dir);
    }
245639
public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition(static::REGISTRY_NAME) || !$container->hasDefinition(static::EVENT_DISPATCHER_NAME)) {
            return;
        }

        $registry = $container->getDefinition(static::REGISTRY_NAME);
        $dispatcherReference = new Reference(static::EVENT_DISPATCHER_NAME);
        $parameterBag = $container->getParameterBag();

        foreach ($container->findTaggedServiceIds(static::TAG_NAME) as $id => $tags) {
            $registry->addMethodCall("addDriver", [new Reference($id)]);

            // Inject the dispatcher in the driver
            $driver = $container->getDefinition($id);
            $driver->addMethodCall("setDispatcher", [$dispatcherReference]);

            foreach ($tags as $tag) {
                if (isset($tag[static::LISTENER_TAG_PARAMETER])) {
                    $listenerCode = $parameterBag->resolveValue($tag[static::LISTENER_TAG_PARAMETER]);

                    if (!$container->hasDefinition($listenerCode)) {
                        throw new ServiceNotFoundException(sprintf("The service '%s' doesn't exist", $listenerCode));
                    }

                    $listener = $container->getDefinition($listenerCode);
                    $listenerClass = $parameterBag->resolveValue($listener->getClass());

                    $reflection = new \ReflectionClass($listenerClass);

                    if (false === $reflection->implementsInterface(static::DRIVER_LISTENER_INTERFACE)) {
                        throw new InvalidArgumentException(sprintf(
                            "The service '%s' must implement interface '%s' but doesn't",
                            $listenerCode,
                            static::DRIVER_LISTENER_INTERFACE
                        ));
                    }

                    $listener->addMethodCall("setDriver", [new Reference($id)]);
                }
            }
        }
    }
760292
public function process(ContainerBuilder $container)
    {
        if (!$this->enabled($container)) {
            return;
        }

        $mappingDriverDef = $this->getDriver($container);
        $chainDriverDefService = $this->getChainDriverServiceName($container);
        // Definition for a Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
        $chainDriverDef = $container->getDefinition($chainDriverDefService);
        foreach ($this->namespaces as $namespace) {
            $chainDriverDef->addMethodCall('addDriver', [$mappingDriverDef, $namespace]);
        }

        if (!\count($this->aliasMap)) {
            return;
        }

        $configurationServiceName = $this->getConfigurationServiceName($container);
        // Definition of the Doctrine\...\Configuration class specific to the Doctrine flavour.
        $configurationServiceDefinition = $container->getDefinition($configurationServiceName);
        foreach ($this->aliasMap as $alias => $namespace) {
            $configurationServiceDefinition->addMethodCall($this->registerAliasMethodName, [$alias, $namespace]);
        }
    }
963578
private function createOrGetFolder($directory, ContainerBuilder $container)
    {
        $filesystem = new Filesystem();

        $directory = $container->getParameterBag()->resolveValue($directory);
        if (!file_exists($directory)) {
            $filesystem->mkdir($directory);
        }

        return $directory;
    }