/**
  * @return void
  */
 protected function writeComposerManifest()
 {
     $composerJsonFilename = Files::concatenatePaths(array($this->targetPackageData['path'], 'composer.json'));
     if (file_exists($composerJsonFilename)) {
         return;
     }
     $manifest = array();
     $nameParts = explode('.', $this->targetPackageData['packageKey']);
     $vendor = array_shift($nameParts);
     $manifest['name'] = strtolower($vendor . '/' . implode('-', $nameParts));
     switch ($this->targetPackageData['category']) {
         case 'Application':
             $manifest['type'] = 'typo3-flow-package';
             break;
         default:
             $manifest['type'] = strtolower('typo3-flow-' . $this->targetPackageData['category']);
     }
     $manifest['description'] = $this->targetPackageData['meta']['description'];
     $manifest['version'] = $this->targetPackageData['meta']['version'];
     $manifest['require'] = array('typo3/flow' => '*');
     $manifest['autoload'] = array('psr-0' => array(str_replace('.', '\\', $this->targetPackageData['packageKey']) => 'Classes'));
     if (defined('JSON_PRETTY_PRINT')) {
         file_put_contents($composerJsonFilename, json_encode($manifest, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
     } else {
         file_put_contents($composerJsonFilename, json_encode($manifest));
     }
 }
示例#2
0
 /**
  * Returns a package instance.
  *
  * @param string $packagesBasePath the base install path of packages,
  * @param string $packagePath path to package, relative to base path
  * @param string $packageKey key / name of the package
  * @param string $classesPath path to the classes directory, relative to the package path
  * @param string $manifestPath path to the package's Composer manifest, relative to package path, defaults to same path
  * @return \TYPO3\Flow\Package\PackageInterface
  * @throws \TYPO3\Flow\Package\Exception\CorruptPackageException
  */
 public function create($packagesBasePath, $packagePath, $packageKey, $classesPath, $manifestPath = '')
 {
     $packagePath = Files::getNormalizedPath(Files::concatenatePaths(array($packagesBasePath, $packagePath)));
     $packageClassPathAndFilename = Files::concatenatePaths(array($packagePath, 'Classes/' . str_replace('.', '/', $packageKey) . '/Package.php'));
     $alternativeClassPathAndFilename = Files::concatenatePaths(array($packagePath, 'Classes/Package.php'));
     $packageClassPathAndFilename = @file_exists($alternativeClassPathAndFilename) ? $alternativeClassPathAndFilename : $packageClassPathAndFilename;
     if (@file_exists($packageClassPathAndFilename)) {
         require_once $packageClassPathAndFilename;
         if (substr($packagePath, 0, strlen(PATH_typo3)) === PATH_typo3 && strpos($packageKey, '.') === FALSE) {
             //TODO Remove this exception once the systextension are renamed to proper Flow naming scheme packages
             $packageClassName = 'TYPO3\\CMS\\' . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($packageKey) . '\\Package';
         } else {
             $packageClassName = str_replace('.', '\\', $packageKey) . '\\Package';
         }
         if (!class_exists($packageClassName, FALSE)) {
             throw new \TYPO3\Flow\Package\Exception\CorruptPackageException(sprintf('The package "%s" does not contain a valid package class. Check if the file "%s" really contains a class called "%s".', $packageKey, $packageClassPathAndFilename, $packageClassName), 1327587092);
         }
     } else {
         $emConfPath = Files::concatenatePaths(array($packagePath, 'ext_emconf.php'));
         $packageClassName = @file_exists($emConfPath) ? 'TYPO3\\CMS\\Core\\Package\\Package' : 'TYPO3\\Flow\\Package\\Package';
     }
     /** @var $package \TYPO3\Flow\Package\PackageInterface */
     $package = new $packageClassName($this->packageManager, $packageKey, $packagePath, $classesPath, $manifestPath);
     return $package;
 }
 /**
  * Execute this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options Supported options: "scriptBasePath" and "scriptIdentifier"
  * @return void
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $workspacePath = $deployment->getWorkspacePath($application);
     $scriptBasePath = isset($options['scriptBasePath']) ? $options['scriptBasePath'] : Files::concatenatePaths(array($workspacePath, 'Web'));
     if (!isset($options['scriptIdentifier'])) {
         // Generate random identifier
         $factory = new \RandomLib\Factory();
         $generator = $factory->getMediumStrengthGenerator();
         $scriptIdentifier = $generator->generateString(32, \RandomLib\Generator::CHAR_ALNUM);
         // Store the script identifier as an application option
         $application->setOption('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask[scriptIdentifier]', $scriptIdentifier);
     } else {
         $scriptIdentifier = $options['scriptIdentifier'];
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $commands = array('cd ' . escapeshellarg($scriptBasePath), 'rm -f surf-opcache-reset-*');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
     if (!$deployment->isDryRun()) {
         $scriptFilename = $scriptBasePath . '/surf-opcache-reset-' . $scriptIdentifier . '.php';
         $result = file_put_contents($scriptFilename, '<?php
             if (function_exists("opcache_reset")) {
                 opcache_reset();
             }
             @unlink(__FILE__);
             echo "success";
         ');
         if ($result === false) {
             throw new \TYPO3\Surf\Exception\TaskExecutionException('Could not write file "' . $scriptFilename . '"', 1421932414);
         }
     }
 }
 /**
  * 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;
 }
 /**
  * Calls actions and install scripts provided by installed packages.
  *
  * @param \Composer\Script\PackageEvent $event
  * @return void
  * @throws Exception\UnexpectedOperationException
  */
 public static function postPackageUpdateAndInstall(PackageEvent $event)
 {
     $operation = $event->getOperation();
     if (!$operation instanceof \Composer\DependencyResolver\Operation\InstallOperation && !$operation instanceof \Composer\DependencyResolver\Operation\UpdateOperation) {
         throw new Exception\UnexpectedOperationException('Handling of operation with type "' . $operation->getJobType() . '" not supported', 1348750840);
     }
     $package = $operation->getJobType() === 'install' ? $operation->getPackage() : $operation->getTargetPackage();
     $packageExtraConfig = $package->getExtra();
     if (isset($packageExtraConfig['typo3/flow'])) {
         if (isset($packageExtraConfig['typo3/flow']['post-install']) && $operation->getJobType() === 'install') {
             self::runPackageScripts($packageExtraConfig['typo3/flow']['post-install']);
         } elseif (isset($packageExtraConfig['typo3/flow']['post-update']) && $operation->getJobType() === 'update') {
             self::runPackageScripts($packageExtraConfig['typo3/flow']['post-update']);
         }
         $installPath = $event->getComposer()->getInstallationManager()->getInstallPath($package);
         $relativeInstallPath = str_replace(getcwd() . '/', '', $installPath);
         if (isset($packageExtraConfig['typo3/flow']['manage-resources']) && $packageExtraConfig['typo3/flow']['manage-resources'] === TRUE) {
             if (is_dir($relativeInstallPath . '/Resources/Private/Installer/Distribution/Essentials')) {
                 Files::copyDirectoryRecursively($relativeInstallPath . '/Resources/Private/Installer/Distribution/Essentials', './', FALSE, TRUE);
             }
             if (is_dir($relativeInstallPath . '/Resources/Private/Installer/Distribution/Defaults')) {
                 Files::copyDirectoryRecursively($relativeInstallPath . '/Resources/Private/Installer/Distribution/Defaults', './', TRUE, TRUE);
             }
         }
     }
 }
 /**
  * Add a warning for each HTML file that uses one of the f:uri.* or the f:format.json ViewHelpers
  *
  * @param string $packagePath
  * @return void
  */
 protected function addWarningsForAffectedViewHelpers($packagePath)
 {
     $foundAffectedViewHelpers = array();
     $allPathsAndFilenames = Files::readDirectoryRecursively($packagePath, NULL, TRUE);
     foreach ($allPathsAndFilenames as $pathAndFilename) {
         $pathInfo = pathinfo($pathAndFilename);
         if (!isset($pathInfo['filename']) || $pathInfo['extension'] !== 'html') {
             continue;
         }
         $fileContents = file_get_contents($pathAndFilename);
         preg_match_all('/f\\:(uri\\.[\\w]+|format\\.json)/', $fileContents, $matches, PREG_SET_ORDER);
         foreach ($matches as $match) {
             $viewHelperName = $match[1];
             if (!isset($foundAffectedViewHelpers[$viewHelperName])) {
                 $foundAffectedViewHelpers[$viewHelperName] = array();
             }
             $truncatedPathAndFilename = substr($pathAndFilename, strlen($packagePath) + 1);
             if (!in_array($truncatedPathAndFilename, $foundAffectedViewHelpers[$viewHelperName])) {
                 $foundAffectedViewHelpers[$viewHelperName][] = $truncatedPathAndFilename;
             }
         }
     }
     foreach ($foundAffectedViewHelpers as $viewHelperName => $filePathsAndNames) {
         $this->showWarning(sprintf('The behavior of the "%s" ViewHelper has been changed to produce escaped output.' . chr(10) . 'This package makes use of this ViewHelper in the following files:' . chr(10) . '- %s' . chr(10) . 'See upgrading instructions for further details.' . chr(10), $viewHelperName, implode(chr(10) . '- ', $filePathsAndNames)));
     }
 }
 /**
  * @return \TYPO3\Flow\Resource\Resource
  * @throws \TYPO3\Flow\Resource\Exception
  */
 protected function buildTestResource()
 {
     $testImagePath = Files::concatenatePaths([__DIR__, 'Fixtures/Resources/Lighthouse.jpg']);
     $resource = $this->resourceManager->importResource($testImagePath);
     $asset = new \TYPO3\Media\Domain\Model\Asset($resource);
     return $asset;
 }
 /**
  * Returns a package instance.
  *
  * @param string $packagesBasePath the base install path of packages,
  * @param string $packagePath path to package, relative to base path
  * @param string $packageKey key / name of the package
  * @param string $classesPath path to the classes directory, relative to the package path
  * @param string $manifestPath path to the package's Composer manifest, relative to package path, defaults to same path
  * @return \TYPO3\Flow\Package\PackageInterface
  * @throws Exception\CorruptPackageException
  */
 public function create($packagesBasePath, $packagePath, $packageKey, $classesPath = null, $manifestPath = null)
 {
     $absolutePackagePath = Files::concatenatePaths(array($packagesBasePath, $packagePath)) . '/';
     $absoluteManifestPath = $manifestPath === null ? $absolutePackagePath : Files::concatenatePaths(array($absolutePackagePath, $manifestPath)) . '/';
     $autoLoadDirectives = array();
     try {
         $autoLoadDirectives = (array) PackageManager::getComposerManifest($absoluteManifestPath, 'autoload');
     } catch (MissingPackageManifestException $exception) {
     }
     if (isset($autoLoadDirectives[Package::AUTOLOADER_TYPE_PSR4])) {
         $packageClassPathAndFilename = Files::concatenatePaths(array($absolutePackagePath, 'Classes', 'Package.php'));
     } else {
         $packageClassPathAndFilename = Files::concatenatePaths(array($absolutePackagePath, 'Classes', str_replace('.', '/', $packageKey), 'Package.php'));
     }
     $package = null;
     if (file_exists($packageClassPathAndFilename)) {
         require_once $packageClassPathAndFilename;
         $packageClassContents = file_get_contents($packageClassPathAndFilename);
         $packageClassName = (new PhpAnalyzer($packageClassContents))->extractFullyQualifiedClassName();
         if ($packageClassName === null) {
             throw new Exception\CorruptPackageException(sprintf('The package "%s" does not contain a valid package class. Check if the file "%s" really contains a class.', $packageKey, $packageClassPathAndFilename), 1327587091);
         }
         $package = new $packageClassName($this->packageManager, $packageKey, $absolutePackagePath, $classesPath, $manifestPath);
         if (!$package instanceof PackageInterface) {
             throw new Exception\CorruptPackageException(sprintf('The package class of package "%s" does not implement \\TYPO3\\Flow\\Package\\PackageInterface. Check the file "%s".', $packageKey, $packageClassPathAndFilename), 1427193370);
         }
         return $package;
     }
     return new Package($this->packageManager, $packageKey, $absolutePackagePath, $classesPath, $manifestPath);
 }
示例#9
0
 /**
  * Returns a ProfilingRun instance that has been saved as $filename.
  *
  * @param string $filename
  * @return \Sandstorm\PhpProfiler\Domain\Model\ProfilingRun
  */
 protected function getProfile($filename)
 {
     $pathAndFilename = Files::concatenatePaths(array($this->settings['profilePath'], $filename));
     $profile = unserialize(file_get_contents($pathAndFilename));
     $profile->setPathAndFilename($pathAndFilename);
     return $profile;
 }
 /**
  * @param string $subject
  * @param boolean $exclusiveLock TRUE to, acquire an exclusive (write) lock, FALSE for a shared (read) lock.
  * @throws LockNotAcquiredException
  * @throws \TYPO3\Flow\Utility\Exception
  * @return void
  */
 public function acquire($subject, $exclusiveLock)
 {
     if ($this->isWindowsOS()) {
         return;
     }
     if (self::$temporaryDirectory === null) {
         if (Bootstrap::$staticObjectManager === null || !Bootstrap::$staticObjectManager->isRegistered(\TYPO3\Flow\Utility\Environment::class)) {
             throw new LockNotAcquiredException('Environment object could not be accessed', 1386680952);
         }
         $environment = Bootstrap::$staticObjectManager->get(\TYPO3\Flow\Utility\Environment::class);
         $temporaryDirectory = Files::concatenatePaths(array($environment->getPathToTemporaryDirectory(), 'Lock'));
         Files::createDirectoryRecursively($temporaryDirectory);
         self::$temporaryDirectory = $temporaryDirectory;
     }
     $this->lockFileName = Files::concatenatePaths(array(self::$temporaryDirectory, md5($subject)));
     if (($this->filePointer = @fopen($this->lockFileName, 'r')) === false) {
         if (($this->filePointer = @fopen($this->lockFileName, 'w')) === false) {
             throw new LockNotAcquiredException(sprintf('Lock file "%s" could not be opened', $this->lockFileName), 1386520596);
         }
     }
     if ($exclusiveLock === false && flock($this->filePointer, LOCK_SH) === true) {
         // Shared lock acquired
     } elseif ($exclusiveLock === true && flock($this->filePointer, LOCK_EX) === true) {
         // Exclusive lock acquired
     } else {
         throw new LockNotAcquiredException(sprintf('Could not lock file "%s"', $this->lockFileName), 1386520597);
     }
 }
 /**
  * @test
  */
 public function getPathToTemporaryDirectoryReturnsAnExistingPath()
 {
     $environment = new \TYPO3\Flow\Utility\Environment(new ApplicationContext('Testing'));
     $environment->setTemporaryDirectoryBase(\TYPO3\Flow\Utility\Files::concatenatePaths(array(sys_get_temp_dir(), 'FlowEnvironmentTest')));
     $path = $environment->getPathToTemporaryDirectory();
     $this->assertTrue(file_exists($path), 'The temporary path does not exist.');
 }
 /**
  * Factory method which creates an EntityManager.
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function create()
 {
     $config = new \Doctrine\ORM\Configuration();
     $config->setClassMetadataFactoryName('TYPO3\\Flow\\Persistence\\Doctrine\\Mapping\\ClassMetadataFactory');
     $cache = new \TYPO3\Flow\Persistence\Doctrine\CacheAdapter();
     // must use ObjectManager in compile phase...
     $cache->setCache($this->objectManager->get('TYPO3\\Flow\\Cache\\CacheManager')->getCache('Flow_Persistence_Doctrine'));
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $resultCache = new \TYPO3\Flow\Persistence\Doctrine\CacheAdapter();
     // must use ObjectManager in compile phase...
     $resultCache->setCache($this->objectManager->get('TYPO3\\Flow\\Cache\\CacheManager')->getCache('Flow_Persistence_Doctrine_Results'));
     $config->setResultCacheImpl($resultCache);
     if (class_exists($this->settings['doctrine']['sqlLogger'])) {
         $config->setSQLLogger(new $this->settings['doctrine']['sqlLogger']());
     }
     $eventManager = $this->buildEventManager();
     $flowAnnotationDriver = $this->objectManager->get('TYPO3\\Flow\\Persistence\\Doctrine\\Mapping\\Driver\\FlowAnnotationDriver');
     $config->setMetadataDriverImpl($flowAnnotationDriver);
     $proxyDirectory = \TYPO3\Flow\Utility\Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'Doctrine/Proxies'));
     \TYPO3\Flow\Utility\Files::createDirectoryRecursively($proxyDirectory);
     $config->setProxyDir($proxyDirectory);
     $config->setProxyNamespace('TYPO3\\Flow\\Persistence\\Doctrine\\Proxies');
     $config->setAutoGenerateProxyClasses(FALSE);
     $entityManager = \Doctrine\ORM\EntityManager::create($this->settings['backendOptions'], $config, $eventManager);
     $flowAnnotationDriver->setEntityManager($entityManager);
     \Doctrine\DBAL\Types\Type::addType('objectarray', 'TYPO3\\Flow\\Persistence\\Doctrine\\DataTypes\\ObjectArray');
     if (isset($this->settings['doctrine']['filters']) && is_array($this->settings['doctrine']['filters'])) {
         foreach ($this->settings['doctrine']['filters'] as $filterName => $filterClass) {
             $config->addFilter($filterName, $filterClass);
             $entityManager->getFilters()->enable($filterName);
         }
     }
     return $entityManager;
 }
示例#13
0
 /**
  * @param string $filename
  * @return string
  * @throws \TYPO3\Flow\Utility\Exception
  */
 public function getDocumentAbsolutePath($filename = null)
 {
     $path = str_replace('\\', '/', get_called_class());
     $documentAbsolutePath = $this->temporaryDirectoryBase . $path . '/';
     Files::createDirectoryRecursively($documentAbsolutePath);
     return Files::getNormalizedPath($documentAbsolutePath) . $filename;
 }
 /**
  * Detects if the package contains a package file and returns the path and classname.
  *
  * @param string $packageKey The package key
  * @param string $absolutePackagePath Absolute path to the package
  * @return array The path to the package file and classname for this package or an empty array if none was found.
  * @throws Exception\CorruptPackageException
  * @throws InvalidPackagePathException
  */
 public function detectFlowPackageFilePath($packageKey, $absolutePackagePath)
 {
     if (!is_dir($absolutePackagePath)) {
         throw new InvalidPackagePathException(sprintf('The given package path "%s" is not a readable directory.', $absolutePackagePath), 1445904440);
     }
     $composerManifest = ComposerUtility::getComposerManifest($absolutePackagePath);
     if (!ComposerUtility::isFlowPackageType(isset($composerManifest['type']) ? $composerManifest['type'] : '')) {
         return [];
     }
     $possiblePackageClassPaths = [Files::concatenatePaths(['Classes', 'Package.php']), Files::concatenatePaths(['Classes', str_replace('.', '/', $packageKey), 'Package.php'])];
     $foundPackageClassPaths = array_filter($possiblePackageClassPaths, function ($packageClassPathAndFilename) use($absolutePackagePath) {
         $absolutePackageClassPath = Files::concatenatePaths([$absolutePackagePath, $packageClassPathAndFilename]);
         return is_file($absolutePackageClassPath);
     });
     if ($foundPackageClassPaths === []) {
         return [];
     }
     if (count($foundPackageClassPaths) > 1) {
         throw new Exception\CorruptPackageException(sprintf('The package "%s" contains multiple possible "Package.php" files. Please make sure that only one "Package.php" exists in the autoload root(s) of your Flow package.', $packageKey), 1457454840);
     }
     $packageClassPathAndFilename = reset($foundPackageClassPaths);
     $absolutePackageClassPath = Files::concatenatePaths([$absolutePackagePath, $packageClassPathAndFilename]);
     $packageClassContents = file_get_contents($absolutePackageClassPath);
     $packageClassName = (new PhpAnalyzer($packageClassContents))->extractFullyQualifiedClassName();
     if ($packageClassName === null) {
         throw new Exception\CorruptPackageException(sprintf('The package "%s" does not contain a valid package class. Check if the file "%s" really contains a class.', $packageKey, $packageClassPathAndFilename), 1327587091);
     }
     return ['className' => $packageClassName, 'pathAndFilename' => $packageClassPathAndFilename];
 }
 /**
  * Builds a temporary directory to work on.
  * @return void
  */
 protected function prepareTemporaryDirectory()
 {
     $this->temporaryDirectory = \TYPO3\Flow\Utility\Files::concatenatePaths(array(FLOW_PATH_DATA, 'Temporary', 'Testing', str_replace('\\', '_', __CLASS__)));
     if (!file_exists($this->temporaryDirectory)) {
         \TYPO3\Flow\Utility\Files::createDirectoryRecursively($this->temporaryDirectory);
     }
 }
示例#16
0
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $configurationFileExtension = isset($options['configurationFileExtension']) ? $options['configurationFileExtension'] : 'yaml';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath();
     if (!is_dir($configurationPath)) {
         return;
     }
     $commands = array();
     $configurationFiles = Files::readDirectoryRecursively($configurationPath, $configurationFileExtension);
     foreach ($configurationFiles as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         $escapedSourcePath = escapeshellarg($configuration);
         $escapedTargetPath = escapeshellarg(Files::concatenatePaths(array($targetReleasePath, 'Configuration', $targetConfigurationPath)) . '/');
         if ($node->isLocalhost()) {
             $commands[] = 'mkdir -p ' . $escapedTargetPath;
             $commands[] = 'cp ' . $escapedSourcePath . ' ' . $escapedTargetPath;
         } else {
             $username = isset($options['username']) ? $options['username'] . '@' : '';
             $hostname = $node->getHostname();
             $sshPort = isset($options['port']) ? '-p ' . escapeshellarg($options['port']) . ' ' : '';
             $scpPort = isset($options['port']) ? '-P ' . escapeshellarg($options['port']) . ' ' : '';
             $createDirectoryCommand = '"mkdir -p ' . $escapedTargetPath . '"';
             $commands[] = "ssh {$sshPort}{$username}{$hostname} {$createDirectoryCommand}";
             $commands[] = "scp {$scpPort}{$escapedSourcePath} {$username}{$hostname}:\"{$escapedTargetPath}\"";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
 /**
  * @param Thumbnail $thumbnail
  * @return void
  * @throws Exception\NoThumbnailAvailableException
  */
 public function refresh(Thumbnail $thumbnail)
 {
     $temporaryPathAndFilename = null;
     try {
         $filename = pathinfo($thumbnail->getOriginalAsset()->getResource()->getFilename(), PATHINFO_FILENAME);
         $temporaryLocalCopyFilename = $thumbnail->getOriginalAsset()->getResource()->createTemporaryLocalCopy();
         $temporaryPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('ProcessedFontThumbnail-') . '.' . $filename . '.jpg';
         $width = 1000;
         $height = 1000;
         $im = imagecreate($width, $height);
         $red = imagecolorallocate($im, 0xff, 0xff, 0xff);
         $black = imagecolorallocate($im, 0x0, 0x0, 0x0);
         imagefilledrectangle($im, 0, 0, 1000, 1000, $red);
         imagefttext($im, 48, 0, 80, 150, $black, $temporaryLocalCopyFilename, 'Neos Font Preview');
         imagefttext($im, 32, 0, 80, 280, $black, $temporaryLocalCopyFilename, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
         imagefttext($im, 32, 0, 80, 360, $black, $temporaryLocalCopyFilename, 'abcdefghijklmopqrstuvwxyz');
         imagefttext($im, 32, 0, 80, 440, $black, $temporaryLocalCopyFilename, '1234567890');
         imagefttext($im, 32, 0, 80, 560, $black, $temporaryLocalCopyFilename, '+ " * ç % & / ( ) = ? @ €');
         imagejpeg($im, $temporaryPathAndFilename);
         $resource = $this->resourceManager->importResource($temporaryPathAndFilename);
         $processedImageInfo = $this->resize($thumbnail, $resource);
         $thumbnail->setResource($processedImageInfo['resource']);
         $thumbnail->setWidth($processedImageInfo['width']);
         $thumbnail->setHeight($processedImageInfo['height']);
         Files::unlink($temporaryPathAndFilename);
     } catch (\Exception $exception) {
         Files::unlink($temporaryPathAndFilename);
         $filename = $thumbnail->getOriginalAsset()->getResource()->getFilename();
         $sha1 = $thumbnail->getOriginalAsset()->getResource()->getSha1();
         $message = sprintf('Unable to generate thumbnail for the given font (filename: %s, SHA1: %s)', $filename, $sha1);
         throw new Exception\NoThumbnailAvailableException($message, 1433109653, $exception);
     }
 }
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  * @return void
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $options['username'] = isset($options['username']) ? $options['username'] . '@' : '';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath() . '/';
     if (!is_dir($configurationPath)) {
         return;
     }
     $configurations = \TYPO3\Flow\Utility\Files::readDirectoryRecursively($configurationPath);
     $commands = array();
     foreach ($configurations as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         if ($node->isLocalhost()) {
             $commands[] = "mkdir -p '{$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "cp {$configuration} {$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         } else {
             $username = $options['username'];
             $hostname = $node->getHostname();
             $port = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';
             $commands[] = "ssh {$port} {$username}{$hostname} 'mkdir -p {$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "scp {$port} {$configuration} {$username}{$hostname}:{$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
示例#19
0
 /**
  * @param array $configuration
  */
 public function removeTemporaryConfigurationRootPath(array $configuration)
 {
     $configurationRootPath = $configuration['configurationRootPath'];
     $buildPath = $this->generateTemporaryConfigurationRootPath($configurationRootPath);
     if (@is_dir($buildPath)) {
         Files::removeDirectoryRecursively($buildPath);
     }
 }
 /**
  * @test
  */
 public function getLanguagesScansFormatDirectoryAndReturnsLanguagesAsStrings()
 {
     $formatPath = vfsStream::url('testDirectory') . '/';
     \TYPO3\Flow\Utility\Files::createDirectoryRecursively($formatPath . 'en');
     $format = new \TYPO3\Flow\Package\Documentation\Format('DocBook', $formatPath);
     $availableLanguages = $format->getAvailableLanguages();
     $this->assertEquals(array('en'), $availableLanguages);
 }
 /**
  * @test
  */
 public function modelIsReturnedCorrectlyForLocaleImplicatingChaining()
 {
     $localeImplementingChaining = new \TYPO3\Flow\I18n\Locale('de_DE');
     $cldrModel = $this->cldrRepository->getModelForLocale($localeImplementingChaining);
     $this->assertAttributeContains(\TYPO3\Flow\Utility\Files::concatenatePaths(array($this->cldrBasePath, 'main/root.xml')), 'sourcePaths', $cldrModel);
     $this->assertAttributeContains(\TYPO3\Flow\Utility\Files::concatenatePaths(array($this->cldrBasePath, 'main/de_DE.xml')), 'sourcePaths', $cldrModel);
     $this->assertAttributeContains(\TYPO3\Flow\Utility\Files::concatenatePaths(array($this->cldrBasePath, 'main/de.xml')), 'sourcePaths', $cldrModel);
 }
示例#22
0
 public function __construct()
 {
     parent::__construct();
     $this->dumpDirectory = FLOW_PATH_DATA . 'Persistent/GermaniaSacra/Dump/';
     if (!file_exists($this->dumpDirectory)) {
         Files::createDirectoryRecursively($this->dumpDirectory);
     }
 }
 /**
  * @test
  */
 public function importTemporaryFileSkipsFilesThatAlreadyExist()
 {
     $mockTempFile = vfsStream::newFile('SomeTemporaryFile', 0333)->withContent('fixture')->at($this->mockDirectory);
     $finalTargetPathAndFilename = $this->writableFileSystemStorage->_call('getStoragePathAndFilenameByHash', sha1('fixture'));
     Files::createDirectoryRecursively(dirname($finalTargetPathAndFilename));
     file_put_contents($finalTargetPathAndFilename, 'existing file');
     $this->writableFileSystemStorage->_call('importTemporaryFile', $mockTempFile->url(), 'default');
     $this->assertSame('existing file', file_get_contents($finalTargetPathAndFilename));
 }
 /**
  * @test
  */
 public function getDocumentationFormatsScansDocumentationDirectoryAndReturnsDocumentationFormatObjectsIndexedByFormatName()
 {
     $documentationPath = vfsStream::url('testDirectory') . '/';
     $mockPackage = $this->getMock(\TYPO3\Flow\Package\PackageInterface::class);
     \TYPO3\Flow\Utility\Files::createDirectoryRecursively($documentationPath . 'DocBook/en');
     $documentation = new \TYPO3\Flow\Package\Documentation($mockPackage, 'Manual', $documentationPath);
     $documentationFormats = $documentation->getDocumentationFormats();
     $this->assertEquals('DocBook', $documentationFormats['DocBook']->getFormatName());
 }
 /**
  * Sets the temporaryDirectory as static variable for the lock class.
  *
  * @throws LockNotAcquiredException
  * @throws \TYPO3\Flow\Utility\Exception
  * return void;
  */
 protected function configureTemporaryDirectory()
 {
     if (Bootstrap::$staticObjectManager === null || !Bootstrap::$staticObjectManager->isRegistered(\TYPO3\Flow\Utility\Environment::class)) {
         throw new LockNotAcquiredException('Environment object could not be accessed', 1386680952);
     }
     $environment = Bootstrap::$staticObjectManager->get('TYPO3\\Flow\\Utility\\Environment');
     $temporaryDirectory = Files::concatenatePaths([$environment->getPathToTemporaryDirectory(), 'Lock']);
     Files::createDirectoryRecursively($temporaryDirectory);
     self::$temporaryDirectory = $temporaryDirectory;
 }
 /**
  * @param string $file
  * @return string
  */
 protected function loadAndPrepareTypoScriptFromFile($file)
 {
     $content = Files::getFileContents($file) . chr(10);
     $content = preg_replace_callback('/include:[ ]?(.*)/', function ($match) use($file) {
         if (substr($match[1], 0, 11) === 'resource://') {
             return $match[0];
         }
         return 'include: ' . dirname($file) . '/' . $match[1];
     }, $content);
     return $content;
 }
 /**
  * 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, getcwd() . '/', false, true);
     }
     $defaultsPath = $installerResourcesDirectory . 'Distribution/Defaults';
     if (is_dir($defaultsPath)) {
         Files::copyDirectoryRecursively($defaultsPath, getcwd() . '/', true, true);
     }
 }
示例#28
0
 /**
  * @Given /^the recipient list is:$/
  */
 public function theRecipientListIs(TableNode $table)
 {
     $content = '';
     $receiverGroup = new \Sandstorm\Newsletter\Domain\Model\ReceiverSource();
     foreach ($table->getHash() as $row) {
         $content .= json_encode($row) . "\n";
     }
     Files::createDirectoryRecursively(dirname($receiverGroup->getCacheFileName()));
     file_put_contents($receiverGroup->getCacheFileName(), $content);
     $this->newsletter->setReceiverGroup($receiverGroup);
 }
示例#29
0
 /**
  * Resolve view object. Falls back to TYPO3.Ice package templates
  * if current package does not contain a template for current request.
  *
  * @return \TYPO3\Flow\Mvc\View\ViewInterface the resolved view
  */
 public function resolveView()
 {
     $view = parent::resolveView();
     if (!$view->canRender($this->controllerContext) && $this->request->getFormat() === 'html') {
         $templateFileName = \TYPO3\Flow\Utility\Files::concatenatePaths(array($this->packageManager->getPackage('TYPO3.Ice')->getPackagePath(), 'Resources', 'Private', 'Templates', 'Standard', 'Index.html'));
         // Fallback to TYPO3.Ice template if file exists
         if (file_exists($templateFileName)) {
             $view->setTemplatePathAndFilename($templateFileName);
         }
     }
     return $view;
 }
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @return void
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $this->hosting = $application->getOption('hosting');
     $this->username = $options['username'];
     $this->hostname = $node->getHostname();
     $this->deployment = $deployment;
     $this->resourcePath = $this->packageManager->getPackage('Famelo.Surf.SharedHosting')->getResourcesPath() . 'Private/' . $this->hosting;
     $this->temporaryPath = FLOW_PATH_ROOT . '/Data/Temporary/Deployment/' . $this->hosting;
     if (!is_dir($this->temporaryPath)) {
         \TYPO3\Flow\Utility\Files::createDirectoryRecursively($this->temporaryPath);
     }
 }