Gets all allowed storage paths based on RBAC

@param array   $manifest
@param string  $serviceName
@param integer $serviceId
@param bool    $fullTree
437377
private function getAllowedStoragePaths(&$manifest, $serviceName, $serviceId, $fullTree)
    {
        if (Session::isSysAdmin()) {
            // Get all paths bypassing RBAC
            $manifest['service'][$serviceName] = $this->getAllResources(
                $serviceName, '', ['as_list' => true, 'full_tree' => $fullTree], null, false
            );
        } else {
            $roleId = Session::getRoleId();
            $requestorMask = Session::getRequestor();
            $manifest['service'][$serviceName] = [];

            $accesses = RoleServiceAccess::whereRoleId($roleId)
                ->whereServiceId($serviceId)
                ->whereRequestorMask($requestorMask)
                ->get(['component', 'verb_mask']);

            foreach ($accesses as $access) {
                if ($access->verb_mask & VerbsMask::toNumeric(Verbs::GET)) {
                    $allowedPath = $access->component;
                    if ($allowedPath === '*') {
                        $manifest['service'][$serviceName] = $this->getAllResources(
                            $serviceName, '', ['as_list' => true, 'full_tree' => $fullTree]
                        );
                        // Safe to break out from the loop here.
                        // Access === '*' mean everything is allowed anyway.
                        // No need to check further accesses.
                        break;
                    } else {
                        // Only consider paths ending with * like my/path/*
                        // A path without * at the end (my/path/) only allows
                        // for directory listing which is not useful for exports.
                        if (substr($allowedPath, strlen($allowedPath) - 1) === '*') {
                            if ($fullTree) {
                                $allPaths = $this->getAllResources(
                                    $serviceName,
                                    substr($allowedPath, 0, strlen($allowedPath) - 1),
                                    ['as_list' => true, 'full_tree' => $fullTree]
                                );
                                $manifest['service'][$serviceName] = array_merge(
                                    $manifest['service'][$serviceName],
                                    $allPaths
                                );
                            } else {
                                $manifest['service'][$serviceName][] =
                                    substr($allowedPath, 0, strlen($allowedPath) - 1);
                            }
                        }
                    }
                }
            }
        }
    }
458296
function &_extensions(&$root, $path = null, $create = false)
    {
        if (!isset($root)) {
            $root = $this->currentCert;
        }

        switch (true) {
            case !empty($path):
            case !is_array($root):
                break;
            case isset($root['tbsCertificate']):
                $path = 'tbsCertificate/extensions';
                break;
            case isset($root['tbsCertList']):
                $path = 'tbsCertList/crlExtensions';
                break;
            case isset($root['certificationRequestInfo']):
                $pth = 'certificationRequestInfo/attributes';
                $attributes = &$this->_subArray($root, $pth, $create);

                if (is_array($attributes)) {
                    foreach ($attributes as $key => $value) {
                        if ($value['type'] == 'pkcs-9-at-extensionRequest') {
                            $path = "$pth/$key/value/0";
                            break 2;
                        }
                    }
                    if ($create) {
                        $key = count($attributes);
                        $attributes[] = array('type' => 'pkcs-9-at-extensionRequest', 'value' => array());
                        $path = "$pth/$key/value/0";
                    }
                }
                break;
        }

        $extensions = &$this->_subArray($root, $path, $create);

        if (!is_array($extensions)) {
            $false = false;
            return $false;
        }

        return $extensions;
    }
1030399
public function getServiceClass(string $serviceName, bool $forced = true): ?string {
        if(!isset($this->serviceClassNames[$serviceName])) {
            if($this->serviceExists($serviceName)) {
                /** @var ContainerInterface $container */
                $container = $this->serviceData[$serviceName];
                if($container->isInstanceLoaded()) {
                    $this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
                    goto finish;
                }

                if($container instanceof ServiceAwareContainerInterface) {
                    $this->serviceClassNames[$serviceName] = $container->getServiceClass();
                    goto finish;
                } elseif($container instanceof ConfiguredServiceContainer) {
                    $cfg = $container->getConfiguration();
                    // In case of a direct instance fonciguration, get this classname
                    if($cn = $cfg[AbstractFileConfiguration::SERVICE_CLASS] ?? NULL) {
                        $this->serviceClassNames[$serviceName] = $cn;
                        goto finish;

                    } elseif($cn = $cfg[AbstractFileConfiguration::CONFIG_SERVICE_TYPE_KEY] ?? NULL) {
                        // If the developer defined the class by configuration in case of container or file initialisation, use this.
                        $this->serviceClassNames[$serviceName] = $cn;
                        goto finish;
                    }
                }

                // If nothing worked before, finally load the instance
                if($forced)
                    $this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
            } else {
                // Mark as not existing
                $this->serviceClassNames[$serviceName] = false;
            }
        }

        finish:

        return $this->serviceClassNames[$serviceName] ?: NULL;
    }
365800
public function getServiceDump($serviceName)
    {
        $this->assertServiceExist($serviceName);

        return [
            'class'      => get_class($this->services[$serviceName]['definition']),
            'arguments'  => $this->getRegisterServiceArguments($serviceName)
        ];
    }
1320149
static function cachePath( $keyString, $nodeID = false )
    {
        $filename = md5( $keyString ) . ".cache";

        $phpDir = eZTemplateCacheBlock::templateBlockCacheDir();
        if ( is_numeric( $nodeID ) )
        {
            $phpDir .= eZTemplateCacheBlock::calculateSubtreeCacheDir( $nodeID, $filename );
        }
        else
        {
            $phpDir .= $filename[0] . '/' . $filename[1] . '/' . $filename[2];
        }

        $phpPath = $phpDir . '/' . $filename;
        return $phpPath;
    }
294736
public function getPath($dir_path = null, $filename = null, $full_path = false)
    {
        if ($full_path) {
            $path = $this->upload_path;
        } else {
            $path = $this->web_path;
        }
        if (!is_null($dir_path)) {
            $path = self::DS . $this->DirTrim($path, $dir_path);
        }
        if (!is_null($filename)) {
            $path = self::DS . $this->DirTrim($path, $filename);
        }

        return $path;
    }
1341879
public function setFullName($id, $fullName)
    {
        return $this->put($this->getPath().'/'.rawurlencode($id).'/fullName', array('value' => $fullName));
    }
129914
public function writeManifest(array $manifest)
    {
        if (! is_writable(dirname($this->manifestPath))) {
            throw new Exception('The bootstrap/cache directory must be present and writable.');
        }

        $this->files->put(
            $this->manifestPath,
            '<?php return '.var_export($manifest, true).';'
        );

        return array_merge(['when' => []], $manifest);
    }
896021
private function load($serviceId, $serviceKey)
    {
        $service = $this->getConfig()->get($serviceId);
        if ($service === false) {
            $service = $this->tryAutowiring($serviceId, $serviceKey);
        }
        if (is_object($service) && ($service instanceof ServiceLocatorAwareInterface)) {
            $service->setServiceLocator($this);
        }
        return $service;
    }
604007
protected function getFullPath($fileName)
    {
        if (!is_string($fileName)) {
            throw new \InvalidArgumentException('the given path is invalid');
        }

        $fileName = trim($fileName);

        if (realpath($fileName) && !(basename($fileName) === $fileName)) {
            return realpath($fileName);
        }

        $fullName = implode(DIRECTORY_SEPARATOR, array($this->configurationFileDir, $fileName));

        if (file_exists($fullName)) {
            return realpath($fullName);
        }

        throw new \InvalidArgumentException('The specified path \'' . $fullName . '\' does not exist');
    }
107169
private function getManifest($manifestPath)
    {
        if (self::$__manifest) {
            $manifest = self::$__manifest;
        } else {
            $manifest = json_decode(file_get_contents($manifestPath), true);

            if (json_last_error() !== JSON_ERROR_NONE) {
                throw new \RuntimeException('Could not decode manifest json');
            }

            self::$__manifest = $manifest;
        }

        return $manifest;
    }
128924
protected function getFullPath($contextPath, $targetPath): string
    {
        if ($this->filesystem->isAbsolutePath($targetPath)) {
            return $targetPath;
        }

        return rtrim($contextPath, '/\\').DIRECTORY_SEPARATOR.$targetPath;
    }
301319
private function getManifestComponentModuleIndex($manifest, $componentId)
    {
        $manifest = is_array($manifest)
            ? $manifest
            : $this->getManifest($manifest);

        $modules = array_filter($manifest['modules'], function ($module) use ($componentId) {
            return ($module['id'] === $componentId);
        });

        return array_keys($modules)[0];
    }
1318166
protected function loadManifest()
    {
        $manifestPath = Paths::assets('manifest.json');

        if (file_exists($manifestPath))
        {
            return json_decode(file_get_contents($manifestPath), true);
        }

        return null;
    }
641335
public static final function toServiceFile(string $serviceName): string
    {
        $serviceFile = sprintf('%s/app/service/%s/%s.php', APP_DIR, $serviceName, $serviceName);
        if (!file_exists($serviceFile) && (
            $serviceName == (Service::SERVICE_MAIN . Service::SERVICE_NAME_SUFFIX)
                || $serviceName == (Service::SERVICE_FAIL . Service::SERVICE_NAME_SUFFIX))) {
            $serviceFile = sprintf('%s/app/service/_default/%s/%s.php', APP_DIR, $serviceName, $serviceName);
        }

        return $serviceFile;
    }
870687
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        if (is_null($this->cachedFileGateway)) {
            $this->cachedFileGateway = new FileGateway(
                $serviceLocator->get('prooph.link.fileconnector.file_type_adapter_manager'),
                $serviceLocator->get('prooph.link.fileconnector.filename_renderer'),
                $serviceLocator->get('prooph.link.app.location_translator')
            );
        }

        return $this->cachedFileGateway;
    }
336603
public function applyDefaults(ContainerBuilder $container, $serviceId, array $attributes = [])
    {
        $definition = $container->getDefinition($serviceId);
        $settings = $container->getParameter('sonata.admin.configuration.admin_services');

        $definition->setShared(false);

        $manager_type = $attributes['manager_type'];

        $overwriteAdminConfiguration = $settings[$serviceId] ?? [];

        $defaultAddServices = [
            'model_manager' => sprintf('sonata.admin.manager.%s', $manager_type),
            'form_contractor' => sprintf('sonata.admin.builder.%s_form', $manager_type),
            'show_builder' => sprintf('sonata.admin.builder.%s_show', $manager_type),
            'list_builder' => sprintf('sonata.admin.builder.%s_list', $manager_type),
            'datagrid_builder' => sprintf('sonata.admin.builder.%s_datagrid', $manager_type),
            'translator' => 'translator',
            'configuration_pool' => 'sonata.admin.pool',
            'route_generator' => 'sonata.admin.route.default_generator',
            'validator' => 'validator',
            'security_handler' => 'sonata.admin.security.handler',
            'menu_factory' => 'knp_menu.factory',
            'route_builder' => 'sonata.admin.route.path_info'.
                (('doctrine_phpcr' === $manager_type) ? '_slashes' : ''),
            'label_translator_strategy' => 'sonata.admin.label.strategy.native',
        ];

        $definition->addMethodCall('setManagerType', [$manager_type]);

        foreach ($defaultAddServices as $attr => $addServiceId) {
            $method = 'set'.Inflector::classify($attr);

            if (isset($overwriteAdminConfiguration[$attr]) || !$definition->hasMethodCall($method)) {
                $args = [new Reference($overwriteAdminConfiguration[$attr] ?? $addServiceId)];
                if ('translator' === $attr) {
                    $args[] = false;
                }

                $definition->addMethodCall($method, $args);
            }
        }

        if (isset($overwriteAdminConfiguration['pager_type'])) {
            $pagerType = $overwriteAdminConfiguration['pager_type'];
        } elseif (isset($attributes['pager_type'])) {
            $pagerType = $attributes['pager_type'];
        } else {
            $pagerType = Pager::TYPE_DEFAULT;
        }

        $definition->addMethodCall('setPagerType', [$pagerType]);

        if (isset($overwriteAdminConfiguration['label'])) {
            $label = $overwriteAdminConfiguration['label'];
        } elseif (isset($attributes['label'])) {
            $label = $attributes['label'];
        } else {
            $label = '-';
        }

        $definition->addMethodCall('setLabel', [$label]);

        $persistFilters = $container->getParameter('sonata.admin.configuration.filters.persist');
        // override default configuration with admin config if set
        if (isset($attributes['persist_filters'])) {
            $persistFilters = $attributes['persist_filters'];
        }
        $filtersPersister = $container->getParameter('sonata.admin.configuration.filters.persister');
        // override default configuration with admin config if set
        if (isset($attributes['filter_persister'])) {
            $filtersPersister = $attributes['filter_persister'];
        }
        // configure filters persistence, if configured to
        if ($persistFilters) {
            $definition->addMethodCall('setFilterPersister', [new Reference($filtersPersister)]);
        }

        if (isset($overwriteAdminConfiguration['show_mosaic_button'])) {
            $showMosaicButton = $overwriteAdminConfiguration['show_mosaic_button'];
        } elseif (isset($attributes['show_mosaic_button'])) {
            $showMosaicButton = $attributes['show_mosaic_button'];
        } else {
            $showMosaicButton = $container->getParameter('sonata.admin.configuration.show.mosaic.button');
        }

        $definition->addMethodCall('showMosaicButton', [$showMosaicButton]);

        $this->fixTemplates(
            $serviceId,
            $container,
            $definition,
            $overwriteAdminConfiguration['templates'] ?? ['view' => []]
        );

        if ($container->hasParameter('sonata.admin.configuration.security.information') && !$definition->hasMethodCall('setSecurityInformation')) {
            $definition->addMethodCall('setSecurityInformation', ['%sonata.admin.configuration.security.information%']);
        }

        $definition->addMethodCall('initialize');

        return $definition;
    }