/**
  * 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 \TYPO3\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);
 }
 /**
  * @test
  */
 public function splitConfigurationFilesAreMergedAsExpected()
 {
     $expectedConfiguration = array('configurationFileHasBeenLoaded' => TRUE, 'TYPO3' => array('Flow' => array('default' => 'test', 'toBeOverwritten' => 2, 'something' => 'zzz', '@bar' => 1, 'aboolean' => TRUE)));
     $pathAndFilename = __DIR__ . '/../Fixture/SplitYamlConfigurationFile';
     $configurationSource = new \TYPO3\Flow\Configuration\Source\YamlSource();
     $configuration = $configurationSource->load($pathAndFilename, TRUE);
     $this->assertSame($expectedConfiguration, $configuration);
 }
Example #3
0
 /**
  * Checks if the configured PHP binary is executable and the same version as the one
  * running the current (web server) PHP process. If not or if there is no binary configured,
  * tries to find the correct one on the PATH.
  *
  * Once found, the binary will be written to the configuration, if it is not the default one
  * (PHP_BINARY or in PHP_BINDIR).
  *
  * @return Message An error or warning message or NULL if PHP was detected successfully
  */
 protected function checkAndSetPhpBinaryIfNeeded()
 {
     $configurationSource = new \TYPO3\Flow\Configuration\Source\YamlSource();
     $distributionSettings = $configurationSource->load(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
     if (isset($distributionSettings['TYPO3']['Flow']['core']['phpBinaryPathAndFilename'])) {
         return $this->checkPhpBinary($distributionSettings['TYPO3']['Flow']['core']['phpBinaryPathAndFilename']);
     }
     list($phpBinaryPathAndFilename, $message) = $this->detectPhpBinaryPathAndFilename();
     if ($phpBinaryPathAndFilename !== NULL) {
         $defaultPhpBinaryPathAndFilename = PHP_BINDIR . '/php';
         if (DIRECTORY_SEPARATOR !== '/') {
             $defaultPhpBinaryPathAndFilename = str_replace('\\', '/', $defaultPhpBinaryPathAndFilename) . '.exe';
         }
         if ($phpBinaryPathAndFilename !== $defaultPhpBinaryPathAndFilename) {
             $distributionSettings = \TYPO3\Flow\Utility\Arrays::setValueByPath($distributionSettings, 'TYPO3.Flow.core.phpBinaryPathAndFilename', $phpBinaryPathAndFilename);
             $configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $distributionSettings);
         }
     }
     return $message;
 }
 /**
  * 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);
     $expectedConfigurationFileName = $configurationType . '.yaml';
     $configurationPathsAndFilenames = array_filter($yamlPathsAndFilenames, function ($pathAndFileName) use($expectedConfigurationFileName) {
         if (basename($pathAndFileName) === $expectedConfigurationFileName) {
             return TRUE;
         } else {
             return FALSE;
         }
     });
     $yamlSource = new \TYPO3\Flow\Configuration\Source\YamlSource();
     foreach ($configurationPathsAndFilenames as $pathAndFilename) {
         $configuration = $yamlSource->load(substr($pathAndFilename, 0, -5));
         $processor($configuration);
         if ($saveResult === TRUE) {
             $yamlSource->save(substr($pathAndFilename, 0, -5), $configuration);
         }
     }
 }