/**
  * 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\FLOW3\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;
 }
예제 #2
0
 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->unixStylePath = \TYPO3\FLOW3\Utility\Files::getUnixStylePath(__DIR__);
     $this->unixStylePathAndFilename = \TYPO3\FLOW3\Utility\Files::getUnixStylePath(__FILE__);
     \vfsStreamWrapper::register();
     \vfsStreamWrapper::setRoot(new \vfsStreamDirectory('testDirectory'));
 }
예제 #3
0
파일: Bootstrap.php 프로젝트: nxpthx/FLOW3
 /**
  * Defines various path constants used by FLOW3 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('FLOW3_SAPITYPE')) {
         return;
     }
     define('FLOW3_SAPITYPE', PHP_SAPI === 'cli' ? 'CLI' : 'Web');
     if (!defined('FLOW3_PATH_FLOW3')) {
         define('FLOW3_PATH_FLOW3', str_replace('//', '/', str_replace('\\', '/', __DIR__ . '/../../')));
     }
     if (!defined('FLOW3_PATH_ROOT')) {
         $rootPath = isset($_SERVER['FLOW3_ROOTPATH']) ? $_SERVER['FLOW3_ROOTPATH'] : FALSE;
         if ($rootPath === FALSE && isset($_SERVER['REDIRECT_FLOW3_ROOTPATH'])) {
             $rootPath = $_SERVER['REDIRECT_FLOW3_ROOTPATH'];
         }
         if (FLOW3_SAPITYPE === 'CLI' && $rootPath === FALSE) {
             $rootPath = getcwd();
             if (realpath(__DIR__) !== realpath($rootPath . '/Packages/Framework/TYPO3.FLOW3/Classes/Core')) {
                 echo 'FLOW3: Invalid root path. (Error #1301225173)' . PHP_EOL . 'You must start FLOW3 from the root directory or set the environment variable FLOW3_ROOTPATH correctly.' . PHP_EOL;
                 exit(1);
             }
         }
         if ($rootPath !== FALSE) {
             $rootPath = \TYPO3\FLOW3\Utility\Files::getUnixStylePath(realpath($rootPath)) . '/';
             $testPath = \TYPO3\FLOW3\Utility\Files::getUnixStylePath(realpath(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($rootPath, 'Packages/Framework/TYPO3.FLOW3')))) . '/';
             $expectedPath = \TYPO3\FLOW3\Utility\Files::getUnixStylePath(realpath(FLOW3_PATH_FLOW3)) . '/';
             if ($testPath !== $expectedPath) {
                 echo 'FLOW3: Invalid root path. (Error #1248964375)' . PHP_EOL . '"' . $testPath . '" does not lead to' . PHP_EOL . '"' . $expectedPath . '"' . PHP_EOL;
                 exit(1);
             }
             define('FLOW3_PATH_ROOT', $rootPath);
             unset($rootPath);
             unset($testPath);
         }
     }
     if (FLOW3_SAPITYPE === 'CLI') {
         if (!defined('FLOW3_PATH_ROOT')) {
             echo 'FLOW3: No root path defined in environment variable FLOW3_ROOTPATH (Error #1248964376)' . PHP_EOL;
             exit(1);
         }
         if (!defined('FLOW3_PATH_WEB')) {
             if (isset($_SERVER['FLOW3_WEBPATH']) && is_dir($_SERVER['FLOW3_WEBPATH'])) {
                 define('FLOW3_PATH_WEB', \TYPO3\FLOW3\Utility\Files::getUnixStylePath(realpath($_SERVER['FLOW3_WEBPATH'])) . '/');
             } else {
                 define('FLOW3_PATH_WEB', FLOW3_PATH_ROOT . 'Web/');
             }
         }
     } else {
         if (!defined('FLOW3_PATH_ROOT')) {
             define('FLOW3_PATH_ROOT', \TYPO3\FLOW3\Utility\Files::getUnixStylePath(realpath(dirname($_SERVER['SCRIPT_FILENAME']) . '/../')) . '/');
         }
         define('FLOW3_PATH_WEB', \TYPO3\FLOW3\Utility\Files::getUnixStylePath(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/');
     }
     define('FLOW3_PATH_CONFIGURATION', FLOW3_PATH_ROOT . 'Configuration/');
     define('FLOW3_PATH_DATA', FLOW3_PATH_ROOT . 'Data/');
     define('FLOW3_PATH_PACKAGES', FLOW3_PATH_ROOT . 'Packages/');
     define('FLOW3_VERSION_BRANCH', '1.2');
 }
예제 #4
0
 /**
  * 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\FLOW3\Utility\Files::getUnixStylePath($this->realpath($sourcePath)), '/');
     $targetPath = rtrim(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->resourcesPublishingPath, 'Static', $relativeTargetPath)), '/');
     if ($this->settings['resource']['publishing']['fileSystem']['mirrorMode'] === 'link') {
         if (\TYPO3\FLOW3\Utility\Files::is_link($targetPath) && rtrim(\TYPO3\FLOW3\Utility\Files::getUnixStylePath($this->realpath($targetPath)), '/') === $sourcePath) {
             return TRUE;
         } elseif (is_dir($targetPath)) {
             \TYPO3\FLOW3\Utility\Files::removeDirectoryRecursively($targetPath);
         } elseif (is_link($targetPath)) {
             unlink($targetPath);
         } else {
             \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively(dirname($targetPath));
         }
         symlink($sourcePath, $targetPath);
     } else {
         foreach (\TYPO3\FLOW3\Utility\Files::readDirectoryRecursively($sourcePath) as $sourcePathAndFilename) {
             if (substr(strtolower($sourcePathAndFilename), -4, 4) === '.php') {
                 continue;
             }
             $targetPathAndFilename = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($targetPath, str_replace($sourcePath, '', $sourcePathAndFilename)));
             if (!file_exists($targetPathAndFilename) || filemtime($sourcePathAndFilename) > filemtime($targetPathAndFilename)) {
                 $this->mirrorFile($sourcePathAndFilename, $targetPathAndFilename, TRUE);
             }
         }
     }
     return TRUE;
 }
예제 #5
0
 /**
  * Initializes the identifier prefix when setting the cache.
  *
  * @param \TYPO3\FLOW3\Cache\Frontend\FrontendInterface $cache
  * @return void
  */
 public function setCache(\TYPO3\FLOW3\Cache\Frontend\FrontendInterface $cache)
 {
     parent::setCache($cache);
     $this->identifierPrefix = 'FLOW3_' . md5($cache->getIdentifier() . \TYPO3\FLOW3\Utility\Files::getUnixStylePath($_SERVER['SCRIPT_FILENAME']) . PHP_SAPI) . '_';
 }
예제 #6
0
 /**
  * Creates FLOW3's temporary directory - or at least asserts that it exists and is
  * writable.
  *
  * For each FLOW3 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 \TYPO3\FLOW3\Utility\Exception if the temporary directory could not be created or is not writable
  */
 protected function createTemporaryDirectory($temporaryDirectoryBase)
 {
     $temporaryDirectoryBase = \TYPO3\FLOW3\Utility\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 {
             \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($temporaryDirectory);
         } catch (\TYPO3\FLOW3\Error\Exception $exception) {
             throw new \TYPO3\FLOW3\Utility\Exception('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.FLOW3.utility.environment.temporaryDirectoryBase".', 1335382361);
         }
     }
     if (!is_writable($temporaryDirectory)) {
         throw new \TYPO3\FLOW3\Utility\Exception('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.FLOW3.utility.environment.temporaryDirectoryBase".', 1216287176);
     }
     return $temporaryDirectory;
 }
예제 #7
0
 /**
  * @param \TYPO3\Form\Core\Model\FinisherContext $finisherContext
  * @return void
  * @throws \TYPO3\Setup\Exception
  */
 public function importSite(\TYPO3\Form\Core\Model\FinisherContext $finisherContext)
 {
     $formValues = $finisherContext->getFormRuntime()->getFormState()->getFormValues();
     if (isset($formValues['prune']) && intval($formValues['prune']) === 1) {
         $this->nodeRepository->removeAll();
         $this->workspaceRepository->removeAll();
         $this->domainRepository->removeAll();
         $this->siteRepository->removeAll();
         $this->persistenceManager->persistAll();
     }
     if (!empty($formValues['packageKey'])) {
         if ($this->packageManager->isPackageAvailable($formValues['packageKey'])) {
             throw new \TYPO3\Setup\Exception(sprintf('The package key "%s" already exists.', $formValues['packageKey']), 1346759486);
         }
         $packageKey = $formValues['packageKey'];
         $siteName = $formValues['packageKey'];
         $this->packageManager->createPackage($packageKey, NULL, Files::getUnixStylePath(Files::concatenatePaths(array(FLOW3_PATH_PACKAGES, 'Sites'))));
         $this->generatorService->generateSitesXml($packageKey, $siteName);
         $this->generatorService->generateSitesTypoScript($packageKey, $siteName);
         $this->generatorService->generateSitesTemplate($packageKey, $siteName);
         $this->packageManager->activatePackage($packageKey);
     } else {
         $packageKey = $formValues['site'];
     }
     if ($packageKey !== '') {
         try {
             $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live');
             $this->nodeRepository->setContext($contentContext);
             $this->siteImportService->importFromPackage($packageKey);
         } catch (\Exception $exception) {
             $finisherContext->cancel();
             $this->flashMessageContainer->addMessage(new \TYPO3\FLOW3\Error\Error(sprintf('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', $packageKey, $exception->getMessage())));
         }
     }
 }
예제 #8
0
 /**
  * Scans the 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) {
         $filename = $fileInfo->getFilename();
         if ($filename[0] !== '.') {
             $packagePath = Files::getUnixStylePath($fileInfo->getPathName()) . '/';
             $packageMetaPathAndFilename = $packagePath . 'Meta/Package.xml';
             if (file_exists($packageMetaPathAndFilename)) {
                 $collectedPackagePaths[] = $packagePath;
             } elseif ($fileInfo->isDir() && $filename[0] !== '.') {
                 $this->scanPackagesInPath($packagePath, $collectedPackagePaths);
             }
         }
     }
     return $collectedPackagePaths;
 }
예제 #9
0
 /**
  * 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
  * @return void
  * @throws \InvalidArgumentException
  * @api
  */
 public function monitorDirectory($path)
 {
     if (!is_string($path)) {
         throw new \InvalidArgumentException('String expected, ' . gettype($path), ' given.', 1231171810);
     }
     $path = rtrim(\TYPO3\FLOW3\Utility\Files::getUnixStylePath($path), '/');
     if (array_search($path, $this->monitoredDirectories) === FALSE) {
         $this->monitoredDirectories[] = $path;
     }
 }
예제 #10
0
파일: FilesTest.php 프로젝트: nxpthx/FLOW3
 /**
  * @test
  * @dataProvider pathsWithProtocol
  */
 public function getUnixStylePathWorksForPathWithProtocol($path, $expected)
 {
     $this->assertEquals($expected, \TYPO3\FLOW3\Utility\Files::getUnixStylePath($path));
 }
예제 #11
0
파일: Scripts.php 프로젝트: nxpthx/FLOW3
 /**
  * Executes the given command as a sub-request to the FLOW3 CLI system.
  *
  * @param string $commandIdentifier E.g. typo3.flow3:cache:flush
  * @param array $settings The FLOW3 settings
  * @param boolean $outputResults if FALSE the output of this command is only echoed if the execution was not successful
  * @return boolean TRUE if the command execution was successful (exit code = 0)
  * @api
  */
 public static function executeCommand($commandIdentifier, array $settings, $outputResults = TRUE)
 {
     $subRequestEnvironmentVariables = array('FLOW3_ROOTPATH' => FLOW3_PATH_ROOT, 'FLOW3_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));
         }
     }
     $phpBinaryPathAndFilename = escapeshellcmd(\TYPO3\FLOW3\Utility\Files::getUnixStylePath($settings['core']['phpBinaryPathAndFilename']));
     $command .= sprintf('"%s" -c %s %s %s', $phpBinaryPathAndFilename, escapeshellarg(php_ini_loaded_file()), escapeshellarg(FLOW3_PATH_FLOW3 . 'Scripts/flow3.php'), escapeshellarg($commandIdentifier));
     $output = array();
     exec($command, $output, $result);
     if ($outputResults || $result !== 0) {
         echo implode(PHP_EOL, $output);
     }
     return $result === 0;
 }