Get the Fusion Configuration for the given Fusion path

@param string $fusionPath
@return array
@throws Exception
183474
protected function getConfigurationForPath($fusionPath)
    {
        if (isset($this->configurationOnPathRuntimeCache[$fusionPath])) {
            return $this->configurationOnPathRuntimeCache[$fusionPath]['c'];
        }

        $pathParts = explode('/', $fusionPath);
        $configuration = $this->fusionConfiguration;

        $pathUntilNow = '';
        $currentPrototypeDefinitions = [];
        if (isset($configuration['__prototypes'])) {
            $currentPrototypeDefinitions = $configuration['__prototypes'];
        }

        foreach ($pathParts as $pathPart) {
            $pathUntilNow .= '/' . $pathPart;
            if (isset($this->configurationOnPathRuntimeCache[$pathUntilNow])) {
                $configuration = $this->configurationOnPathRuntimeCache[$pathUntilNow]['c'];
                $currentPrototypeDefinitions = $this->configurationOnPathRuntimeCache[$pathUntilNow]['p'];
                continue;
            }

            $configuration = $this->matchCurrentPathPart($pathPart, $configuration, $currentPrototypeDefinitions);
            $this->configurationOnPathRuntimeCache[$pathUntilNow]['c'] = $configuration;
            $this->configurationOnPathRuntimeCache[$pathUntilNow]['p'] = $currentPrototypeDefinitions;
        }

        return $configuration;
    }
1042714
public static function getAllConfigs($modulePath, $config = [])
    {
        $configFile = $modulePath . DIRECTORY_SEPARATOR . UniModule::$configsSubdir . DIRECTORY_SEPARATOR . UniModule::$configBasefilename . '.php';
        if (is_file($configFile)) {
            $addConfig = self::includeConfigFile($configFile);
            if (!empty($addConfig)) {
                $config = ArrayHelper::merge($addConfig, $config);
                if (isset($addConfig['parentPath'])) {
                    $parentPath = Yii::getAlias($addConfig['parentPath']);
                    if (is_dir($parentPath)) $config = self::getAllConfigs($parentPath, $config);
                }
            }
        }
        return $config;
    }
1028015
public function evaluate()
    {
        $path = $this->getPath();
        if ($path === null) {
            throw new FusionException('"path" was not specified', 1386458763);
        }

        $package = $this->getPackage();
        if ($package === null) {
            $controllerContext = $this->runtime->getControllerContext();
            /** @var $actionRequest ActionRequest */
            $actionRequest = $controllerContext->getRequest();
            $package = $actionRequest->getControllerPackageKey();
        }

        return $this->resourceService->getResourceUri($path, $package);
    }
1351689
public function getPathMapping($repositoryPath)
    {
        if (!isset($this->pathMappings[$repositoryPath])) {
            throw NoSuchPathMappingException::forRepositoryPath($repositoryPath);
        }

        return $this->pathMappings[$repositoryPath];
    }
1195526
public function getFiles()
    {
        $finders = [
            MainConfigurationFinder::class,
            ContextualConfigurationFinder::class,
            PluginsConfigurationFinder::class,
        ];

        // Filter out non-existing folders
        $folders = $this->getFolders();
        if (!$folders) {
            return [];
        }

        $files = [];
        foreach ($folders as $folder) {
            foreach ($finders as $finder) {
                /** @var AbstractConfigurationFinder $finder */
                $finder = new $finder($this->files, $folder);
                $files = array_merge($files, $finder->getFiles());
            }
        }

        // Load consolidated configuration
        $folder = $this->paths->getRocketeerPath();
        if ($this->files->has($folder)) {
            $consolidated = new ConsolidatedConfigurationFinder($this->files, $folder);
            $files = array_merge($files, $consolidated->getFiles());
        }

        return $files;
    }
237980
public function getStyleguideObjectsFromFusionAst($fusionAst)
    {
        $styleguideObjects = [];
        if ($fusionAst && $fusionAst['__prototypes']) {
            foreach ($fusionAst['__prototypes'] as $prototypeFullName => $prototypeObject) {
                if (array_key_exists('__meta', $prototypeObject) && is_array($prototypeObject['__meta']) && array_key_exists('styleguide', $prototypeObject['__meta'])) {
                    list($prototypeVendor, $prototypeName) = explode(':', $prototypeFullName, 2);
                    $styleguideConfiguration = $prototypeObject['__meta']['styleguide'];
                    $styleguideObjects[$prototypeFullName] = [
                        'title' => (isset($styleguideConfiguration['title'])) ? $styleguideConfiguration['title'] : implode(' ', array_reverse(explode('.', $prototypeName))),
                        'path' => (isset($styleguideConfiguration['path'])) ? $styleguideConfiguration['path'] : $prototypeName,
                        'description' => (isset($styleguideConfiguration['description'])) ? $styleguideConfiguration['description'] :  '',
                        'options' => (isset($styleguideConfiguration['options'])) ? $styleguideConfiguration['options'] : null,
                    ];
                }
            }
        }
        return $styleguideObjects;
    }
610994
protected function handle($fusionPath, \Exception $exception, $referenceCode)
    {
        $this->systemLogger->debug('Absorbed Exception: ' . $exception->getMessage(), ['fusionPath' => $fusionPath, 'referenceCode' => $referenceCode, 'FLOW_LOG_ENVIRONMENT' => ['packageKey' => 'Neos.Fusion', 'className' => self::class, 'methodName' => 'handle']]);
        return '';
    }
855684
protected function handle($fusionPath, \Exception $exception, $referenceCode)
    {
        $context = $this->environment->getContext();
        if ($context->isDevelopment()) {
            $handler = new HtmlMessageHandler();
        } else {
            $handler = new XmlCommentHandler();
        }
        $handler->setRuntime($this->getRuntime());
        return $handler->handleRenderingException($fusionPath, $exception);
    }
922746
public function getList(string $path)
    {
        $entity = $this->getEntity($path);

        if (null !== $entity && $entity->file_exists() && $entity->is_dir()) {
            $files = [];
            $changes = $this->getChanges();
            $own = $changes->own($path);

            if (!($entity instanceof VirtualInterface)) {
                $directory = $this->getRoot();
                $directoryPath = $directory->path().'/'.$path;

                $dirHandler = opendir($directoryPath);
                if ($dirHandler) {
                    while (true) {
                        $file = readdir($dirHandler);
                        if (false === $file) {
                            break;
                        } elseif ('.' == $file || '..' == $file) {
                            continue;
                        }

                        $changesKey = ($path ? $path.'/' : '').$file;
                        if (isset($own[$changesKey])) {
                            continue;
                        }
                        $files[$changesKey] = Entity::newInstance($changesKey);
                    }
                    closedir($dirHandler);
                }
            }

            foreach ($own as $changesKey => $file) {
                /* @var $file EntityInterface */
                if ($file instanceof DeletedInterface) {
                    unset($own[$changesKey]);
                }
            }

            $mergedFiles = array_merge($files, $own);
            ksort($mergedFiles);

            $result = array_values($mergedFiles);
        } else {
            $result = null;
        }

        return $result;
    }
715960
protected function getCachedConfiguration($filePaths)
    {
        // Return cached version if available
        if (!$this->cache->isFresh()) {
            return;
        }

        // If the files the configuration was cached from
        // match the ones we have, return the cache
        $cache = $this->cache->getContents();
        if (Arr::get($cache, 'meta') === $filePaths) {
            return $cache;
        }
    }
1332173
public function handleRenderingException($fusionPath, \Exception $exception)
    {
        if ($exception instanceof StopActionException || $exception instanceof SecurityException) {
            throw $exception;
        }
        if ($exception instanceof Exceptions\RuntimeException) {
            $fusionPath = $exception->getFusionPath();
            $exception = $exception->getPrevious();
        }
        if ($this->exceptionDisablesCache($fusionPath, $exception)) {
            $this->runtime->setEnableContentCache(false);
        }
        $referenceCode = ($exception instanceof \Neos\Flow\Exception) ? $exception->getReferenceCode() : null;
        return $this->handle($fusionPath, $exception, $referenceCode);
    }
1137969
public function loadConfiguration($path = self::CONFIG_DEFAULT_FILE)
    {
        if (!is_file($path)) {
            return false;
        }

        $this->configuration = include $path;

        if (!is_array($this->configuration)) {
            throw new ConfigurationException('Configuration file ' . $path . ' must return an array');
        }

        $filesystem = new Filesystem();

        if ($filesystem->isAbsolutePath($this->configuration['web-dir'])) {
            $this->setDocumentRoot($this->configuration['web-dir']);
        } else {
            $this->setDocumentRoot($this->getRoot() . '/' . $this->configuration['web-dir']);
        }

        if (!is_dir($_SERVER['DOCUMENT_ROOT'])) {
            return false;
        }

        return true;
    }
1074434
public function getPluginConfiguration($pluginPath)
    {
        $yaml = new Parser();
        $specificationFilePath = $pluginPath . '/plugin.yml';
        if (!file_exists($specificationFilePath)) {
            return [];
        }

        $parsedConfiguration = $yaml->parse(file_get_contents($specificationFilePath));
        if (!is_array($parsedConfiguration)) {
            return [];
        }

        $processor = new Processor();
        $pluginConfiguration = $processor
            ->processConfiguration(
                new PluginConfigurationTree(),
                $parsedConfiguration
            );

        return $pluginConfiguration;
    }
1103986
protected function handlePropTypeException($fusionPath, PropTypeException $exception, $referenceCode)
    {
        $messageBody = sprintf('<p class="neos-message-content">%s</p>', htmlspecialchars($exception->getMessage()));

        if ($this->renderTechnicalDetails) {
            $result = $exception->getResult();
            if ($result && $result->hasErrors()) {
                $errors = $result->getFlattenedErrors();
                $renderedErrors = [];
                foreach ($errors as $path => $pathErrors) {
                    foreach ($pathErrors as $error) {
                        $renderedErrors[] = sprintf('%s: %s', $path, $error->render());
                    }
                }
                $messageBody .= sprintf('<p class="neos-message-stacktrace">The following errors were detected:<br/><code style="white-space: pre-wrap"> - %s</code></p>', implode(chr(10) . ' - ', $renderedErrors));
                $messageBody .= sprintf('<p class="neos-message-stacktrace"><code>FusionPath: %s</code></p>', htmlspecialchars($fusionPath));

            }
        }

        if ($referenceCode) {
            $messageBody .= sprintf('<p class="neos-reference-code">%s</p>', $this->formatErrorCodeMessage($referenceCode));
        }

        $message = sprintf(
            '<div class="neos-message-header"><div class="neos-message-icon"><i class="icon-warning-sign"></i></div><h1>An exception was thrown while Neos tried to render your page</h1></div>' .
            '<div class="neos-message-wrapper">%s</div>',
            $messageBody
        );

        $this->systemLogger->logException($exception);
        return $message;
    }
1069162
public static function getRootDir($bundlepath = false)
    {
        if (static::isSymfony()) {
            $dir = dirname(static::getCont()->getParameter('kernel.root_dir'));

            if (is_object($bundlepath)) {
                $path = get_class($bundlepath);
                $bundle = preg_replace('#^(.*?\\\\[^\\\\]+Bundle)\\\\.*$#', '$1', $path);
                if ($path !== $bundle) {
                    $bundle = str_replace('\\', '/', $bundle);

                    return static::getRootDir().'/src/'.$bundle;
                }
                throw new Exeption("Can't analyse path '$path' to find bundle directory");
            }
            if ($bundlepath) {
                return static::getKernel()->getBundle($bundlepath)->getPath();
    //            $n = get_called_class();
    //            $n = substr($n, 0, -strlen(strrchr($n, '\\')));
    //            $n = substr($n, 0, -strlen(strrchr($n, '\\')));
    //            $n = str_replace('\\', '/', $n);
    //            $dir .= "/src/$n";
            }

            return $dir;
        } else {
            if ($bundlepath !== false) {
                throw new Exception("This is not Symfony 2, can't user getRootDir with parameter");
            }
            // nie wiem czy to najlepsze ale najwyżej później to wymienie
            if (!static::$root) {
                $reflection = new ReflectionClass('Composer\Autoload\ClassLoader');
                static::$root = str_replace('\\', '/', dirname(dirname(dirname($reflection->getFileName()))));
            }

            return static::$root;
        }
    }
2307
protected function evaluateProcessors($valueToProcess, $configurationWithEventualProcessors, $fusionPath, AbstractFusionObject $contextObject = null)
    {
        if (isset($configurationWithEventualProcessors['__meta']['process'])) {
            $processorConfiguration = $configurationWithEventualProcessors['__meta']['process'];
            $positionalArraySorter = new PositionalArraySorter($processorConfiguration, '__meta.position');
            foreach ($positionalArraySorter->getSortedKeys() as $key) {
                $processorPath = $fusionPath . '/__meta/process/' . $key;
                if ($this->evaluateIfCondition($processorConfiguration[$key], $processorPath, $contextObject) === false) {
                    continue;
                }
                if (isset($processorConfiguration[$key]['expression'])) {
                    $processorPath .= '/expression';
                }

                $this->pushContext('value', $valueToProcess);
                $result = $this->evaluateInternal($processorPath, self::BEHAVIOR_EXCEPTION, $contextObject);
                if ($this->getLastEvaluationStatus() !== static::EVALUATION_SKIPPED) {
                    $valueToProcess = $result;
                }
                $this->popContext();
            }
        }

        return $valueToProcess;
    }
486722
protected function canRenderWithConfiguration(array $fusionConfiguration)
    {
        if ($this->hasExpressionOrValue($fusionConfiguration)) {
            return true;
        }

        if (isset($fusionConfiguration['__meta']['class']) && isset($fusionConfiguration['__objectType'])) {
            return true;
        }

        return false;
    }