コード例 #1
0
 /**
  * @test
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function getLanguagesScansFormatDirectoryAndReturnsLanguagesAsStrings()
 {
     $formatPath = \vfsStream::url('testDirectory') . '/';
     \F3\FLOW3\Utility\Files::createDirectoryRecursively($formatPath . 'en');
     $format = new \F3\FLOW3\Package\Documentation\Format('DocBook', $formatPath);
     $availableLanguages = $format->getAvailableLanguages();
     $this->assertEquals(array('en'), $availableLanguages);
 }
コード例 #2
0
 /**
  * @test
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function getDocumentationFormatsScansDocumentationDirectoryAndReturnsDocumentationFormatObjectsIndexedByFormatName()
 {
     $documentationPath = \vfsStream::url('testDirectory') . '/';
     $mockPackage = $this->getMock('F3\\FLOW3\\Package\\PackageInterface');
     \F3\FLOW3\Utility\Files::createDirectoryRecursively($documentationPath . 'DocBook/en');
     $mockDocumentationFormat = $this->getMock('F3\\FLOW3\\Package\\Documentation\\Format', array('dummy'), array(), '', FALSE);
     $mockObjectFactory = $this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface');
     $mockObjectFactory->expects($this->once())->method('create')->with('F3\\FLOW3\\Package\\Documentation\\Format', 'DocBook', $documentationPath . 'DocBook/')->will($this->returnValue($mockDocumentationFormat));
     $documentation = new \F3\FLOW3\Package\Documentation($mockPackage, 'Manual', $documentationPath);
     $documentation->injectObjectFactory($mockObjectFactory);
     $documentationFormats = $documentation->getDocumentationFormats();
     $this->assertEquals(array('DocBook' => $mockDocumentationFormat), $documentationFormats);
 }
コード例 #3
0
 /**
  * Generate the XSD file.
  *
  * @param string $baseNamespace
  * @param string $namespacePrefix
  * @return string HTML string
  * @author Sebastian Kurfürst <*****@*****.**>
  * @todo Still has to be finished
  */
 public function generateXsdAction($baseNamespace, $namespacePrefix)
 {
     $xsdFileContents = $this->xsdGenerator->generateXSD($baseNamespace);
     $path = 'Resources/Fluid/XSD/';
     if (!is_dir(FLOW3_PATH_WEB . $path)) {
         \F3\FLOW3\Utility\Files::createDirectoryRecursively(FLOW3_PATH_WEB . $path);
     }
     $filename = $path . str_replace('\\', '_', $baseNamespace) . '.xsd';
     $fp = fopen(FLOW3_PATH_WEB . $filename, 'w');
     fputs($fp, $xsdFileContents);
     fclose($fp);
     return $this->view->assign('xsdPath', $filename)->assign('namespaceUri', 'http://typo3.org/ns/fluid/' . str_replace('\\', '/', $baseNamespace))->assign('namespacePrefix', $namespacePrefix)->assign('view', $this->view)->render();
 }
コード例 #4
0
    /**
     * Saves the current configuration into a cache file and creates a cache inclusion script
     * in the context's Configuration directory.
     *
     * @return void
     * @author Robert Lemke <*****@*****.**>
     */
    protected function saveConfigurationCache()
    {
        $configurationCachePath = $this->environment->getPathToTemporaryDirectory() . 'Configuration/';
        if (!file_exists($configurationCachePath)) {
            \F3\FLOW3\Utility\Files::createDirectoryRecursively($configurationCachePath);
        }
        $cachePathAndFilename = $configurationCachePath . $this->context . 'Configurations.php';
        $currentRevision = \F3\FLOW3\Core\Bootstrap::REVISION;
        $includeCachedConfigurationsCode = <<<EOD
<?php
\tif (file_exists('{$cachePathAndFilename}') && \\F3\\FLOW3\\Core\\Bootstrap::REVISION === '{$currentRevision}') {
\t\treturn require '{$cachePathAndFilename}';
\t} else {
\t\tunlink(__FILE__);
\t\treturn array();
\t}
?>
EOD;
        file_put_contents($cachePathAndFilename, '<?php return ' . var_export($this->configurations, TRUE) . '?>');
        file_put_contents($this->includeCachedConfigurationsPathAndFilename, $includeCachedConfigurationsCode);
    }
コード例 #5
0
 /**
  * Create a package, given the package key
  *
  * @param string $packageKey The package key of the new package
  * @param \F3\FLOW3\Package\MetaData $packageMetaData If specified, this package meta object is used for writing the Package.xml file
  * @param string $packagesPath If specified, the package will be created in this path, otherwise getLocalPackagesPath() is used
  * @return \F3\FLOW3\Package\Package The newly created package
  * @author Christopher Hlubek <*****@*****.**>
  * @api
  */
 public function createPackage($packageKey, \F3\FLOW3\Package\MetaData $packageMetaData = NULL, $packagesPath = '')
 {
     if (!$this->isPackageKeyValid($packageKey)) {
         throw new \F3\FLOW3\Package\Exception\InvalidPackageKeyException('The package key "' . $packageKey . '" is invalid', 1220722210);
     }
     if ($this->isPackageAvailable($packageKey)) {
         throw new \F3\FLOW3\Package\Exception\PackageKeyAlreadyExistsException('The package key "' . $packageKey . '" already exists', 1220722873);
     }
     if ($packageMetaData === NULL) {
         $packageMetaData = $this->objectFactory->create('F3\\FLOW3\\Package\\MetaData', $packageKey);
     }
     if ($packagesPath === '') {
         $packagesPath = $this->getLocalPackagesPath();
     }
     if ($packagesPath === '') {
         throw new \F3\FLOW3\Package\Exception\InvalidPackagePathException('The path "Packages/Application" does not exist.', 1243932738);
     }
     $packagePath = $packagesPath . $packageKey . '/';
     \F3\FLOW3\Utility\Files::createDirectoryRecursively($packagePath);
     foreach (array(\F3\FLOW3\Package\Package::DIRECTORY_METADATA, \F3\FLOW3\Package\Package::DIRECTORY_CLASSES, \F3\FLOW3\Package\Package::DIRECTORY_CONFIGURATION, \F3\FLOW3\Package\Package::DIRECTORY_DOCUMENTATION, \F3\FLOW3\Package\Package::DIRECTORY_RESOURCES, \F3\FLOW3\Package\Package::DIRECTORY_TESTS_UNIT, \F3\FLOW3\Package\Package::DIRECTORY_TESTS_INTEGRATION, \F3\FLOW3\Package\Package::DIRECTORY_TESTS_SYSTEM) as $path) {
         \F3\FLOW3\Utility\Files::createDirectoryRecursively($packagePath . $path);
     }
     $package = $this->objectFactory->create('F3\\FLOW3\\Package\\Package', $packageKey, $packagePath);
     $result = $this->packageMetaDataWriter->writePackageMetaData($package, $packageMetaData);
     if ($result === FALSE) {
         throw new \F3\FLOW3\Package\Exception('Error while writing the package meta data information at "' . $packagePath . '"', 1232625240);
     }
     $this->packages[$packageKey] = $package;
     foreach (array_keys($this->packages) as $upperCamelCasedPackageKey) {
         $this->packageKeys[strtolower($upperCamelCasedPackageKey)] = $upperCamelCasedPackageKey;
     }
     return $package;
 }
コード例 #6
0
 /**
  * Creates FLOW3's temporary directory - or at least asserts that it exists and is
  * writable.
  *
  * @param string $temporaryDirectoryBase Full path to the base for the temporary directory
  * @return string The full path to the temporary directory
  * @throws \F3\FLOW3\Utility\Exception if the temporary directory could not be created or is not writable
  * @author Robert Lemke <*****@*****.**>
  * @author Bastian Waidelich <*****@*****.**>
  */
 protected function createTemporaryDirectory($temporaryDirectoryBase)
 {
     $temporaryDirectoryBase = \F3\FLOW3\Utility\Files::getUnixStylePath($temporaryDirectoryBase);
     if (substr($temporaryDirectoryBase, -1, 1) !== '/') {
         $temporaryDirectoryBase .= '/';
     }
     $maximumPathLength = $this->getMaximumPathLength();
     if (strlen($temporaryDirectoryBase) > $maximumPathLength - 230) {
         $this->systemLogger->log('The path to your temporary directory is ' . strlen($temporaryDirectoryBase) . ' characters long. The maximum path length of your system is only ' . $maximumPathLength . '. Please consider setting the temporaryDirectoryBase option to a shorter path.', LOG_WARNING);
     }
     $processUser = extension_loaded('posix') ? posix_getpwuid(posix_geteuid()) : array('name' => 'default');
     $pathHash = substr(md5(FLOW3_PATH_WEB . $this->getSAPIName() . $processUser['name'] . $this->context), 0, 12);
     $temporaryDirectory = $temporaryDirectoryBase . $pathHash . '/';
     if (!is_dir($temporaryDirectory)) {
         try {
             \F3\FLOW3\Utility\Files::createDirectoryRecursively($temporaryDirectory);
         } catch (\F3\FLOW3\Error\Exception $exception) {
         }
     }
     if (!is_writable($temporaryDirectory)) {
         throw new \F3\FLOW3\Utility\Exception('The temporary directory "' . $temporaryDirectory . '" could not be created or is not writable for the current user "' . $processUser['name'] . '". Please make this directory writable or define another temporary directory by setting the respective system environment variable (eg. TMPDIR) or defining it in the FLOW3 settings.', 1216287176);
     }
     return $temporaryDirectory;
 }
コード例 #7
0
 /**
  * @test
  * @author Robert Lemke <*****@*****.**>
  */
 public function publishStaticResourcesDoesNotMirrorAFileIfItAlreadyExistsAndTheModificationTimeIsEqualOrNewer()
 {
     mkdir('vfs://Foo/Sources');
     file_put_contents('vfs://Foo/Sources/file1.txt', 1);
     file_put_contents('vfs://Foo/Sources/file2.txt', 1);
     file_put_contents('vfs://Foo/Sources/file3.txt', 1);
     \F3\FLOW3\Utility\Files::createDirectoryRecursively('vfs://Foo/Web/_Resources/Static/Bar');
     file_put_contents('vfs://Foo/Web/_Resources/Static/Bar/file2.txt', 1);
     \vfsStreamWrapper::getRoot()->getChild('Web/_Resources/Static/Bar/file2.txt')->setFilemtime(time() - 5);
     file_put_contents('vfs://Foo/Web/_Resources/Static/Bar/file3.txt', 1);
     $mirrorFileCallback = function ($sourcePathAndFilename, $targetPathAndFilename) {
         if ($sourcePathAndFilename === 'vfs://Foo/Sources/file3.txt') {
             throw new \Exception('file3.txt should not have been mirrored.');
         }
     };
     $publishingTarget = $this->getMock($this->buildAccessibleProxy('\\F3\\FLOW3\\Resource\\Publishing\\FileSystemPublishingTarget'), array('mirrorFile'));
     $publishingTarget->_set('resourcesPublishingPath', 'vfs://Foo/Web/_Resources/');
     $publishingTarget->expects($this->exactly(2))->method('mirrorFile')->will($this->returnCallback($mirrorFileCallback));
     $result = $publishingTarget->publishStaticResources('vfs://Foo/Sources', 'Bar');
     $this->assertTrue($result);
 }
コード例 #8
0
 /**
  * Carries out all actions necessary to prepare the logging backend, such as opening
  * the log file or opening a database connection.
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  * @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, 'at');
     } else {
         $logPath = dirname($this->logFileUrl);
         if (!is_dir($logPath)) {
             if ($this->createParentDirectories === FALSE) {
                 throw new \F3\FLOW3\Log\Exception\CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access because the parent directory does not exist.', 1243931200);
             }
             \F3\FLOW3\Utility\Files::createDirectoryRecursively($logPath);
         }
         $this->fileHandle = fopen($this->logFileUrl, 'at');
         if ($this->fileHandle === FALSE) {
             throw new \F3\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, 'at');
         }
     }
     if ($this->fileHandle === FALSE) {
         throw new \F3\FLOW3\Log\Exception\CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access.', 1229448440);
     }
 }
コード例 #9
0
 /**
  * @test
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function getPackageDocumentationsScansDocumentationDirectoryAndCreatesDocumentationObjects()
 {
     \vfsStreamWrapper::register();
     \vfsStreamWrapper::setRoot(new \vfsStreamDirectory('testDirectory'));
     $packagePath = \vfsStream::url('testDirectory') . '/';
     \F3\FLOW3\Utility\Files::createDirectoryRecursively($packagePath . 'Documentation/Manual/DocBook/en');
     $mockDocumentation = $this->getMock('F3\\FLOW3\\Package\\Documentation', array('dummy'), array(), '', FALSE);
     $package = new \F3\FLOW3\Package\Package('FLOW3', $packagePath);
     $mockObjectFactory = $this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface');
     $mockObjectFactory->expects($this->once())->method('create')->with('F3\\FLOW3\\Package\\Documentation', $package, 'Manual', $packagePath . 'Documentation/Manual/')->will($this->returnValue($mockDocumentation));
     $package->injectObjectFactory($mockObjectFactory);
     $documentations = $package->getPackageDocumentations();
     $this->assertEquals(array('Manual' => $mockDocumentation), $documentations);
 }
コード例 #10
0
 /**
  * Sets up the APC backend used for testing
  *
  * @return \F3\FLOW3\Cache\Backend\PdoBackend
  * @author Karsten Dambekalns <*****@*****.**>
  */
 protected function setUpBackend()
 {
     $environment = $this->objectManager->getObject('F3\\FLOW3\\Utility\\Environment');
     $this->fixtureFolder = $environment->getPathToTemporaryDirectory() . 'FLOW3/Tests/';
     \F3\FLOW3\Utility\Files::createDirectoryRecursively($this->fixtureFolder);
     $this->fixtureDB = uniqid('Cache') . '.db';
     $pdoHelper = new \F3\FLOW3\Utility\PdoHelper('sqlite:' . $this->fixtureFolder . $this->fixtureDB, '', '');
     $pdoHelper->importSql(FLOW3_PATH_FLOW3 . 'Resources/Private/Cache/SQL/DDL.sql');
     $mockSystemLogger = $this->getMock('F3\\FLOW3\\Log\\SystemLoggerInterface');
     $mockCache = $this->getMock('F3\\FLOW3\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
     $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('TestCache'));
     $backend = new \F3\FLOW3\Cache\Backend\PdoBackend('Testing');
     $backend->injectEnvironment($environment);
     $backend->injectSystemLogger($mockSystemLogger);
     $backend->setCache($mockCache);
     $backend->setDataSourceName('sqlite:' . $this->fixtureFolder . $this->fixtureDB);
     $backend->initializeObject();
     return $backend;
 }
コード例 #11
0
 /**
  * Setter for where the coverage output should go
  *
  * @param string $path
  * @return void
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function setCoverageOutputPath($path)
 {
     if (!is_dir($path)) {
         \F3\FLOW3\Utility\Files::createDirectoryRecursively($path);
     }
     $this->coverageOutputPath = $path;
 }
コード例 #12
0
 /**
  * Depending on the settings of this publishing target copies the specified file
  * or creates a symbolic link.
  *
  * @param string $sourcePathAndFilename
  * @param string $targetPathAndFilename
  * @return void
  * @author Robert Lemke <*****@*****.**>
  * @author Karsten Dambekalns <*****@*****.**>
  */
 protected function mirrorFile($sourcePathAndFilename, $targetPathAndFilename, $createDirectoriesIfNecessary)
 {
     if ($createDirectoriesIfNecessary === TRUE) {
         \F3\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 (is_link($targetPathAndFilename) && readlink($targetPathAndFilename) === $sourcePathAndFilename) {
                     break;
                 }
                 unlink($targetPathAndFilename);
                 symlink($sourcePathAndFilename, $targetPathAndFilename);
             } else {
                 symlink($sourcePathAndFilename, $targetPathAndFilename);
             }
             break;
         default:
             throw new \F3\FLOW3\Resource\Exception('An invalid mirror mode (' . $this->settings['resource']['publishing']['fileSystem']['mirrorMode'] . ') has been configured.', 1256133400);
     }
     if (!file_exists($targetPathAndFilename)) {
         throw new \F3\FLOW3\Resource\Exception('The resource "' . str_replace($sourcePath, '', $sourcePathAndFilename) . '" could not be mirrored.', 1207255453);
     }
 }
コード例 #13
0
 /**
  * Generate a file with the given content and add it to the
  * generated files
  *
  * @param string $targetPathAndFilename
  * @param string $fileContent
  * @return void
  * @author Christopher Hlubek <*****@*****.**>
  */
 protected function generateFile($targetPathAndFilename, $fileContent)
 {
     if (!is_dir(dirname($targetPathAndFilename))) {
         \F3\FLOW3\Utility\Files::createDirectoryRecursively(dirname($targetPathAndFilename));
     }
     file_put_contents($targetPathAndFilename, $fileContent);
     $relativeTargetPathAndFilename = substr($targetPathAndFilename, strlen(FLOW3_PATH_ROOT) - 1);
     $this->generatedFiles[] = '+ ...' . $relativeTargetPathAndFilename;
 }
コード例 #14
0
 /**
  * Sets a reference to the cache frontend which uses this backend and
  * initializes the default cache directory
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 public function setCache(\F3\FLOW3\Cache\Frontend\FrontendInterface $cache)
 {
     parent::setCache($cache);
     $cacheDirectory = $this->environment->getPathToTemporaryDirectory() . 'Cache/' . $this->cacheIdentifier . '/';
     if (!is_writable($cacheDirectory)) {
         try {
             \F3\FLOW3\Utility\Files::createDirectoryRecursively($cacheDirectory);
         } catch (\F3\FLOW3\Utility\Exception $exception) {
             throw new \F3\FLOW3\Cache\Exception('The cache directory "' . $cacheDirectory . '" could not be created.', 1264426237);
         }
     }
     if (!is_dir($cacheDirectory)) {
         throw new \F3\FLOW3\Cache\Exception('The cache directory "' . $cacheDirectory . '" does not exist.', 1203965199);
     }
     if (!is_writable($cacheDirectory)) {
         throw new \F3\FLOW3\Cache\Exception('The cache directory "' . $cacheDirectory . '" is not writable.', 1203965200);
     }
     $this->cacheDirectory = $cacheDirectory;
 }