/**
  * Add a warning for each HTML file that uses one of the f:uri.* or the f:format.json ViewHelpers
  *
  * @param string $packagePath
  * @return void
  */
 protected function addWarningsForAffectedViewHelpers($packagePath)
 {
     $foundAffectedViewHelpers = array();
     $allPathsAndFilenames = Files::readDirectoryRecursively($packagePath, null, true);
     foreach ($allPathsAndFilenames as $pathAndFilename) {
         $pathInfo = pathinfo($pathAndFilename);
         if (!isset($pathInfo['filename']) || $pathInfo['extension'] !== 'html') {
             continue;
         }
         $fileContents = file_get_contents($pathAndFilename);
         preg_match_all('/f\\:(uri\\.[\\w]+|format\\.json)/', $fileContents, $matches, PREG_SET_ORDER);
         foreach ($matches as $match) {
             $viewHelperName = $match[1];
             if (!isset($foundAffectedViewHelpers[$viewHelperName])) {
                 $foundAffectedViewHelpers[$viewHelperName] = array();
             }
             $truncatedPathAndFilename = substr($pathAndFilename, strlen($packagePath) + 1);
             if (!in_array($truncatedPathAndFilename, $foundAffectedViewHelpers[$viewHelperName])) {
                 $foundAffectedViewHelpers[$viewHelperName][] = $truncatedPathAndFilename;
             }
         }
     }
     foreach ($foundAffectedViewHelpers as $viewHelperName => $filePathsAndNames) {
         $this->showWarning(sprintf('The behavior of the "%s" ViewHelper has been changed to produce escaped output.' . chr(10) . 'This package makes use of this ViewHelper in the following files:' . chr(10) . '- %s' . chr(10) . 'See upgrading instructions for further details.' . chr(10), $viewHelperName, implode(chr(10) . '- ', $filePathsAndNames)));
     }
 }
 public function up()
 {
     $affectedFiles = array();
     $allPathsAndFilenames = Files::readDirectoryRecursively($this->targetPackageData['path'], null, true);
     foreach ($allPathsAndFilenames as $pathAndFilename) {
         if (substr($pathAndFilename, -14) !== 'ViewHelper.php') {
             continue;
         }
         $fileContents = file_get_contents($pathAndFilename);
         if (preg_match('/\\$this->reflectionService/', $fileContents) === 1) {
             $affectedFiles[] = substr($pathAndFilename, strlen($this->targetPackageData['path']) + 1);
         }
     }
     if ($affectedFiles !== array()) {
         $this->showWarning('Following ViewHelpers might use a removed ReflectionService dependency from AbstractViewHelper, please inject a ReflectionService instance yourself:' . PHP_EOL . PHP_EOL . '* ' . implode(PHP_EOL . '* ', $affectedFiles));
     }
 }
 /**
  * Apply the given processor to the raw results of loading the given configuration
  * type for the package from YAML. If multiple files exist (context configuration)
  * all are processed independently.
  *
  * @param string $configurationType One of ConfigurationManager::CONFIGURATION_TYPE_*
  * @param \Closure $processor
  * @param boolean $saveResult
  * @return void
  */
 protected function processConfiguration($configurationType, \Closure $processor, $saveResult = false)
 {
     if (is_dir($this->targetPackageData['path'] . '/Configuration') === false) {
         return;
     }
     $yamlPathsAndFilenames = Files::readDirectoryRecursively($this->targetPackageData['path'] . '/Configuration', 'yaml', true);
     $configurationPathsAndFilenames = array_filter($yamlPathsAndFilenames, function ($pathAndFileName) use($configurationType) {
         if (strpos(basename($pathAndFileName, '.yaml'), $configurationType) === 0) {
             return true;
         } else {
             return false;
         }
     });
     $yamlSource = new YamlSource();
     foreach ($configurationPathsAndFilenames as $pathAndFilename) {
         $originalConfiguration = $configuration = $yamlSource->load(substr($pathAndFilename, 0, -5));
         $processor($configuration);
         if ($saveResult === true && $configuration !== $originalConfiguration) {
             $yamlSource->save(substr($pathAndFilename, 0, -5), $configuration);
         }
     }
 }
 /**
  * Reads all Policy.yaml files below Packages, extracts the roles and prepends
  * them with the package key "guessed" from the path.
  *
  * @return array
  */
 protected function loadRolesFromPolicyFiles()
 {
     $roles = array();
     $yamlPathsAndFilenames = Files::readDirectoryRecursively(__DIR__ . '/../../../../../Packages', 'yaml', true);
     $configurationPathsAndFilenames = array_filter($yamlPathsAndFilenames, function ($pathAndFileName) {
         if (basename($pathAndFileName) === 'Policy.yaml') {
             return true;
         } else {
             return false;
         }
     });
     $yamlSource = new \Neos\Flow\Configuration\Source\YamlSource();
     foreach ($configurationPathsAndFilenames as $pathAndFilename) {
         if (preg_match('%Packages/.+/([^/]+)/Configuration/(?:Development|Production|Policy).+%', $pathAndFilename, $matches) === 0) {
             continue;
         }
         $packageKey = $matches[1];
         $configuration = $yamlSource->load(substr($pathAndFilename, 0, -5));
         if (isset($configuration['roles']) && is_array($configuration['roles'])) {
             foreach ($configuration['roles'] as $roleIdentifier => $parentRoles) {
                 $roles[$packageKey . ':' . $roleIdentifier] = true;
             }
         }
     }
     return array_keys($roles);
 }
 /**
  * Load TypoScript from the directories specified by $this->getOption('typoScriptPathPatterns')
  *
  * @return void
  */
 protected function loadTypoScript()
 {
     $mergedTypoScriptCode = '';
     $typoScriptPathPatterns = $this->getOption('typoScriptPathPatterns');
     ksort($typoScriptPathPatterns);
     foreach ($typoScriptPathPatterns as $typoScriptPathPattern) {
         $typoScriptPathPattern = str_replace('@package', $this->getPackageKey(), $typoScriptPathPattern);
         $filePaths = array_merge(Files::readDirectoryRecursively($typoScriptPathPattern, '.fusion'), Files::readDirectoryRecursively($typoScriptPathPattern, '.ts2'));
         sort($filePaths);
         foreach ($filePaths as $filePath) {
             $mergedTypoScriptCode .= PHP_EOL . file_get_contents($filePath) . PHP_EOL;
         }
     }
     $this->parsedTypoScript = $this->typoScriptParser->parse($mergedTypoScriptCode);
 }