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); }
/** * 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'))); }
/** * Returns a key by its name * * @param string $name * @return boolean * @throws \TYPO3\FLOW3\Security\Exception */ public function getKey($name) { if (strlen($name) === 0) { throw new \TYPO3\FLOW3\Security\Exception('Required name argument was empty', 1334215378); } $keyPathAndFilename = $this->getKeyPathAndFilename($name); if (!file_exists($keyPathAndFilename)) { throw new \TYPO3\FLOW3\Security\Exception(sprintf('The key "%s" does not exist.', $keyPathAndFilename), 1305812921); } $key = Files::getFileContents($keyPathAndFilename); if ($key === FALSE) { throw new \TYPO3\FLOW3\Security\Exception(sprintf('The key "%s" could not be read.', $keyPathAndFilename), 1334483163); } if (strlen($key) === 0) { throw new \TYPO3\FLOW3\Security\Exception(sprintf('The key "%s" is empty.', $keyPathAndFilename), 1334483165); } return $key; }
/** * Create a package, given the package key * * @param string $packageKey The package key of the new package * @param \TYPO3\FLOW3\Package\MetaData $packageMetaData If specified, this package meta object is used for writing the Package.xml file, otherwise a rudimentary Package.xml file is created * @param string $packagesPath If specified, the package will be created in this path, otherwise the default "Application" directory is used * @return \TYPO3\FLOW3\Package\Package\PackageInterface The newly created package * @throws \TYPO3\FLOW3\Package\Exception * @throws \TYPO3\FLOW3\Package\Exception\PackageKeyAlreadyExistsException * @throws \TYPO3\FLOW3\Package\Exception\InvalidPackageKeyException * @api */ public function createPackage($packageKey, \TYPO3\FLOW3\Package\MetaData $packageMetaData = NULL, $packagesPath = '') { if (!$this->isPackageKeyValid($packageKey)) { throw new \TYPO3\FLOW3\Package\Exception\InvalidPackageKeyException('The package key "' . $packageKey . '" is invalid', 1220722210); } if ($this->isPackageAvailable($packageKey)) { throw new \TYPO3\FLOW3\Package\Exception\PackageKeyAlreadyExistsException('The package key "' . $packageKey . '" already exists', 1220722873); } if ($packageMetaData === NULL) { $packageMetaData = new \TYPO3\FLOW3\Package\MetaData($packageKey); } if ($packagesPath === '') { $packagesPath = Files::getUnixStylePath(Files::concatenatePaths(array($this->packagesBasePath, 'Application'))); } $packagePath = Files::concatenatePaths(array($packagesPath, $packageKey)) . '/'; Files::createDirectoryRecursively($packagePath); foreach (array(PackageInterface::DIRECTORY_METADATA, PackageInterface::DIRECTORY_CLASSES, PackageInterface::DIRECTORY_CONFIGURATION, PackageInterface::DIRECTORY_DOCUMENTATION, PackageInterface::DIRECTORY_RESOURCES, PackageInterface::DIRECTORY_TESTS_UNIT, PackageInterface::DIRECTORY_TESTS_FUNCTIONAL) as $path) { Files::createDirectoryRecursively(Files::concatenatePaths(array($packagePath, $path))); } $package = new Package($packageKey, $packagePath); $result = PackageMetaDataWriter::writePackageMetaData($package, $packageMetaData); if ($result === FALSE) { throw new \TYPO3\FLOW3\Package\Exception('Error while writing the package meta data information at "' . $packagePath . '"', 1232625240); } $packageNamespace = str_replace('.', '\\', $packageKey); $packagePhpSource = str_replace('{packageKey}', $packageKey, Files::getFileContents($this->packageClassTemplateUri)); $packagePhpSource = str_replace('{packageNamespace}', $packageNamespace, $packagePhpSource); file_put_contents($package->getClassesPath() . 'Package.php', $packagePhpSource); $this->packages[$packageKey] = $package; foreach (array_keys($this->packages) as $upperCamelCasedPackageKey) { $this->packageKeys[strtolower($upperCamelCasedPackageKey)] = $upperCamelCasedPackageKey; } $this->activatePackage($packageKey); return $package; }
/** * Reads the TypoScript file from the given path and filename. * If it doesn't exist, this function will just return an empty string. * * @param string $pathAndFilename Path and filename of the TypoScript file * @return string The content of the .ts2 file, plus one chr(10) at the end */ protected function readExternalTypoScriptFile($pathAndFilename) { return file_exists($pathAndFilename) ? Files::getFileContents($pathAndFilename) . chr(10) : ''; }