/**
  * @test
  */
 public function saveWritesDoesNotOverwriteExistingHeaderCommentsIfFileExists()
 {
     $pathAndFilename = vfsStream::url('testDirectory') . '/YAMLConfiguration';
     $comment = '# This comment should stay' . chr(10) . 'Test: foo' . chr(10);
     file_put_contents($pathAndFilename . '.yaml', $comment);
     $configurationSource = new \TYPO3\Flow\Configuration\Source\YamlSource();
     $configurationSource->save($pathAndFilename, array('configurationFileHasBeenLoaded' => TRUE));
     $yaml = file_get_contents($pathAndFilename . '.yaml');
     $this->assertContains('# This comment should stay' . chr(10) . chr(10), $yaml, 'Header comment was removed from file.');
     $this->assertNotContains('Test: foo', $yaml);
 }
예제 #2
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;
 }
예제 #3
0
 /**
  * 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);
         }
     }
 }