@param string $container
@param array  $files
@param string $root

@throws BadRequestException
@return array
6246
public function deleteFiles($container, $files, $root = '')
    {
        $root = FileUtilities::fixFolderPath($root);
        foreach ($files as $key => $fileInfo) {
            try {
                // path is full path, name is relative to root, take either
                $path = array_get($fileInfo, 'path');
                if (!empty($path)) {
                    $file = static::asFullPath($path, true);
                    if (!is_file($file)) {
                        throw new BadRequestException("'$path' is not a valid file.");
                    }
                    if (!unlink($file)) {
                        throw new InternalServerErrorException("Failed to delete file '$path'.");
                    }
                } else {
                    $name = array_get($fileInfo, 'name');
                    if (!empty($name)) {
                        $path = $root . $name;
                        $this->deleteFile($container, $path);
                    } else {
                        throw new BadRequestException('No path or name found for file in delete request.');
                    }
                }
            } catch (\Exception $ex) {
                // error whole batch here?
                $files[$key]['error'] = ['message' => $ex->getMessage(), 'code' => $ex->getCode()];
            }
        }

        return $files;
    }
660687
public function process(ContainerBuilder $container)
    {
        $routes = [];
        foreach ($container->getParameter('graviton.rest.services') as $service => $params) {
            list($app, $bundle, , $entity) = explode('.', $service);
            $routes[] = implode('.', [$app, $bundle, 'rest', $entity, 'all']);
            $routes[] = implode('.', [$app, $bundle, 'rest', $entity, 'get']);
        }

        $container->setParameter('graviton.rest.listener.rqlqueryrequestlistener.allowedroutes', $routes);
    }
776083
public function execute($resource = null, array $files = array())
    {
        $this->populateCDNResources();

        $urls = [];
        foreach ($files as $file) {
            $urls[] = '/' . urlencode($file);
        }

        $cdnResources = array_filter($this->cdnResources, function($value, $key) use ($resource) {
            return $value['cname'] == $resource;
        }, ARRAY_FILTER_USE_BOTH);

        foreach ($cdnResources as $cdnResource) {
            $this->client->post($this->url, [
                'form_params' => [
                    'cdn_id' => $cdnResource['id'],
                    'login' => $this->login,
                    'passwd' => $this->password,
                    'url' => $urls
                ]
            ]);
        }

        return;
    }
75550
public function getFolders($rootFolder = null)
    {
        $folders = $this->_protocol->listMailbox((string)$rootFolder);
        if (!$folders) {
            /**
             * @see Zend_Mail_Storage_Exception
             */
            // require_once 'Zend/Mail/Storage/Exception.php';
            throw new Zend_Mail_Storage_Exception('folder not found');
        }

        ksort($folders, SORT_STRING);
        $root = new Zend_Mail_Storage_Folder('/', '/', false);
        $stack = array(null);
        $folderStack = array(null);
        $parentFolder = $root;
        $parent = '';

        foreach ($folders as $globalName => $data) {
            do {
                if (!$parent || strpos($globalName, $parent) === 0) {
                    $pos = strrpos($globalName, $data['delim']);
                    if ($pos === false) {
                        $localName = $globalName;
                    } else {
                        $localName = substr($globalName, $pos + 1);
                    }
                    $selectable = !$data['flags'] || !in_array('\\Noselect', $data['flags']);

                    array_push($stack, $parent);
                    $parent = $globalName . $data['delim'];
                    $folder = new Zend_Mail_Storage_Folder($localName, $globalName, $selectable);
                    $parentFolder->$localName = $folder;
                    array_push($folderStack, $parentFolder);
                    $parentFolder = $folder;
                    break;
                } else if ($stack) {
                    $parent = array_pop($stack);
                    $parentFolder = array_pop($folderStack);
                }
            } while ($stack);
            if (!$stack) {
                /**
                 * @see Zend_Mail_Storage_Exception
                 */
                // require_once 'Zend/Mail/Storage/Exception.php';
                throw new Zend_Mail_Storage_Exception('error while constructing folder tree');
            }
        }

        return $root;
    }
1226690
private function createContainer(array $files)
    {
        $containerBuilder = new Container();
        $loader = $this->createLoader($containerBuilder);
        foreach ($files as $file) {
            $loader->load($file);
        }

        return $containerBuilder;
    }
681181
private static function getDirectories(ContainerBuilder $container): array
    {
        /**
         * @noinspection PhpUnhandledExceptionInspection
         * @psalm-var    array<int, string> $directories
         *
         * @var string[] $directories
         */
        $directories = true === $container->hasParameter('service_bus.auto_import.handlers_directories')
            ? $container->getParameter('service_bus.auto_import.handlers_directories')
            : [];

        return $directories;
    }
879534
private function loadAndParseFile($fileName, $rootDir)
    {
        if (!$this->configuration->isRemoteFileInclusionEnabled()) {
            $rootDir = \realpath($rootDir);
            $fullPath = \realpath($rootDir . '/' . $fileName);

            if (!\is_readable($fullPath)) {
                throw new FileNotFoundException($fileName);
            }
        } else {
            $fullPath = $rootDir . '/' . $fileName;
            if (!\filter_var($fullPath, FILTER_VALIDATE_URL) && !\is_readable($fullPath)) {
                throw new FileNotFoundException($fileName);
            }
        }

        // Prevent LFI directory traversal attacks
        if (!$this->configuration->isDirectoryTraversalAllowed() &&
            \substr($fullPath, 0, \strlen($rootDir)) !== $rootDir
        ) {
            throw new FileNotFoundException($fileName);
        }

        $cacheKey = \md5($fullPath);

        // cache based on file name, prevents including/parsing the same file multiple times
        if (isset($this->cachedFiles[$cacheKey])) {
            return $this->cachedFiles[$cacheKey];
        }

        $fileExtension = (\pathinfo($fileName, PATHINFO_EXTENSION));

        if (\in_array($fileExtension, ['yaml', 'yml', 'raml'], true)) {
            $rootDir = \dirname($rootDir . '/' . $fileName);

            // RAML and YAML files are always parsed
            $fileData = $this->parseRamlString(
                \file_get_contents($fullPath),
                $rootDir
            );
            $fileData = $this->includeAndParseFiles($fileData, $rootDir);
        } else {
            $loader = \array_key_exists($fileExtension, $this->fileLoaders) ? $this->fileLoaders[$fileExtension] : $this->fileLoaders['*'];

            $fileData = $loader->loadFile($fullPath);
            $this->cachedFilesPaths[\md5($fileData)] = $fullPath;
        }

        // cache before returning
        $this->cachedFiles[$cacheKey] = $fileData;

        $this->includedFiles[] = $fullPath;

        return $fileData;
    }
1361698
public static function searchFile($root, $pattern = '*', $flags = 0)
    {
        $dirs = self::listDirs($root);
        array_unshift($dirs, $root);
        
        $foundFiles = [];
        
        if ($pattern instanceof \Closure) {
            $closure = $pattern;
            $pattern = '*';
        } else {
            $closure = null;
        }
        
        foreach ($dirs as $dir) {
            $filePatt = $dir . '/' . $pattern;
            $files = glob($filePatt, $flags);
            
            if ($closure) {
                foreach ($files as $file) {
                    if ($closure($file)) {
                        $foundFiles[] = $file;
                    }
                }
            } else {
                if ($files) {
                    $foundFiles = array_merge($foundFiles, $files);
                }
            }
        }
        
        return $foundFiles;
    }
372065
public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.xml');

        $config = $this->processConfiguration(new Configuration(), $configs);

        if (!empty($config['unalias_subscriber'])) {
            // deprecation, remove in next major
            trigger_error('unalias_subscriber is no longer used. This has moved to form transformers.', E_USER_DEPRECATED);
        }


        if (isset($config['static_ref'])) {
            $container->getDefinition('zicht_url.static_refs')->addMethodCall('addAll', [$config['static_ref']]);
        }
        if (!empty($config['aliasing']) && $config['aliasing']['enabled'] === true) {
            $this->loadAliasingConfig($container, $config['aliasing'], $loader);
            $container->setAlias('zicht_url.sitemap_provider', new Alias('zicht_url.alias_sitemap_provider'));
        } else {
            $container->setAlias('zicht_url.sitemap_provider', new Alias('zicht_url.provider'));
        }
        if (!empty($config['logging'])) {
            $loader->load('logging.xml');
        }
        if (!empty($config['admin'])) {
            $loader->load('admin.xml');
        }
        if (!empty($aliasingConfig) && $config['caching']['enabled'] === true) {
            $loader->load('cache.xml');
            $subscriberDefinition = $container->getDefinition('zicht_url.cache_subscriber');
            $subscriberDefinition->replaceArgument(1, $config['caching']['entities']);
        }
        if (!empty($config['db_static_ref']) && $config['db_static_ref']['enabled'] === true) {
            $loader->load('db.xml');
        }

        if ($container->hasDefinition('zicht_url.aliasing')) {
            $container->getDefinition('zicht_url.twig_extension')->addArgument(new Reference('zicht_url.aliasing'));
        }

        if ($container->hasDefinition('zicht_url.mapper.html')) {
            $container->getDefinition('zicht_url.mapper.html')->addMethodCall('addAttributes', [$config['html_attributes']]);
        }

        if ($container->hasDefinition('zicht_url.listener.strict_public_url')) {
            $container->getDefinition('zicht_url.listener.strict_public_url')->replaceArgument(0, $config['strict_public_url']);
        }

        if ($container->hasDefinition('zicht_url.validator.contains_url_alias')) {
            $container->getDefinition('zicht_url.validator.contains_url_alias')->replaceArgument(1, $config['strict_public_url']);
        }

        $formResources = $container->getParameter('twig.form.resources');
        $formResources[] = 'ZichtUrlBundle::form_theme.html.twig';
        $container->setParameter('twig.form.resources', $formResources);
    }
634783
final public function prepareMultipartRequestPayloads(array $headers = [], array $body = [], array $files = []): array
    {
        $multipart = (($headers['Content-Type'] ?? null) == 'multipart/form-data');

        if (empty($files) && ! $multipart) {
            return [$headers, $body];
        }

        $builder = new Builder(StreamFactoryDiscovery::find());

        $this->addFilesToMultipartBuilder($builder, $files);
        $this->addBodyToMultipartBuilder(
            $builder, $this instanceof Filterable ? $this->filterRequest($body) : $body
        );

        $headers['Content-Type'] = 'multipart/form-data; boundary='.$builder->getBoundary();

        return [$headers, $builder->build()];
    }
1146774
public function load(array $configs, ContainerBuilder $container)
    {
        $config = $this->processConfiguration(new Configuration(), $configs);

        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.xml');

        if (isset($config['quicklist'])) {
            $loader->load('quicklist.xml');
            foreach ($config['quicklist'] as $name => $quicklistConfig) {
                $container->getDefinition('zicht_admin.quicklist')
                    ->addMethodCall('addRepositoryConfig', array($name, $quicklistConfig));

                $formResources = $container->getParameter('twig.form.resources');
                $formResources[]= 'ZichtAdminBundle::form_theme.html.twig';
                $container->setParameter('twig.form.resources', $formResources);
            }
        }

        if (isset($config['transactional_listener']) && $config['transactional_listener']['auto']) {
            $loader->load('transactional_listener.xml');

            $container->getDefinition('zicht_admin.transactional_listener')
                ->addArgument($config['transactional_listener']['pattern']);
        }

        if (isset($config['rc'])) {
            $loader->load('rc.xml');
            $container->getDefinition('zicht_admin.controller.rc')->replaceArgument(0, $config['rc']);
        }

        $container->getDefinition('zicht_admin.security.authorization.voter.admin_voter')
            ->replaceArgument(0, $config['security']['mapped_attributes']);
    }
1179596
public static function readSimple(string $filename, string $rootDir = '.', ParserInterface $parser = null): array
    {
        $data = ['@import' => $filename];

        $story = new Simple($rootDir);
        $parser = $parser ?? new Standard;

        $parser->parse($data, $story);
        return $data;
    }
515466
public function load(array $configs, ContainerBuilder $container)
    {
        array_unshift($configs, [
            'files' => [
                'web' => [
                    'directory' => $container->getParameter('kernel.root_dir') . '/../web',
                    'exclude' => '*.php',
                ]
            ],
            'routes' => [
                'pages' => [
                    'route' => '_slug',
                    'generator' => 'nodes',
                ],
                'sitemap_index' => [
                    'route' => 'KunstmaanSitemapBundle_sitemapindex',
                    'defaults' => [
                        '_format' => 'xml',
                    ]
                ],
                'sitemaps' => [
                    'route' => 'KunstmaanSitemapBundle_sitemap',
                    'generator' => 'locales',
                    'defaults' => [
                        '_format' => 'xml',
                    ]
                ],
                'robots' => [
                    'route' => 'KunstmaanSeoBundle_robots',
                ]
            ],
            'extensions' => [
                "css" => "text/css",
                "js" => "text/javascript",
                "svg" => "image/svg+xml",
                "map" => "application/json",
                "jpg" => "image/jpeg",
                "jpeg" => "image/jpeg",
                "png" => "image/png",
                "ttf" => "font/ttf",
                "otf" => "application/x-font-opentype",
                "woff" => "application/font-woff",
                "woff2" => "application/font-woff2",
                "eot" => "application/vnd.ms-fontobject",
            ]
        ]);

        $configs = (new Processor)->processConfiguration(new Configuration, $configs);

        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.xml');

        $container->setParameter('nassau.static_site.url_prefix', $configs['url_prefix']);
        $container->setParameter('nassau.static_site.extensions', $configs['extensions']);
        $this->configureRoutes($container, $configs['routes']);
        $this->configureFiles($container, $configs['files']);
    }
444829
private function setFilesystemRootDir($rootDir, ContainerBuilder $container)
    {
        $definition = $container->getDefinition($this->getAlias() . '.filesystem');

        $definition->replaceArgument(0, $rootDir);
    }
1135607
static public function searchFile($root, $pattern = '*', $flags = 0)
    {
        $dirs = self::listDirs($root);
        array_unshift($dirs, $root);
        
        $foundFiles = [];
        
        foreach ($dirs as $dir) {
            $filePatt = $dir . '/' . $pattern;
            $files = glob($filePatt, $flags);
        
            if ($files) {
                $foundFiles = array_merge($foundFiles, $files);
            }
        }
        
        return $foundFiles;
    }
35734
public function load(array $configs, ContainerBuilder $container)
    {
        $config = $this->processConfiguration(
            $this->getConfiguration($configs, $container),
            $configs
        );

        $container->setParameter('liip_imagine.resolvers', $config['resolvers']);
        $container->setParameter('liip_imagine.loaders', $config['loaders']);

        $this->loadResolvers($config['resolvers'], $container);
        $this->loadLoaders($config['loaders'], $container);

        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('imagine.xml');
        $loader->load('commands.xml');

        if ($config['enqueue']) {
            $loader->load('enqueue.xml');
        }

        $container->setParameter('liip_imagine.driver_service', 'liip_imagine.'.$config['driver']);

        $container->setAlias('liip_imagine', new Alias('liip_imagine.'.$config['driver']));
        $container->setAlias(CacheManager::class, new Alias('liip_imagine.cache.manager', false));
        $container->setAlias(DataManager::class, new Alias('liip_imagine.data.manager', false));
        $container->setAlias(FilterManager::class, new Alias('liip_imagine.filter.manager', false));

        $container->setParameter('liip_imagine.cache.resolver.default', $config['cache']);

        $container->setParameter('liip_imagine.default_image', $config['default_image']);

        $container->setParameter('liip_imagine.filter_sets', $config['filter_sets']);
        $container->setParameter('liip_imagine.binary.loader.default', $config['data_loader']);

        $container->setParameter('liip_imagine.controller.filter_action', $config['controller']['filter_action']);
        $container->setParameter('liip_imagine.controller.filter_runtime_action', $config['controller']['filter_runtime_action']);

        $container->setParameter('twig.form.resources', array_merge(
            $container->hasParameter('twig.form.resources') ? $container->getParameter('twig.form.resources') : [],
            ['@LiipImagine/Form/form_div_layout.html.twig']
        ));
    }
41682
public function prepend(ContainerBuilder $container)
    {
        if ($container->hasExtension('sulu_search')) {
            $container->prependExtensionConfig(
                'sulu_search',
                [
                    'indexes' => [
                        'contact' => [
                            'security_context' => 'sulu.contact.people',
                        ],
                        'account' => [
                            'security_context' => 'sulu.contact.organizations',
                        ],
                    ],
                ]
            );
        }

        if ($container->hasExtension('sulu_media')) {
            $container->prependExtensionConfig(
                'sulu_media',
                [
                    'system_collections' => [
                        'sulu_contact' => [
                            'meta_title' => ['en' => 'Sulu contacts', 'de' => 'Sulu Kontakte'],
                            'collections' => [
                                'contact' => [
                                    'meta_title' => ['en' => 'People', 'de' => 'Personen'],
                                ],
                                'account' => [
                                    'meta_title' => ['en' => 'Organizations', 'de' => 'Organisationen'],
                                ],
                            ],
                        ],
                    ],
                ]
            );
        }

        if ($container->hasExtension('sulu_admin')) {
            $container->prependExtensionConfig(
                'sulu_admin',
                [
                    'lists' => [
                        'directories' => [
                            __DIR__ . '/../Resources/config/lists',
                        ],
                    ],
                    'forms' => [
                        'directories' => [
                            __DIR__ . '/../Resources/config/forms',
                        ],
                    ],
                    'resources' => [
                        'contacts' => [
                            'routes' => [
                                'list' => 'get_contacts',
                                'detail' => 'get_contact',
                            ],
                        ],
                        'accounts' => [
                            'routes' => [
                                'list' => 'get_accounts',
                                'detail' => 'get_account',
                            ],
                        ],
                        'contact_titles' => [
                            'routes' => [
                                'list' => 'get_contact-titles',
                            ],
                        ],
                        'contact_positions' => [
                            'routes' => [
                                'list' => 'get_contact-positions',
                            ],
                        ],
                    ],
                    'field_type_options' => [
                        'single_selection' => [
                            'single_account_selection' => [
                                'default_type' => 'auto_complete',
                                'resource_key' => 'accounts',
                                'types' => [
                                    'auto_complete' => [
                                        'display_property' => 'name',
                                        'search_properties' => ['number', 'name'],
                                    ],
                                    'list_overlay' => [
                                        'adapter' => 'table',
                                        'list_key' => 'accounts',
                                        'display_properties' => ['name'],
                                        'empty_text' => 'sulu_contact.no_account_selected',
                                        'icon' => 'su-house',
                                        'overlay_title' => 'sulu_contact.single_account_selection_overlay_title',
                                    ],
                                ],
                            ],
                            'single_contact_selection' => [
                                'default_type' => 'list_overlay',
                                'resource_key' => 'contacts',
                                'types' => [
                                    'list_overlay' => [
                                        'adapter' => 'table',
                                        'list_key' => 'contacts',
                                        'display_properties' => ['fullName'],
                                        'empty_text' => 'sulu_contact.no_contact_selected',
                                        'icon' => 'su-user',
                                        'overlay_title' => 'sulu_contact.single_contact_selection_overlay_title',
                                    ],
                                ],
                            ],
                            'single_contact_title_selection' => [
                                'default_type' => 'single_select',
                                'resource_key' => 'contact_titles',
                                'types' => [
                                    'single_select' => [
                                        'id_property' => 'id',
                                        'display_property' => 'title',
                                        'overlay_title' => 'sulu_contact.edit_title_overlay_title',
                                    ],
                                ],
                            ],
                            'single_contact_position_selection' => [
                                'default_type' => 'single_select',
                                'resource_key' => 'contact_positions',
                                'types' => [
                                    'single_select' => [
                                        'id_property' => 'id',
                                        'display_property' => 'position',
                                        'overlay_title' => 'sulu_contact.edit_position_overlay_title',
                                    ],
                                ],
                            ],
                        ],
                    ],
                ]
            );
        }
    }