/**
  * 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
 /**
  * @test
  */
 public function getPathToTemporaryDirectoryReturnsAnExistingPath()
 {
     $environment = new \TYPO3\FLOW3\Utility\Environment(new ApplicationContext('Testing'));
     $environment->setTemporaryDirectoryBase(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array(sys_get_temp_dir(), 'FLOW3EnvironmentTest')));
     $path = $environment->getPathToTemporaryDirectory();
     $this->assertTrue(file_exists($path), 'The temporary path does not exist.');
 }
예제 #3
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'));
 }
예제 #4
0
 /**
  * @test
  */
 public function modelIsReturnedCorrectlyForLocaleImplicatingChaining()
 {
     $localeImplementingChaining = new \TYPO3\FLOW3\I18n\Locale('de_DE');
     $cldrModel = $this->cldrRepository->getModelForLocale($localeImplementingChaining);
     $this->assertAttributeContains(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->cldrBasePath, 'main/root.xml')), 'sourcePaths', $cldrModel);
     $this->assertAttributeContains(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->cldrBasePath, 'main/de_DE.xml')), 'sourcePaths', $cldrModel);
     $this->assertAttributeContains(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->cldrBasePath, 'main/de.xml')), 'sourcePaths', $cldrModel);
 }
예제 #5
0
파일: FormatTest.php 프로젝트: nxpthx/FLOW3
 /**
  * @test
  */
 public function getLanguagesScansFormatDirectoryAndReturnsLanguagesAsStrings()
 {
     $formatPath = \vfsStream::url('testDirectory') . '/';
     \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($formatPath . 'en');
     $format = new \TYPO3\FLOW3\Package\Documentation\Format('DocBook', $formatPath);
     $availableLanguages = $format->getAvailableLanguages();
     $this->assertEquals(array('en'), $availableLanguages);
 }
 protected function parseTemplate($templatePathAndFilename)
 {
     $templateSource = \TYPO3\FLOW3\Utility\Files::getFileContents($templatePathAndFilename, FILE_TEXT);
     if ($templateSource === FALSE) {
         throw new \TYPO3\Fluid\View\Exception\InvalidTemplateResourceException('"' . $templatePathAndFilename . '" is not a valid template resource URI.', 1257246929);
     }
     return $this->templateParser->parse($templateSource);
 }
예제 #7
0
 /**
  * @test
  */
 public function getDocumentationFormatsScansDocumentationDirectoryAndReturnsDocumentationFormatObjectsIndexedByFormatName()
 {
     $documentationPath = \vfsStream::url('testDirectory') . '/';
     $mockPackage = $this->getMock('TYPO3\\FLOW3\\Package\\PackageInterface');
     \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($documentationPath . 'DocBook/en');
     $documentation = new \TYPO3\FLOW3\Package\Documentation($mockPackage, 'Manual', $documentationPath);
     $documentationFormats = $documentation->getDocumentationFormats();
     $this->assertEquals('DocBook', $documentationFormats['DocBook']->getFormatName());
 }
예제 #8
0
파일: XmlReader.php 프로젝트: nxpthx/FLOW3
 /**
  * Read the package metadata for the given package from the
  * Package.xml file contained in the package
  *
  * @param \TYPO3\FLOW3\Package\PackageInterface $package The package to read metadata for
  * @return \TYPO3\FLOW3\Package\MetaData A package meta data instance with the data from the package's Package.xml file.
  */
 public static function readPackageMetaData(\TYPO3\FLOW3\Package\PackageInterface $package)
 {
     $packageInfoPath = $package->getMetaPath();
     $meta = new \TYPO3\FLOW3\Package\MetaData($package->getPackageKey());
     $xml = simplexml_load_file(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($packageInfoPath, 'Package.xml')));
     if ($xml === FALSE) {
         $meta->setDescription('[Package.xml could not be read.]');
     } else {
         $meta->setVersion((string) $xml->version);
         $meta->setTitle((string) $xml->title);
         $meta->setDescription((string) $xml->description);
         self::readCategories($xml, $meta);
         self::readParties($xml, $meta);
         self::readConstraints($xml, $meta);
     }
     return $meta;
 }
예제 #9
0
파일: Package.php 프로젝트: nxpthx/FLOW3
 /**
  * Constructor
  *
  * @param string $packageKey Key of this package
  * @param string $packagePath Absolute path to the package's main directory
  * @param string $classesPath Path the classes of the package are in, relative to $packagePath. Optional, defaults to 'Classes'
  * @throws \TYPO3\FLOW3\Package\Exception\InvalidPackageKeyException if an invalid package key was passed
  * @throws \TYPO3\FLOW3\Package\Exception\InvalidPackagePathException if an invalid package path was passed
  */
 public function __construct($packageKey, $packagePath, $classesPath = self::DIRECTORY_CLASSES)
 {
     if (preg_match(self::PATTERN_MATCH_PACKAGEKEY, $packageKey) !== 1) {
         throw new \TYPO3\FLOW3\Package\Exception\InvalidPackageKeyException('"' . $packageKey . '" is not a valid package key.', 1217959510);
     }
     if (!(is_dir($packagePath) || \TYPO3\FLOW3\Utility\Files::is_link($packagePath) && is_dir(realpath(rtrim($packagePath, '/'))))) {
         throw new \TYPO3\FLOW3\Package\Exception\InvalidPackagePathException('Package path does not exist or is no directory.', 1166631889);
     }
     if (substr($packagePath, -1, 1) !== '/') {
         throw new \TYPO3\FLOW3\Package\Exception\InvalidPackagePathException('Package path has no trailing forward slash.', 1166633720);
     }
     if (substr($classesPath, 1, 1) === '/') {
         throw new \TYPO3\FLOW3\Package\Exception\InvalidPackagePathException('Package classes path has a leading forward slash.', 1334841320);
     }
     $this->packageKey = $packageKey;
     $this->packagePath = $packagePath;
     $this->classesPath = $classesPath;
 }
 /**
  * Executes this task
  *
  * @param \TYPO3\Deploy\Domain\Model\Node $node
  * @param \TYPO3\Deploy\Domain\Model\Application $application
  * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment
  * @param array $options
  * @return void
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $username = $node->getOption('username');
     $hostname = $node->getHostname();
     $configurationPath = $this->getDeploymentConfigurationPath() . '/Configuration/' . $deployment->getName() . '/';
     $encryptedConfiguration = \TYPO3\FLOW3\Utility\Files::readDirectoryRecursively($configurationPath, 'yaml.encrypted');
     if (count($encryptedConfiguration) > 0) {
         throw new \Exception('You have sealed configuration files, please open the configuration for "' . $deployment->getName() . '"', 1317229449);
     }
     $configurations = \TYPO3\FLOW3\Utility\Files::readDirectoryRecursively($configurationPath, 'yaml');
     $commands = array();
     foreach ($configurations as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         $commands[] = "scp {$configuration} {$username}@{$hostname}:{$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
예제 #11
0
파일: Tools.php 프로젝트: nxpthx/FLOW3
 /**
  * Will return an array with all available packages.
  *
  * The data for each entry will be an array with the key, full path to
  * the package (index 'path') and a category (the packages subfolder,
  * index 'category'). The array is indexed by package key.
  *
  * @param string $packagesPath
  * @return array
  */
 public static function getPackagesData($packagesPath)
 {
     $packagesData = array();
     $packagesDirectoryIterator = new \DirectoryIterator($packagesPath);
     foreach ($packagesDirectoryIterator as $categoryFileInfo) {
         $category = $categoryFileInfo->getFilename();
         if (!$categoryFileInfo->isDir() || $category[0] === '.') {
             continue;
         }
         $categoryDirectoryIterator = new \DirectoryIterator($categoryFileInfo->getPathname());
         foreach ($categoryDirectoryIterator as $packageFileInfo) {
             $packageKey = $packageFileInfo->getFilename();
             if (!$packageFileInfo->isDir() || $packageKey[0] === '.') {
                 continue;
             }
             if (!file_exists(Files::concatenatePaths(array($packageFileInfo->getPathname(), 'Classes/Package.php')))) {
                 continue;
             }
             $packagesData[$packageKey] = array('packageKey' => $packageKey, 'category' => $category, 'path' => $packageFileInfo->getPathname());
         }
     }
     return $packagesData;
 }
예제 #12
0
 /**
  * Removes all cache entries of this cache and sets the frozen flag to FALSE.
  *
  * @return void
  * @api
  */
 public function flush()
 {
     \TYPO3\FLOW3\Utility\Files::emptyDirectoryRecursively($this->cacheDirectory);
     if ($this->frozen === TRUE) {
         @unlink($this->cacheDirectory . 'FrozenCache.data');
         $this->frozen = FALSE;
     }
 }
 /**
  * @test
  */
 public function inLinkModeRewritePersistentResourcePublishPathAndFilenameForPrivateResourcesCreatesRoleDirectoriesForEachAllowedRoleAndSymlinksThemIntoTheCurrentSessionDirectory()
 {
     $settings = array('resource' => array('publishing' => array('fileSystem' => array('mirrorMode' => 'link'))));
     $allowedRoles = array(new Role('Role2'), new Role('Role3'));
     $mockPublishingConfiguration = $this->getMock('TYPO3\\FLOW3\\Security\\Authorization\\Resource\\SecurityPublishingConfiguration', array(), array(), '', FALSE);
     $mockPublishingConfiguration->expects($this->once())->method('getAllowedRoles')->will($this->returnValue($allowedRoles));
     $actualRoles = array(new Role('Role1'), new Role('Role2'), new Role('Role3'));
     $mockEnvironment = $this->getMock('TYPO3\\FLOW3\\Utility\\Environment', array(), array(), '', FALSE);
     $mockEnvironment->expects($this->any())->method('getPathToTemporaryDirectory')->will($this->returnValue($this->temporaryDirectoryPath));
     $mockSecurityContext = $this->getMock('TYPO3\\FLOW3\\Security\\Context', array(), array(), '', FALSE);
     $mockSecurityContext->expects($this->once())->method('getRoles')->will($this->returnValue($actualRoles));
     $mockPublishingTargetProxy = $this->getMock('TYPO3\\FLOW3\\Resource\\Publishing\\FileSystemPublishingTarget', array(), array(), '', FALSE);
     $mockPublishingTargetProxy->expects($this->once())->method('getResourcesPublishingPath')->will($this->returnValue($this->publishPath));
     $mockResourcePointer = $this->getMock('TYPO3\\FLOW3\\Resource\\ResourcePointer', array(), array(), '', FALSE);
     $mockResourcePointer->expects($this->once())->method('getHash')->will($this->returnValue('ResourceHash'));
     $mockResource = $this->getMock('TYPO3\\FLOW3\\Resource\\Resource', array(), array(), '', FALSE);
     $mockResource->expects($this->once())->method('getPublishingConfiguration')->will($this->returnValue($mockPublishingConfiguration));
     $mockResource->expects($this->once())->method('getResourcePointer')->will($this->returnValue($mockResourcePointer));
     $mockResource->expects($this->once())->method('getFileExtension')->will($this->returnValue('ResourceFileExtension'));
     $mockJoinPoint = $this->getMock('TYPO3\\FLOW3\\Aop\\JoinPointInterface', array(), array(), '', FALSE);
     $mockJoinPoint->expects($this->at(0))->method('getMethodArgument')->with('resource')->will($this->returnValue($mockResource));
     $mockJoinPoint->expects($this->at(1))->method('getMethodArgument')->with('returnFilename')->will($this->returnValue(FALSE));
     $mockJoinPoint->expects($this->once())->method('getProxy')->will($this->returnValue($mockPublishingTargetProxy));
     $mockSession = $this->getMock('TYPO3\\FLOW3\\Session\\SessionInterface', array(), array(), '', FALSE);
     $mockSession->expects($this->once())->method('getID')->will($this->returnValue('TheCurrentSessionId'));
     $mockAccessRestrictionPublisher = $this->getMock('\\TYPO3\\FLOW3\\Security\\Authorization\\Resource\\AccessRestrictionPublisherInterface', array(), array(), '', FALSE);
     $publishingAspect = $this->getAccessibleMock('TYPO3\\FLOW3\\Security\\Aspect\\PrivateResourcesPublishingAspect', array('dummy'), array(), '', FALSE);
     $publishingAspect->_set('securityContext', $mockSecurityContext);
     $publishingAspect->_set('session', $mockSession);
     $publishingAspect->_set('environment', $mockEnvironment);
     $publishingAspect->_set('settings', $settings);
     $publishingAspect->_set('accessRestrictionPublisher', $mockAccessRestrictionPublisher);
     $publishingAspect->_call('rewritePersistentResourcePublishPathAndFilenameForPrivateResources', $mockJoinPoint);
     $this->assertFileExists($this->temporaryDirectoryPath . '/PrivateResourcePublishing/Role2/');
     $this->assertFileExists($this->temporaryDirectoryPath . '/PrivateResourcePublishing/Role3/');
     $this->assertFileExists($this->publishPath . '/Persistent/TheCurrentSessionId/Role2');
     $this->assertFileExists($this->publishPath . '/Persistent/TheCurrentSessionId/Role3');
     $role2PrivateResourcePath = realpath(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->temporaryDirectoryPath, 'PrivateResourcePublishing/Role2')));
     $role2SymlinkedPath = realpath(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->publishPath, 'Persistent/TheCurrentSessionId/Role2')));
     $this->assertEquals($role2PrivateResourcePath, $role2SymlinkedPath);
     $role3PrivateResourcePath = realpath(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->temporaryDirectoryPath, 'PrivateResourcePublishing/Role3')));
     $role3SymlinkedPath = realpath(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->publishPath, 'Persistent/TheCurrentSessionId/Role3')));
     $this->assertEquals($role3PrivateResourcePath, $role3SymlinkedPath);
 }
예제 #14
0
    /**
     * Performs special transformations
     * 
     * @return void 
     */
    public function transformSpecial()
    {
        // FormRuntime
        file_put_contents($this->targetPath . '/Classes/Core/Runtime/FormRuntime.php', preg_replace('/protected function getControllerContext\\(\\) {[^}]+}/', 'protected function getControllerContext() {
		$uriBuilder = $this->objectManager->get(\'Tx_Extbase_MVC_Web_Routing_UriBuilder\');
		$controllerContext = $this->objectManager->create(\'Tx_Extbase_MVC_Controller_ControllerContext\');
		$controllerContext->setRequest($this->request);
		$controllerContext->setResponse($this->response);
		$controllerContext->setArguments($this->objectManager->create(\'Tx_Extbase_MVC_Controller_Arguments\', array()));
		$controllerContext->setUriBuilder($uriBuilder);
		$controllerContext->setFlashMessageContainer($this->objectManager->get(\'Tx_Extbase_MVC_Controller_FlashMessages\'));
		return $controllerContext;
	}', \TYPO3\FLOW3\Utility\Files::getFileContents($this->targetPath . '/Classes/Core/Runtime/FormRuntime.php')));
        file_put_contents($this->targetPath . '/Classes/Core/Runtime/FormRuntime.php', str_replace('public function initializeObject() {
		$this->request = $this->objectManager->create(\'Tx_Extbase_MVC_Request\',$this->request);
		$this->request->setArgumentNamespace($this->formDefinition->getIdentifier());
		if ($this->request->getParentRequest()->hasArgument($this->request->getArgumentNamespace()) === TRUE && is_array($this->request->getParentRequest()->getArgument($this->request->getArgumentNamespace()))) {
			$this->request->setArguments($this->request->getParentRequest()->getArgument($this->request->getArgumentNamespace()));
		}
		
		$this->initializeFormStateFromRequest();
		$this->initializeCurrentPageFromRequest();

		if ($this->formPageHasBeenSubmitted()) {
			$this->processSubmittedFormValues();
		}
	}', 'public function initializeObject() {
		$this->initializeFormStateFromRequest();
		if ($this->request->hasArgument(\'formIdentifier\') && $this->request->getArgument(\'formIdentifier\') !== $this->formDefinition->getIdentifier()) {
			$this->formState->setLastDisplayedPageIndex(Tx_' . \TYPO3\FormBackporter\Utility\Extension::extKeyToName($this->extensionKey) . '_Core_Runtime_FormState::NOPAGE);
		}
		$this->initializeCurrentPageFromRequest();

		if ($this->formPageHasBeenSubmitted()) {
			$this->processSubmittedFormValues();
		}
	}', \TYPO3\FLOW3\Utility\Files::getFileContents($this->targetPath . '/Classes/Core/Runtime/FormRuntime.php')));
        file_put_contents($this->targetPath . '/Classes/Core/Runtime/FormRuntime.php', str_replace('protected function processSubmittedFormValues() {
		$result = $this->mapAndValidatePage($this->lastDisplayedPage);
		if ($result->hasErrors()) {
			$this->currentPage = $this->lastDisplayedPage;
			$this->request->setArgument(\'__submittedArguments\', $this->request->getArguments());
			$this->request->setArgument(\'__submittedArgumentValidationResults\', $result);
		}
	}', 'protected function processSubmittedFormValues() {
		$result = $this->mapAndValidatePage($this->lastDisplayedPage);
		if ($result->hasErrors()) {
			$this->request->setOriginalRequestMappingResults($result);
			$this->currentPage = $this->lastDisplayedPage;
			$this->request->setArgument(\'__submittedArguments\', $this->request->getArguments());
			$this->request->setArgument(\'__submittedArgumentValidationResults\', $result);
		}
	}', \TYPO3\FLOW3\Utility\Files::getFileContents($this->targetPath . '/Classes/Core/Runtime/FormRuntime.php')));
        // Array Utility
        file_put_contents($this->targetPath . '/Classes/Utility/Arrays.php', str_replace('class Tx_FormBase_Utility_Arrays implements t3lib_Singleton {', 'class Tx_FormBase_Utility_Arrays implements t3lib_Singleton {

	/**
	 * Validates the given $arrayToTest by checking if an element is not in $allowedArrayKeys.
	 *
	 * @param array $arrayToTest
	 * @param array $allowedArrayKeys
	 * @throws Tx_Flow3FormApi_Exception_TypeDefinitionNotValidException if an element in $arrayToTest is not in $allowedArrayKeys
	 */
	public static function assertAllArrayKeysAreValid(array $arrayToTest, array $allowedArrayKeys) {
		$notAllowedArrayKeys = array_keys(array_diff_key($arrayToTest, array_flip($allowedArrayKeys)));
		if (count($notAllowedArrayKeys) !== 0) {
			throw new Tx_Flow3FormApi_Exception_TypeDefinitionNotValidException(sprintf(\'The options "%s" were not allowed (allowed were: "%s")\', implode(\', \', $notAllowedArrayKeys), implode(\', \', $allowedArrayKeys)), 1325697085);
		}
	}', \TYPO3\FLOW3\Utility\Files::getFileContents($this->targetPath . '/Classes/Utility/Arrays.php')));
        // Form definition
        file_put_contents($this->targetPath . '/Classes/Core/Model/FormDefinition.php', str_replace(array('throw $this->objectManager->create(\'Tx_FormBase_Exception_IdentifierNotValidException\',\'The given identifier was not a string or the string was empty.\', 1325574803);', '$page = $this->objectManager->create(\'$implementationClassName\',$identifier, $typeName);'), array('throw new Tx_FormBase_Exception_IdentifierNotValidException(\'The given identifier was not a string or the string was empty.\', 1325574803);', '$page = $this->objectManager->create($implementationClassName, $identifier, $typeName);'), \TYPO3\FLOW3\Utility\Files::getFileContents($this->targetPath . '/Classes/Core/Model/FormDefinition.php')));
        // Form runtime
        file_put_contents($this->targetPath . '/Classes/Core/Runtime/FormRuntime.php', str_replace(array('$renderer = $this->objectManager->create(\'$rendererClassName\');'), array('$renderer = $this->objectManager->create($rendererClassName);'), \TYPO3\FLOW3\Utility\Files::getFileContents($this->targetPath . '/Classes/Core/Runtime/FormRuntime.php')));
        // Abstract section
        file_put_contents($this->targetPath . '/Classes/Core/Model/AbstractSection.php', str_replace(array('throw $this->objectManager->create(\'Tx_FormBase_Exception_IdentifierNotValidException\',\'The given identifier was not a string or the string was empty.\', 1325574803);', '$element = $this->objectManager->create(\'$implementationClassName\',$identifier, $typeName);'), array('throw new Tx_FormBase_Exception_IdentifierNotValidException(\'The given identifier was not a string or the string was empty.\', 1325574803);', '$element = $this->objectManager->create($implementationClassName, $identifier, $typeName);'), \TYPO3\FLOW3\Utility\Files::getFileContents($this->targetPath . '/Classes/Core/Model/AbstractSection.php')));
    }
예제 #15
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) . '_';
 }
예제 #16
0
 /**
  * Helper function to get the base path for key storage.
  *
  * @return string
  */
 protected function getPath()
 {
     return Files::concatenatePaths(array(FLOW3_PATH_DATA, 'Persistent', 'FileBasedSimpleKeyService'));
 }
예제 #17
0
 /**
  * Depending on the settings of this publishing target copies the specified file
  * or creates a symbolic link.
  *
  * @param string $sourcePathAndFilename
  * @param string $targetPathAndFilename
  * @param boolean $createDirectoriesIfNecessary
  * @return void
  * @throws \TYPO3\FLOW3\Resource\Exception
  */
 protected function mirrorFile($sourcePathAndFilename, $targetPathAndFilename, $createDirectoriesIfNecessary = FALSE)
 {
     if ($createDirectoriesIfNecessary === TRUE) {
         \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively(dirname($targetPathAndFilename));
     }
     switch ($this->settings['resource']['publishing']['fileSystem']['mirrorMode']) {
         case 'copy':
             copy($sourcePathAndFilename, $targetPathAndFilename);
             touch($targetPathAndFilename, filemtime($sourcePathAndFilename));
             break;
         case 'link':
             if (file_exists($targetPathAndFilename)) {
                 if (\TYPO3\FLOW3\Utility\Files::is_link($targetPathAndFilename) && $this->realpath($targetPathAndFilename) === $this->realpath($sourcePathAndFilename)) {
                     break;
                 }
                 unlink($targetPathAndFilename);
                 symlink($sourcePathAndFilename, $targetPathAndFilename);
             } else {
                 symlink($sourcePathAndFilename, $targetPathAndFilename);
             }
             break;
         default:
             throw new \TYPO3\FLOW3\Resource\Exception('An invalid mirror mode (' . $this->settings['resource']['publishing']['fileSystem']['mirrorMode'] . ') has been configured.', 1256133400);
     }
     if (!file_exists($targetPathAndFilename)) {
         throw new \TYPO3\FLOW3\Resource\Exception('The resource "' . $sourcePathAndFilename . '" could not be mirrored.', 1207255453);
     }
 }
예제 #18
0
 /**
  * Creates a resource (file) from the given binary content as a persistent resource.
  * On a successful creation this method returns a Resource object representing the
  * newly created persistent resource.
  *
  * @param mixed $content The binary content of the file
  * @param string $filename
  * @return \TYPO3\FLOW3\Resource\Resource A resource object representing the created resource or FALSE if an error occurred.
  * @api
  */
 public function createResourceFromContent($content, $filename)
 {
     $pathInfo = pathinfo($filename);
     if (!isset($pathInfo['extension']) || substr(strtolower($pathInfo['extension']), -3, 3) === 'php') {
         return FALSE;
     }
     $hash = sha1($content);
     $finalTargetPathAndFilename = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->persistentResourcesStorageBaseUri, $hash));
     if (!file_exists($finalTargetPathAndFilename)) {
         file_put_contents($finalTargetPathAndFilename, $content);
         $this->fixFilePermissions($finalTargetPathAndFilename);
     }
     $resource = $this->createResourceFromHashAndFilename($hash, $pathInfo['basename']);
     $this->attachImportedResource($resource);
     return $resource;
 }
예제 #19
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');
 }
예제 #20
0
 /**
  * Evaluates the absolute path and filename of the resource file specified
  * by the given path.
  *
  * @param string $requestedPath
  * @param boolean $checkForExistence Whether a (non-hash) path should be checked for existence before being returned
  * @return mixed The full path and filename or FALSE if the file doesn't exist
  * @throws \TYPO3\FLOW3\Resource\Exception
  * @throws \InvalidArgumentException
  */
 protected function evaluateResourcePath($requestedPath, $checkForExistence = TRUE)
 {
     if (substr($requestedPath, 0, strlen(self::SCHEME)) !== self::SCHEME) {
         throw new \InvalidArgumentException('The ' . __CLASS__ . ' only supports the \'' . self::SCHEME . '\' scheme.', 1256052544);
     }
     $uriParts = parse_url($requestedPath);
     if (!is_array($uriParts) || !isset($uriParts['host'])) {
         return FALSE;
     }
     if (strlen($uriParts['host']) === 40) {
         $resourcePath = $this->resourceManager->getPersistentResourcesStorageBaseUri() . $uriParts['host'];
         if ($checkForExistence === FALSE || file_exists($resourcePath)) {
             return $resourcePath;
         } else {
             return FALSE;
         }
     }
     if (!$this->packageManager->isPackageAvailable($uriParts['host'])) {
         throw new \TYPO3\FLOW3\Resource\Exception(sprintf('Invalid resource URI "%s": Package "%s" is not available.', $requestedPath, $uriParts['host']), 1309269952);
     }
     $package = $this->packageManager->getPackage($uriParts['host']);
     $resourcePath = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($package->getResourcesPath(), $uriParts['path']));
     if ($checkForExistence === FALSE || file_exists($resourcePath)) {
         return $resourcePath;
     }
     return FALSE;
 }
예제 #21
0
 /**
  * Returns absolute paths to CLDR files connected in hierarchy
  *
  * For given locale, many CLDR files have to be merged in order to get full
  * set of CLDR data. For example, for 'en_GB' locale, files 'root', 'en',
  * and 'en_GB' should be merged.
  *
  * @param \TYPO3\FLOW3\I18n\Locale $locale A locale
  * @param string $directoryPath Relative path to existing CLDR directory which contains one file per locale (see 'main' directory in CLDR for example)
  * @return array<string> Absolute paths to CLDR files in hierarchy
  */
 protected function findLocaleChain(\TYPO3\FLOW3\I18n\Locale $locale, $directoryPath)
 {
     $filesInHierarchy = array(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($directoryPath, (string) $locale . '.xml')));
     $localeIdentifier = (string) $locale;
     while ($localeIdentifier = substr($localeIdentifier, 0, (int) strrpos($localeIdentifier, '_'))) {
         $possibleFilename = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($directoryPath, $localeIdentifier . '.xml'));
         if (file_exists($possibleFilename)) {
             array_unshift($filesInHierarchy, $possibleFilename);
         }
     }
     array_unshift($filesInHierarchy, \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($directoryPath, 'root.xml')));
     return $filesInHierarchy;
 }
예제 #22
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;
 }
예제 #23
0
 /**
  * Carries out all actions necessary to prepare the logging backend, such as opening
  * the log file or opening a database connection.
  *
  * @return void
  * @throws \TYPO3\FLOW3\Log\Exception\CouldNotOpenResourceException
  * @api
  */
 public function open()
 {
     $this->severityLabels = array(LOG_EMERG => 'EMERGENCY', LOG_ALERT => 'ALERT    ', LOG_CRIT => 'CRITICAL ', LOG_ERR => 'ERROR    ', LOG_WARNING => 'WARNING  ', LOG_NOTICE => 'NOTICE   ', LOG_INFO => 'INFO     ', LOG_DEBUG => 'DEBUG    ');
     if (file_exists($this->logFileUrl) && $this->maximumLogFileSize > 0 && filesize($this->logFileUrl) > $this->maximumLogFileSize) {
         $this->rotateLogFile();
     }
     if (file_exists($this->logFileUrl)) {
         $this->fileHandle = fopen($this->logFileUrl, 'ab');
     } else {
         $logPath = dirname($this->logFileUrl);
         if (!is_dir($logPath) && !is_link($logPath)) {
             if ($this->createParentDirectories === FALSE) {
                 throw new \TYPO3\FLOW3\Log\Exception\CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access because the parent directory does not exist.', 1243931200);
             }
             \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($logPath);
         }
         $this->fileHandle = fopen($this->logFileUrl, 'ab');
         if ($this->fileHandle === FALSE) {
             throw new \TYPO3\FLOW3\Log\Exception\CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access.', 1243588980);
         }
         $streamMeta = stream_get_meta_data($this->fileHandle);
         if ($streamMeta['wrapper_type'] === 'plainfile') {
             fclose($this->fileHandle);
             chmod($this->logFileUrl, 0666);
             $this->fileHandle = fopen($this->logFileUrl, 'ab');
         }
     }
     if ($this->fileHandle === FALSE) {
         throw new \TYPO3\FLOW3\Log\Exception\CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access.', 1229448440);
     }
 }
예제 #24
0
파일: Manager.php 프로젝트: nxpthx/FLOW3
 /**
  * Look for code migration files in the given package path and register them
  * for further action.
  *
  * @param string $packagePath
  * @return void
  */
 protected function registerMigrationFiles($packagePath)
 {
     $packagePath = rtrim($packagePath, '/');
     $packageKey = substr($packagePath, strrpos($packagePath, '/') + 1);
     $migrationsDirectory = Files::concatenatePaths(array($packagePath, 'Migrations/Code'));
     if (!is_dir($migrationsDirectory)) {
         return;
     }
     $migrationFilenames = Files::readDirectoryRecursively($migrationsDirectory, '.php');
     foreach ($migrationFilenames as $filenameAndPath) {
         require_once $filenameAndPath;
         $baseFilename = basename($filenameAndPath, '.php');
         $version = substr($baseFilename, 7);
         $classname = 'TYPO3\\FLOW3\\Core\\Migrations\\' . $baseFilename;
         $this->migrations[$version] = new $classname($this, $packageKey);
     }
     ksort($this->migrations);
 }
예제 #25
0
파일: Service.php 프로젝트: nxpthx/FLOW3
 /**
  * Returns the path to the existing localized version of file given.
  *
  * Searching is done for the current locale if no $locale parameter is
  * provided. The search is done according to the configured fallback
  * rule.
  *
  * If parameter $strict is provided, searching is done only for the
  * provided / current locale (without searching of files localized for
  * more generic locales).
  *
  * If no localized version of file is found, $filepath is returned without
  * any change.
  *
  * @param string $path Base directory to the translation files
  * @param string $sourceName name of the translation source
  * @param \TYPO3\FLOW3\I18n\Locale $locale Desired locale of XLIFF file
  * @return array Path to the localized file (or $filename when no localized file was found) and the matched locale
  * @see Configuration::setFallbackRule()
  * @api
  */
 public function getXliffFilenameAndPath($path, $sourceName, Locale $locale = NULL)
 {
     if ($locale === NULL) {
         $locale = $this->configuration->getCurrentLocale();
     }
     foreach ($this->getLocaleChain($locale) as $localeIdentifier => $locale) {
         $possibleXliffFilename = Files::concatenatePaths(array($path, $localeIdentifier, $sourceName . '.xlf'));
         if (file_exists($possibleXliffFilename)) {
             return array($possibleXliffFilename, $locale);
         }
     }
     return array(FALSE, $locale);
 }
예제 #26
0
 /**
  * Parse TypoScript
  * @param string $additionalTypoScriptFile
  * @return \TYPO3\TypoScript\Core\Runtime
  */
 protected function parseTypoScript($additionalTypoScriptFile = NULL)
 {
     $typoScript = file_get_contents(__DIR__ . '/Fixtures/PredefinedTypoScript.ts2');
     $typoScript .= chr(10) . chr(10) . file_get_contents(__DIR__ . '/Fixtures/BaseTypoScript.ts2');
     $fixtureDirectory = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array(__DIR__, 'Fixtures'));
     if ($additionalTypoScriptFile !== NULL) {
         $typoScript .= chr(10) . chr(10) . file_get_contents(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($fixtureDirectory, $additionalTypoScriptFile)));
     }
     $typoScript = str_replace('FIXTURE_DIRECTORY', $fixtureDirectory, $typoScript);
     $parser = new \TYPO3\TypoScript\Core\Parser();
     $typoScriptConfiguration = $parser->parse($typoScript);
     $httpRequest = \TYPO3\FLOW3\Http\Request::create(new \TYPO3\FLOW3\Http\Uri('http://foo.bar/bazfoo'));
     $request = $httpRequest->createActionRequest();
     $response = new \TYPO3\FLOW3\Http\Response();
     $controllerContext = new \TYPO3\FLOW3\Mvc\Controller\ControllerContext($request, $response, $this->getMock('TYPO3\\FLOW3\\Mvc\\Controller\\Arguments', array(), array(), '', FALSE), $this->getMock('TYPO3\\FLOW3\\Mvc\\Routing\\UriBuilder'), $this->getMock('TYPO3\\FLOW3\\Mvc\\FlashMessageContainer'));
     return new \TYPO3\TypoScript\Core\Runtime($typoScriptConfiguration, $controllerContext);
 }
예제 #27
0
 /**
  * Factory method which creates an EntityManager.
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function create()
 {
     $config = new \Doctrine\ORM\Configuration();
     $config->setClassMetadataFactoryName('TYPO3\\FLOW3\\Persistence\\Doctrine\\Mapping\\ClassMetadataFactory');
     if (class_exists($this->settings['doctrine']['cacheImplementation'])) {
         // safeguard against apc being disabled in CLI...
         if ($this->settings['doctrine']['cacheImplementation'] !== 'Doctrine\\Common\\Cache\\ApcCache' || function_exists('apc_fetch')) {
             $cache = new $this->settings['doctrine']['cacheImplementation']();
             $config->setMetadataCacheImpl($cache);
             $config->setQueryCacheImpl($cache);
         }
     }
     if (class_exists($this->settings['doctrine']['sqlLogger'])) {
         $config->setSQLLogger(new $this->settings['doctrine']['sqlLogger']());
     }
     // must use ObjectManager in compile phase...
     $flow3AnnotationDriver = $this->objectManager->get('TYPO3\\FLOW3\\Persistence\\Doctrine\\Mapping\\Driver\\Flow3AnnotationDriver');
     $config->setMetadataDriverImpl($flow3AnnotationDriver);
     $proxyDirectory = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'Doctrine/Proxies'));
     \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($proxyDirectory);
     $config->setProxyDir($proxyDirectory);
     $config->setProxyNamespace('TYPO3\\FLOW3\\Persistence\\Doctrine\\Proxies');
     $config->setAutoGenerateProxyClasses(FALSE);
     $entityManager = \Doctrine\ORM\EntityManager::create($this->settings['backendOptions'], $config);
     $flow3AnnotationDriver->setEntityManager($entityManager);
     return $entityManager;
 }
예제 #28
0
 /**
  * Returns a XliffModel instance representing desired XLIFF file.
  *
  * Will return existing instance if a model for given $sourceName was already
  * requested before. Returns FALSE when $sourceName doesn't point to existing
  * file.
  *
  * @param string $packageKey Key of the package containing the source file
  * @param string $sourceName Relative path to existing CLDR file
  * @param \TYPO3\FLOW3\I18n\Locale $locale Locale object
  * @return \TYPO3\FLOW3\I18n\Xliff\XliffModel New or existing instance
  * @throws \TYPO3\FLOW3\I18n\Exception
  */
 protected function getModel($packageKey, $sourceName, \TYPO3\FLOW3\I18n\Locale $locale)
 {
     $sourcePath = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array('resource://' . $packageKey, $this->xliffBasePath));
     list($sourcePath, $foundLocale) = $this->localizationService->getXliffFilenameAndPath($sourcePath, $sourceName, $locale);
     if ($sourcePath === FALSE) {
         throw new \TYPO3\FLOW3\I18n\Exception('No XLIFF file is available for ' . $packageKey . '::' . $sourceName . '::' . $locale . ' in the locale chain.', 1334759591);
     }
     if (isset($this->models[$sourcePath])) {
         return $this->models[$sourcePath];
     }
     return $this->models[$sourcePath] = new \TYPO3\FLOW3\I18n\Xliff\XliffModel($sourcePath, $foundLocale);
 }
예제 #29
0
 /**
  * Removes all cache entries of this cache.
  *
  * @return void
  * @api
  */
 public function flush()
 {
     \TYPO3\FLOW3\Utility\Files::emptyDirectoryRecursively($this->cacheDirectory);
 }
예제 #30
0
파일: PhpSession.php 프로젝트: nxpthx/FLOW3
 /**
  * Destroys (file) data from all active PHP sessions.
  *
  * @param \TYPO3\FLOW3\Core\Bootstrap $bootstrap
  * @return integer The number of session files which have been removed
  */
 public static function destroyAll(Bootstrap $bootstrap)
 {
     $settings = $bootstrap->getObjectManager()->get('TYPO3\\FLOW3\\Configuration\\ConfigurationManager')->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.FLOW3');
     if (empty($settings['session']['PhpSession']['savePath'])) {
         $sessionsPath = Files::concatenatePaths(array($bootstrap->getObjectManager()->get('TYPO3\\FLOW3\\Utility\\Environment')->getPathToTemporaryDirectory(), 'Sessions'));
     } else {
         $sessionsPath = $settings['session']['PhpSession']['savePath'];
     }
     if (is_dir($sessionsPath)) {
         $filenames = Files::readDirectoryRecursively($sessionsPath);
         if (count($filenames) > 0) {
             Files::emptyDirectoryRecursively($sessionsPath);
         }
         return count($filenames);
     } else {
         return 0;
     }
 }