/**
  * Include all JavaScript files matching the include regular expression
  * and not matching the exclude regular expression.
  *
  * @param string $include Regular expression of files to include
  * @param string $exclude Regular expression of files to exclude
  * @param string $package The package key of the resources to include or current controller package if NULL
  * @param string $subpackage The subpackage key of the resources to include or current controller subpackage if NULL
  * @param string $directory The directory inside the current subpackage. By default, the "JavaScript" directory will be used.
  * @return string
  */
 public function render($include, $exclude = NULL, $package = NULL, $subpackage = NULL, $directory = 'JavaScript')
 {
     $packageKey = $package === NULL ? $this->controllerContext->getRequest()->getControllerPackageKey() : $package;
     $subpackageKey = $subpackage === NULL ? $this->controllerContext->getRequest()->getControllerSubpackageKey() : $subpackage;
     $baseDirectory = 'resource://' . $packageKey . '/Public/' . ($subpackageKey !== NULL ? $subpackageKey . '/' : '') . $directory . '/';
     $staticJavaScriptWebBaseUri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/' . $packageKey . '/' . ($subpackageKey !== NULL ? $subpackageKey . '/' : '') . $directory . '/';
     $iterator = $this->iterateDirectoryRecursively($baseDirectory);
     if ($iterator === NULL) {
         return '<!-- Warning: Cannot include JavaScript because directory "' . $baseDirectory . '" does not exist. -->';
     }
     $uris = array();
     foreach ($iterator as $file) {
         $relativePath = substr($file->getPathname(), strlen($baseDirectory));
         $relativePath = \TYPO3\Flow\Utility\Files::getUnixStylePath($relativePath);
         if (!$this->patternMatchesPath($exclude, $relativePath) && $this->patternMatchesPath($include, $relativePath)) {
             $uris[] = $staticJavaScriptWebBaseUri . $relativePath;
         }
     }
     // Sadly, the aloha editor needs a predefined inclusion order, which right now matches
     // the sorted URI list. that's why we sort here...
     asort($uris);
     $output = '';
     foreach ($uris as $uri) {
         $output .= '<script src="' . $uri . '"></script>' . chr(10);
     }
     return $output;
 }
 /**
  * Creates an Image object from a file using a mock resource (in order to avoid a database resource pointer entry)
  * @param string $imagePathAndFilename
  * @return \TYPO3\Flow\Resource\Resource
  */
 protected function getMockResourceByImagePath($imagePathAndFilename)
 {
     $imagePathAndFilename = \TYPO3\Flow\Utility\Files::getUnixStylePath($imagePathAndFilename);
     $hash = sha1_file($imagePathAndFilename);
     copy($imagePathAndFilename, 'resource://' . $hash);
     return $mockResource = $this->createMockResourceAndPointerFromHash($hash);
 }
 /**
  * Loads a list of available versions into an array.
  *
  * @return array
  * @throws \TYPO3\TYPO3CR\Migration\Exception\MigrationException
  */
 protected function registerAvailableVersions()
 {
     $this->availableVersions = array();
     foreach ($this->packageManager->getActivePackages() as $package) {
         $possibleMigrationsPath = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getPackagePath(), 'Migrations/TYPO3CR'));
         if (!is_dir($possibleMigrationsPath)) {
             continue;
         }
         $directoryIterator = new \DirectoryIterator($possibleMigrationsPath);
         foreach ($directoryIterator as $fileInfo) {
             $filename = $fileInfo->getFilename();
             if ($fileInfo->isFile() && $filename[0] !== '.' && substr($filename, -5) === '.yaml') {
                 $versionFile = Files::getUnixStylePath($fileInfo->getPathname());
                 $versionNumber = substr(substr($filename, 7), 0, -5);
                 if (array_key_exists($versionNumber, $this->availableVersions)) {
                     throw new \TYPO3\TYPO3CR\Migration\Exception\MigrationException('The migration version ' . $versionNumber . ' exists twice, that is not supported.', 1345823182);
                 }
                 $this->availableVersions[$versionNumber] = array('filePathAndName' => $versionFile, 'package' => $package, 'formattedVersionNumber' => $versionNumber[6] . $versionNumber[7] . '-' . $versionNumber[4] . $versionNumber[5] . '-' . $versionNumber[0] . $versionNumber[1] . $versionNumber[2] . $versionNumber[3] . ' ' . $versionNumber[8] . $versionNumber[9] . ':' . $versionNumber[10] . $versionNumber[11] . ':' . $versionNumber[12] . $versionNumber[13]);
             }
         }
     }
     ksort($this->availableVersions);
 }
예제 #4
0
 /**
  * Checks if the given PHP binary is executable and of the same version as the currently running one.
  *
  * @param string $phpBinaryPathAndFilename
  * @return Message An error or warning message or NULL if the PHP binary was detected successfully
  */
 protected function checkPhpBinary($phpBinaryPathAndFilename)
 {
     $phpVersion = NULL;
     if (file_exists($phpBinaryPathAndFilename) && is_file($phpBinaryPathAndFilename)) {
         if (DIRECTORY_SEPARATOR === '/') {
             $phpCommand = '"' . escapeshellcmd(Files::getUnixStylePath($phpBinaryPathAndFilename)) . '"';
         } else {
             $phpCommand = escapeshellarg(Files::getUnixStylePath($phpBinaryPathAndFilename));
         }
         // If the tested binary is a CGI binary that also runs the current request the SCRIPT_FILENAME would take precedence and create an endless recursion.
         $possibleScriptFilenameValue = getenv('SCRIPT_FILENAME');
         putenv('SCRIPT_FILENAME');
         exec($phpCommand . ' -v', $phpVersionString);
         if ($possibleScriptFilenameValue !== FALSE) {
             putenv('SCRIPT_FILENAME=' . (string) $possibleScriptFilenameValue);
         }
         if (!isset($phpVersionString[0]) || strpos($phpVersionString[0], '(cli)') === FALSE) {
             return new Error('The specified path to your PHP binary (see Configuration/Settings.yaml) is incorrect or not a PHP command line (cli) version.', 1341839376, array(), 'Environment requirements not fulfilled');
         }
         $versionStringParts = explode(' ', $phpVersionString[0]);
         $phpVersion = isset($versionStringParts[1]) ? trim($versionStringParts[1]) : NULL;
         if ($phpVersion === PHP_VERSION) {
             return NULL;
         }
     }
     if ($phpVersion === NULL) {
         return new Error('The specified path to your PHP binary (see Configuration/Settings.yaml) is incorrect.', 1341839376, array(), 'Environment requirements not fulfilled');
     } else {
         $phpMinorVersionMatch = array_slice(explode('.', $phpVersion), 0, 2) === array_slice(explode('.', PHP_VERSION), 0, 2);
         if ($phpMinorVersionMatch) {
             return new \TYPO3\Flow\Error\Warning('The specified path to your PHP binary (see Configuration/Settings.yaml) points to a PHP binary with the version "%s". This is not the exact same version as is currently running ("%s").', 1416913501, array($phpVersion, PHP_VERSION), 'Possible PHP version mismatch');
         } else {
             return new Error('The specified path to your PHP binary (see Configuration/Settings.yaml) points to a PHP binary with the version "%s". This is not compatible to the version that is currently running ("%s").', 1341839377, array($phpVersion, PHP_VERSION), 'Environment requirements not fulfilled');
         }
     }
 }
 /**
  * @param string $commandIdentifier E.g. typo3.flow:cache:flush
  * @param array $settings The TYPO3.Flow settings
  * @param array $commandArguments Command arguments
  *
  * @return string A command line command ready for being exec()uted
  */
 protected static function buildSubprocessCommand($commandIdentifier, $settings, array $commandArguments = array())
 {
     $subRequestEnvironmentVariables = array('FLOW_ROOTPATH' => FLOW_PATH_ROOT, 'FLOW_CONTEXT' => $settings['core']['context']);
     if (isset($settings['core']['subRequestEnvironmentVariables'])) {
         $subRequestEnvironmentVariables = array_merge($subRequestEnvironmentVariables, $settings['core']['subRequestEnvironmentVariables']);
     }
     $command = '';
     foreach ($subRequestEnvironmentVariables as $argumentKey => $argumentValue) {
         if (DIRECTORY_SEPARATOR === '/') {
             $command .= sprintf('%s=%s ', $argumentKey, escapeshellarg($argumentValue));
         } else {
             $command .= sprintf('SET %s=%s&', $argumentKey, escapeshellarg($argumentValue));
         }
     }
     if (DIRECTORY_SEPARATOR === '/') {
         $phpBinaryPathAndFilename = '"' . escapeshellcmd(\TYPO3\Flow\Utility\Files::getUnixStylePath($settings['core']['phpBinaryPathAndFilename'])) . '"';
     } else {
         $phpBinaryPathAndFilename = escapeshellarg(\TYPO3\Flow\Utility\Files::getUnixStylePath($settings['core']['phpBinaryPathAndFilename']));
     }
     $command .= $phpBinaryPathAndFilename;
     if (!isset($settings['core']['subRequestPhpIniPathAndFilename']) || $settings['core']['subRequestPhpIniPathAndFilename'] !== FALSE) {
         if (!isset($settings['core']['subRequestPhpIniPathAndFilename'])) {
             $useIniFile = php_ini_loaded_file();
         } else {
             $useIniFile = $settings['core']['subRequestPhpIniPathAndFilename'];
         }
         $command .= ' -c ' . escapeshellarg($useIniFile);
     }
     $escapedArguments = '';
     if ($commandArguments !== array()) {
         foreach ($commandArguments as $argument => $argumentValue) {
             $escapedArguments .= ' ' . escapeshellarg('--' . trim($argument));
             if (trim($argumentValue) !== '') {
                 $escapedArguments .= ' ' . escapeshellarg(trim($argumentValue));
             }
         }
     }
     $command .= sprintf(' %s %s %s', escapeshellarg(FLOW_PATH_FLOW . 'Scripts/flow.php'), escapeshellarg($commandIdentifier), trim($escapedArguments));
     return trim($command);
 }
 /**
  * Scans all sub directories of the specified directory and collects the package keys of packages it finds.
  *
  * The return of the array is to make this method usable in array_merge.
  *
  * @param string $startPath
  * @param array $collectedPackagePaths
  * @return array
  */
 protected function scanPackagesInPath($startPath, array &$collectedPackagePaths = array())
 {
     foreach (new \DirectoryIterator($startPath) as $fileInfo) {
         if (!$fileInfo->isDir()) {
             continue;
         }
         $filename = $fileInfo->getFilename();
         if ($filename[0] !== '.') {
             $currentPath = Files::getUnixStylePath($fileInfo->getPathName());
             $composerManifestPaths = $this->findComposerManifestPaths($currentPath);
             foreach ($composerManifestPaths as $composerManifestPath) {
                 $targetDirectory = rtrim(self::getComposerManifest($composerManifestPath, 'target-dir'), '/');
                 $packagePath = $targetDirectory ? substr(rtrim($composerManifestPath, '/'), 0, -strlen((string) $targetDirectory)) : $composerManifestPath;
                 $collectedPackagePaths[$packagePath] = $composerManifestPath;
             }
         }
     }
     return $collectedPackagePaths;
 }
예제 #7
0
 /**
  * Expands the given $patterns by adding an array element for each $replacement
  * replacing occurrences of $search.
  *
  * @param array $patterns
  * @param string $search
  * @param array $replacements
  * @return void
  */
 protected function expandPatterns(array &$patterns, $search, array $replacements)
 {
     $patternsWithReplacements = array();
     foreach ($patterns as $pattern) {
         foreach ($replacements as $replacement) {
             $patternsWithReplacements[] = Files::getUnixStylePath(str_replace($search, $replacement, $pattern));
         }
     }
     $patterns = $patternsWithReplacements;
 }
 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->unixStylePath = Files::getUnixStylePath(__DIR__);
     $this->unixStylePathAndFilename = Files::getUnixStylePath(__FILE__);
     vfsStream::setup('testDirectory');
 }
예제 #9
0
 /**
  * Checks if PHP binary file exists bypassing open_basedir violation.
  *
  * If PHP binary is not within open_basedir path,
  * it is impossible to access this binary in any other way than exec() or system().
  * So we must check existence of this file with system tools.
  *
  * @param string $phpBinaryPathAndFilename
  * @return boolean
  */
 protected function phpBinaryExistsAndIsExecutableFile($phpBinaryPathAndFilename)
 {
     $phpBinaryPathAndFilename = escapeshellarg(Files::getUnixStylePath($phpBinaryPathAndFilename));
     if (DIRECTORY_SEPARATOR === '/') {
         $command = sprintf('test -f %s && test -x %s', $phpBinaryPathAndFilename, $phpBinaryPathAndFilename);
     } else {
         $command = sprintf('IF EXIST %s (IF NOT EXIST %s\\* (EXIT 0) ELSE (EXIT 1)) ELSE (EXIT 1)', $phpBinaryPathAndFilename, $phpBinaryPathAndFilename);
     }
     exec($command, $outputLines, $exitCode);
     if ($exitCode === 0) {
         return true;
     }
     return false;
 }
 /**
  * Resolve the partial path and filename based on $this->getPartialRootPath() and request format
  *
  * @param string $partialName The name of the partial
  * @return string the full path which should be used. The path definitely exists.
  * @throws Exception\InvalidTemplateResourceException
  */
 protected function getPartialPathAndFilename($partialName)
 {
     $partialRootPath = $this->getPartialRootPath();
     if (!is_dir($partialRootPath)) {
         throw new Exception\InvalidTemplateResourceException('Partial root path "' . $partialRootPath . '" does not exist.', 1288094648);
     }
     $possiblePartialPaths = array();
     $possiblePartialPaths[] = Files::getUnixStylePath($partialRootPath . '/' . $partialName . '.' . $this->getRequest()->getFormat());
     $possiblePartialPaths[] = Files::getUnixStylePath($partialRootPath . '/' . $partialName);
     foreach ($possiblePartialPaths as $partialPathAndFilename) {
         if (is_file($partialPathAndFilename)) {
             return $partialPathAndFilename;
         }
     }
     throw new Exception\InvalidTemplateResourceException('Could not load partial file. Tried following paths: "' . implode('", "', $possiblePartialPaths) . '".', 1288092555);
 }
 /**
  * @test
  * @param string $path
  * @param string $expected
  * @dataProvider pathsWithProtocol
  */
 public function getUnixStylePathWorksForPathWithProtocol($path, $expected)
 {
     $this->assertEquals($expected, Files::getUnixStylePath($path));
 }
 /**
  * Create a package, given the package key
  *
  * @param string $packageKey The package key of the new package
  * @param \TYPO3\Flow\Package\MetaData $packageMetaData If specified, this package meta object is used for writing the Package.xml file, otherwise a rudimentary Package.xml file is created
  * @param string $packagesPath If specified, the package will be created in this path, otherwise the default "Application" directory is used
  * @param string $packageType
  * @param array $manifest A composer manifest as associative array. This is a preparation for the signature change in Flow 4.0. If you use this argument, then $packageMetaData and $packageType will be ignored.
  * @return PackageInterface The newly created package
  *
  * @throws Exception\InvalidPackageKeyException
  * @throws Exception\PackageKeyAlreadyExistsException
  * @api
  * @deprecated The method signature of this method will change with Flow 4.0, the method itself will stay.
  * @see \TYPO3\Flow\Package\PackageManagerInterface::createPackage
  */
 public function createPackage($packageKey, \TYPO3\Flow\Package\MetaData $packageMetaData = null, $packagesPath = null, $packageType = 'neos-package', array $manifest = null)
 {
     if (!$this->isPackageKeyValid($packageKey)) {
         throw new Exception\InvalidPackageKeyException('The package key "' . $packageKey . '" is invalid', 1220722210);
     }
     if ($this->isPackageAvailable($packageKey)) {
         throw new Exception\PackageKeyAlreadyExistsException('The package key "' . $packageKey . '" already exists', 1220722873);
     }
     // TODO: This if and the method used can be removed for Flow 4.0 together with the MetaData classes.
     if ($manifest === null) {
         $manifest = $this->generateManifestFromMetaDataAndType($packageType, $packageMetaData);
     }
     if ($packagesPath === null) {
         $packagesPath = 'Application';
         $packageType = isset($manifest['type']) ? $manifest['type'] : PackageInterface::DEFAULT_COMPOSER_TYPE;
         if (is_array($this->settings['package']['packagesPathByType']) && isset($this->settings['package']['packagesPathByType'][$packageType])) {
             $packagesPath = $this->settings['package']['packagesPathByType'][$packageType];
         }
         $packagesPath = Files::getUnixStylePath(Files::concatenatePaths([$this->packagesBasePath, $packagesPath]));
     }
     $packagePath = Files::concatenatePaths([$packagesPath, $packageKey]) . '/';
     Files::createDirectoryRecursively($packagePath);
     foreach ([PackageInterface::DIRECTORY_CLASSES, PackageInterface::DIRECTORY_CONFIGURATION, PackageInterface::DIRECTORY_DOCUMENTATION, PackageInterface::DIRECTORY_RESOURCES, PackageInterface::DIRECTORY_TESTS_UNIT, PackageInterface::DIRECTORY_TESTS_FUNCTIONAL] as $path) {
         Files::createDirectoryRecursively(Files::concatenatePaths([$packagePath, $path]));
     }
     $manifest = ComposerUtility::writeComposerManifest($packagePath, $packageKey, $manifest);
     $refreshedPackageStatesConfiguration = $this->rescanPackages(false);
     $this->packageStatesConfiguration = $refreshedPackageStatesConfiguration;
     $this->registerPackageFromStateConfiguration($manifest['name'], $this->packageStatesConfiguration['packages'][$manifest['name']]);
     return $this->packages[$packageKey];
 }
 /**
  * Adds the specified directory to the list of directories to be monitored.
  * All files in these directories will be monitored too.
  *
  * @param string $path Absolute path of the directory to monitor
  * @param string $filenamePattern A pattern for filenames to consider for file monitoring (regular expression)
  * @return void
  * @throws \InvalidArgumentException
  * @api
  */
 public function monitorDirectory($path, $filenamePattern = NULL)
 {
     if (!is_string($path)) {
         throw new \InvalidArgumentException('String expected, ' . gettype($path), ' given.', 1231171810);
     }
     $path = rtrim(\TYPO3\Flow\Utility\Files::getUnixStylePath($path), '/');
     if (!array_key_exists($path, $this->monitoredDirectories)) {
         $this->monitoredDirectories[$path] = $filenamePattern;
     }
 }
 /**
  * Recursively publishes static resources located in the specified directory.
  * These resources are typically public package resources provided by the active packages.
  *
  * @param string $sourcePath The full path to the source directory which should be published (includes sub directories)
  * @param string $relativeTargetPath Path relative to the target's root where resources should be published to.
  * @return boolean TRUE if publication succeeded or FALSE if the resources could not be published
  */
 public function publishStaticResources($sourcePath, $relativeTargetPath)
 {
     if (!is_dir($sourcePath)) {
         return FALSE;
     }
     $sourcePath = rtrim(\TYPO3\Flow\Utility\Files::getUnixStylePath($this->realpath($sourcePath)), '/');
     $targetPath = rtrim(\TYPO3\Flow\Utility\Files::concatenatePaths(array($this->resourcesPublishingPath, 'Static', $relativeTargetPath)), '/');
     if ($this->settings['resource']['publishing']['fileSystem']['mirrorMode'] === 'link') {
         if (\TYPO3\Flow\Utility\Files::is_link($targetPath) && rtrim(\TYPO3\Flow\Utility\Files::getUnixStylePath($this->realpath($targetPath)), '/') === $sourcePath) {
             return TRUE;
         } elseif (is_dir($targetPath)) {
             \TYPO3\Flow\Utility\Files::removeDirectoryRecursively($targetPath);
         } elseif (is_link($targetPath)) {
             unlink($targetPath);
         } else {
             \TYPO3\Flow\Utility\Files::createDirectoryRecursively(dirname($targetPath));
         }
         symlink($sourcePath, $targetPath);
     } else {
         foreach (\TYPO3\Flow\Utility\Files::readDirectoryRecursively($sourcePath) as $sourcePathAndFilename) {
             if (substr(strtolower($sourcePathAndFilename), -4, 4) === '.php') {
                 continue;
             }
             $targetPathAndFilename = \TYPO3\Flow\Utility\Files::concatenatePaths(array($targetPath, str_replace($sourcePath, '', $sourcePathAndFilename)));
             if (!file_exists($targetPathAndFilename) || filemtime($sourcePathAndFilename) > filemtime($targetPathAndFilename)) {
                 $this->mirrorFile($sourcePathAndFilename, $targetPathAndFilename, TRUE);
             }
         }
     }
     return TRUE;
 }
예제 #15
0
 /**
  * Initializes the identifier prefix when setting the cache.
  *
  * @param \TYPO3\Flow\Cache\Frontend\FrontendInterface $cache
  * @return void
  */
 public function setCache(\TYPO3\Flow\Cache\Frontend\FrontendInterface $cache)
 {
     parent::setCache($cache);
     $this->identifierPrefix = 'Flow_' . md5($cache->getIdentifier() . \TYPO3\Flow\Utility\Files::getUnixStylePath($_SERVER['SCRIPT_FILENAME']) . PHP_SAPI) . '_';
 }
<?php

use TYPO3\Flow\Utility\Files;
/**
 * Entry Point (Router) for PHP's embedded HTTP server. Use ./flow server:run to execute.
 */
if (strpos($_SERVER['REQUEST_URI'], '_Resources/') !== FALSE) {
    // published resources shall be served directly
    return FALSE;
}
require __DIR__ . '/../Classes/TYPO3/Flow/Core/Bootstrap.php';
define('FLOW_PATH_ROOT', Files::getUnixStylePath(realpath(__DIR__ . '/../../../../')) . '/');
// Script filename and script name must "emulate" index.php, to not break routing
$_SERVER['SCRIPT_FILENAME'] = FLOW_PATH_ROOT . 'Web/index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
// we want to have nice URLs
putenv('FLOW_REWRITEURLS=1');
$context = \TYPO3\Flow\Core\Bootstrap::getEnvironmentConfigurationSetting('FLOW_CONTEXT') ?: 'Development';
$bootstrap = new \TYPO3\Flow\Core\Bootstrap($context);
$bootstrap->run();
예제 #17
0
 /**
  * @param string $jobIdentifier
  * @param string $path
  */
 public function deleteAction($jobIdentifier, $path)
 {
     /** @var DocumentJobTrait $jobConfiguration */
     $jobConfiguration = $this->jobConfigurationRepository->findOneByIdentifier($jobIdentifier);
     $dirname = Files::getNormalizedPath(Files::getUnixStylePath(dirname($path)));
     if ($jobConfiguration->getDocumentAbsolutePath() !== $dirname) {
         $this->addFlashMessage(sprintf('The current job (%s) path does not match the requested path (%s)', $jobIdentifier, $path), '', Message::SEVERITY_ERROR);
         $this->redirect('downloadCenter', null, null, ['jobIdentifier' => $jobIdentifier]);
     }
     unlink($path);
     $this->redirect('downloadCenter', null, null, ['jobIdentifier' => $jobIdentifier]);
 }
 /**
  * Creates Flow's temporary directory - or at least asserts that it exists and is
  * writable.
  *
  * For each Flow Application Context, we create an extra temporary folder,
  * and for nested contexts, the folders are prefixed with "SubContext" to
  * avoid ambiguity, and look like: Data/Temporary/Production/SubContextLive
  *
  * @param string $temporaryDirectoryBase Full path to the base for the temporary directory
  * @return string The full path to the temporary directory
  * @throws UtilityException if the temporary directory could not be created or is not writable
  */
 protected function createTemporaryDirectory($temporaryDirectoryBase)
 {
     $temporaryDirectoryBase = Files::getUnixStylePath($temporaryDirectoryBase);
     if (substr($temporaryDirectoryBase, -1, 1) !== '/') {
         $temporaryDirectoryBase .= '/';
     }
     $temporaryDirectory = $temporaryDirectoryBase . str_replace('/', '/SubContext', (string) $this->context) . '/';
     if (!is_dir($temporaryDirectory) && !is_link($temporaryDirectory)) {
         try {
             Files::createDirectoryRecursively($temporaryDirectory);
         } catch (ErrorException $exception) {
             throw new UtilityException('The temporary directory "' . $temporaryDirectory . '" could not be created. Please make sure permissions are correct for this path or define another temporary directory in your Settings.yaml with the path "TYPO3.Flow.utility.environment.temporaryDirectoryBase".', 1335382361);
         }
     }
     if (!is_writable($temporaryDirectory)) {
         throw new UtilityException('The temporary directory "' . $temporaryDirectory . '" is not writable. Please make this directory writable or define another temporary directory in your Settings.yaml with the path "TYPO3.Flow.utility.environment.temporaryDirectoryBase".', 1216287176);
     }
     return $temporaryDirectory;
 }
 /**
  * Copies any distribution files to their place if needed.
  *
  * @param string $installerResourcesDirectory Path to the installer directory that contains the Distribution/Essentials and/or Distribution/Defaults directories.
  * @return void
  */
 protected static function copyDistributionFiles($installerResourcesDirectory)
 {
     $essentialsPath = $installerResourcesDirectory . 'Distribution/Essentials';
     if (is_dir($essentialsPath)) {
         Files::copyDirectoryRecursively($essentialsPath, Files::getUnixStylePath(getcwd()) . '/', false, true);
     }
     $defaultsPath = $installerResourcesDirectory . 'Distribution/Defaults';
     if (is_dir($defaultsPath)) {
         Files::copyDirectoryRecursively($defaultsPath, Files::getUnixStylePath(getcwd()) . '/', true, true);
     }
 }
 /**
  * Defines various path constants used by Flow and if no root path or web root was
  * specified by an environment variable, exits with a respective error message.
  *
  * @return void
  */
 protected function defineConstants()
 {
     if (defined('FLOW_SAPITYPE')) {
         return;
     }
     define('FLOW_SAPITYPE', PHP_SAPI === 'cli' ? 'CLI' : 'Web');
     if (!defined('FLOW_PATH_FLOW')) {
         define('FLOW_PATH_FLOW', str_replace('//', '/', str_replace('\\', '/', __DIR__ . '/../../../../')));
     }
     if (!defined('FLOW_PATH_ROOT')) {
         $rootPath = isset($_SERVER['FLOW_ROOTPATH']) ? $_SERVER['FLOW_ROOTPATH'] : false;
         if ($rootPath === false && isset($_SERVER['REDIRECT_FLOW_ROOTPATH'])) {
             $rootPath = $_SERVER['REDIRECT_FLOW_ROOTPATH'];
         }
         if (FLOW_SAPITYPE === 'CLI' && $rootPath === false) {
             $rootPath = getcwd();
             if (realpath(__DIR__) !== realpath($rootPath . '/Packages/Framework/TYPO3.Flow/Classes/Core')) {
                 echo 'TYPO3 Flow: Invalid root path. (Error #1301225173)' . PHP_EOL . 'You must start TYPO3 Flow from the root directory or set the environment variable FLOW_ROOTPATH correctly.' . PHP_EOL;
                 exit(1);
             }
         }
         if ($rootPath !== false) {
             $rootPath = Files::getUnixStylePath(realpath($rootPath)) . '/';
             $testPath = Files::getUnixStylePath(realpath(Files::concatenatePaths(array($rootPath, 'Packages/Framework/TYPO3.Flow')))) . '/';
             $expectedPath = Files::getUnixStylePath(realpath(FLOW_PATH_FLOW)) . '/';
             if ($testPath !== $expectedPath) {
                 echo 'Flow: Invalid root path. (Error #1248964375)' . PHP_EOL . '"' . $testPath . '" does not lead to' . PHP_EOL . '"' . $expectedPath . '"' . PHP_EOL;
                 exit(1);
             }
             define('FLOW_PATH_ROOT', $rootPath);
             unset($rootPath);
             unset($testPath);
         }
     }
     if (FLOW_SAPITYPE === 'CLI') {
         if (!defined('FLOW_PATH_ROOT')) {
             echo 'Flow: No root path defined in environment variable FLOW_ROOTPATH (Error #1248964376)' . PHP_EOL;
             exit(1);
         }
         if (!defined('FLOW_PATH_WEB')) {
             if (isset($_SERVER['FLOW_WEBPATH']) && is_dir($_SERVER['FLOW_WEBPATH'])) {
                 define('FLOW_PATH_WEB', Files::getUnixStylePath(realpath($_SERVER['FLOW_WEBPATH'])) . '/');
             } else {
                 define('FLOW_PATH_WEB', FLOW_PATH_ROOT . 'Web/');
             }
         }
     } else {
         if (!defined('FLOW_PATH_ROOT')) {
             define('FLOW_PATH_ROOT', Files::getUnixStylePath(realpath(dirname($_SERVER['SCRIPT_FILENAME']) . '/../')) . '/');
         }
         define('FLOW_PATH_WEB', Files::getUnixStylePath(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/');
     }
     define('FLOW_PATH_CONFIGURATION', FLOW_PATH_ROOT . 'Configuration/');
     define('FLOW_PATH_DATA', FLOW_PATH_ROOT . 'Data/');
     define('FLOW_PATH_PACKAGES', FLOW_PATH_ROOT . 'Packages/');
     if (!defined('FLOW_PATH_TEMPORARY_BASE')) {
         define('FLOW_PATH_TEMPORARY_BASE', self::getEnvironmentConfigurationSetting('FLOW_PATH_TEMPORARY_BASE') ?: FLOW_PATH_DATA . '/Temporary');
         $temporaryDirectoryPath = Files::concatenatePaths(array(FLOW_PATH_TEMPORARY_BASE, str_replace('/', '/SubContext', (string) $this->context))) . '/';
         define('FLOW_PATH_TEMPORARY', $temporaryDirectoryPath);
     }
     define('FLOW_VERSION_BRANCH', 'dev-master');
 }
 /**
  * Adds the specified directory to the list of directories to be monitored.
  * All files in these directories will be monitored too.
  *
  * @param string $path Absolute path of the directory to monitor
  * @param string $filenamePattern A pattern for filenames to consider for file monitoring (regular expression)
  * @return void
  * @throws \InvalidArgumentException
  * @api
  */
 public function monitorDirectory($path, $filenamePattern = null)
 {
     if (!is_string($path)) {
         throw new \InvalidArgumentException('String expected, ' . gettype($path), ' given.', 1231171810);
     }
     $path = Files::getNormalizedPath(Files::getUnixStylePath($path));
     if (!array_key_exists($path, $this->monitoredDirectories)) {
         $this->monitoredDirectories[$path] = $filenamePattern;
     }
 }
 /**
  * Tries to find out a package key which the Version belongs to. If no
  * package could be found, an empty string is returned.
  *
  * @param Version $version
  * @return string
  */
 protected function getPackageKeyFromMigrationVersion(Version $version)
 {
     $sortedAvailablePackages = $this->packageManager->getAvailablePackages();
     usort($sortedAvailablePackages, function (PackageInterface $packageOne, PackageInterface $packageTwo) {
         return strlen($packageTwo->getPackagePath()) - strlen($packageOne->getPackagePath());
     });
     $reflectedClass = new \ReflectionClass($version->getMigration());
     $classPathAndFilename = Files::getUnixStylePath($reflectedClass->getFileName());
     /** @var $package PackageInterface */
     foreach ($sortedAvailablePackages as $package) {
         $packagePath = Files::getUnixStylePath($package->getPackagePath());
         if (strpos($classPathAndFilename, $packagePath) === 0) {
             return $package->getPackageKey();
         }
     }
     return '';
 }
 /**
  * @param array $settings The TYPO3.Flow settings
  * @return string A command line command for PHP, which can be extended and then exec()uted
  */
 public static function buildPhpCommand(array $settings)
 {
     $subRequestEnvironmentVariables = array('FLOW_ROOTPATH' => FLOW_PATH_ROOT, 'FLOW_CONTEXT' => $settings['core']['context']);
     if (isset($settings['core']['subRequestEnvironmentVariables'])) {
         $subRequestEnvironmentVariables = array_merge($subRequestEnvironmentVariables, $settings['core']['subRequestEnvironmentVariables']);
     }
     $command = '';
     foreach ($subRequestEnvironmentVariables as $argumentKey => $argumentValue) {
         if (DIRECTORY_SEPARATOR === '/') {
             $command .= sprintf('%s=%s ', $argumentKey, escapeshellarg($argumentValue));
         } else {
             $command .= sprintf('SET %s=%s&', $argumentKey, escapeshellarg($argumentValue));
         }
     }
     if (DIRECTORY_SEPARATOR === '/') {
         $phpBinaryPathAndFilename = '"' . escapeshellcmd(\TYPO3\Flow\Utility\Files::getUnixStylePath($settings['core']['phpBinaryPathAndFilename'])) . '"';
     } else {
         $phpBinaryPathAndFilename = escapeshellarg(\TYPO3\Flow\Utility\Files::getUnixStylePath($settings['core']['phpBinaryPathAndFilename']));
     }
     $command .= $phpBinaryPathAndFilename;
     if (!isset($settings['core']['subRequestPhpIniPathAndFilename']) || $settings['core']['subRequestPhpIniPathAndFilename'] !== false) {
         if (!isset($settings['core']['subRequestPhpIniPathAndFilename'])) {
             $useIniFile = php_ini_loaded_file();
         } else {
             $useIniFile = $settings['core']['subRequestPhpIniPathAndFilename'];
         }
         $command .= ' -c ' . escapeshellarg($useIniFile);
     }
     return $command;
 }
예제 #24
0
 /**
  * @param array $collectedExtensionPaths
  * @return array
  */
 protected function scanLegacyExtensions(&$collectedExtensionPaths = array())
 {
     $legacyCmsPackageBasePathTypes = array('sysext', 'global', 'local');
     foreach ($this->packagesBasePaths as $type => $packageBasePath) {
         if (!in_array($type, $legacyCmsPackageBasePathTypes)) {
             continue;
         }
         /** @var $fileInfo \SplFileInfo */
         foreach (new \DirectoryIterator($packageBasePath) as $fileInfo) {
             if (!$fileInfo->isDir()) {
                 continue;
             }
             $filename = $fileInfo->getFilename();
             if ($filename[0] !== '.') {
                 $currentPath = \TYPO3\Flow\Utility\Files::getUnixStylePath($fileInfo->getPathName()) . '/';
                 if (file_exists($currentPath . 'ext_emconf.php')) {
                     $collectedExtensionPaths[$currentPath] = $currentPath;
                 }
             }
         }
     }
     return $collectedExtensionPaths;
 }
예제 #25
0
 /**
  * @param array $collectedExtensionPaths
  * @return array
  */
 protected function scanLegacyExtensions(&$collectedExtensionPaths = array())
 {
     $legacyCmsPackageBasePathTypes = array('sysext', 'global', 'local');
     foreach ($this->packagesBasePaths as $type => $packageBasePath) {
         if (!in_array($type, $legacyCmsPackageBasePathTypes)) {
             continue;
         }
         /** @var $fileInfo \SplFileInfo */
         foreach (new \DirectoryIterator($packageBasePath) as $fileInfo) {
             if (!$fileInfo->isDir()) {
                 continue;
             }
             $filename = $fileInfo->getFilename();
             if ($filename[0] !== '.') {
                 $currentPath = \TYPO3\Flow\Utility\Files::getUnixStylePath($fileInfo->getPathName()) . '/';
                 // Only add the extension if we have an EMCONF and the extension is not yet registered.
                 // This is crucial in order to allow overriding of system extension by local extensions
                 // and strongly depends on the order of paths defined in $this->packagesBasePaths.
                 if (file_exists($currentPath . 'ext_emconf.php') && !isset($collectedExtensionPaths[$filename])) {
                     $collectedExtensionPaths[$filename] = $currentPath;
                 }
             }
         }
     }
     return $collectedExtensionPaths;
 }