/**
  * Processes the FLOW3 configuration code by calling the respective helper methods.
  *
  * @param array $replacePairs an array containing strings to be replaced. Key = search string, value = replacement string.
  * @param array $fileSpecificReplacePairs an array containing strings to be replaced. Key = search string, value = replacement string.
  * @param array $unusedReplacePairs an array which should be initialized to the same value as $replacePairs. After calling processCode(), it contains only the $replacePairs which were not used during the replacement.
  * @param array $unusedFileSpecificReplacePairs an array which should be initialized to the same value as $fileSpecificReplacePairs. After calling processCode(), it contains only the $fileSpecificReplacePairs which were not used during the replacement.
  * @return string the processed code
  * @author Bernhard Schmitt <*****@*****.**>
  */
 function processCode(array $replacePairs, array $fileSpecificReplacePairs, array &$unusedReplacePairs, array &$unusedFileSpecificReplacePairs)
 {
     $this->replaceStrings($replacePairs, $fileSpecificReplacePairs, $unusedReplacePairs, $unusedFileSpecificReplacePairs);
     $this->transformClassName();
     $this->transformObjectNames();
     $this->processedClassCode = str_replace(array('TYPO3.Form:', 'TYPO3.FLOW3:'), array('Tx_' . \TYPO3\FormBackporter\Utility\Extension::extKeyToName($this->extensionKey) . '_', ''), $this->processedClassCode);
     $configurationPrefix = 'plugin.tx_' . str_replace('_', '', $this->extensionKey);
     $configurationArray = \Symfony\Component\Yaml\Yaml::parse($this->processedClassCode);
     $configurationArray = array($configurationPrefix => array('settings' => $configurationArray['TYPO3']['Form']));
     unset($configurationArray[$configurationPrefix]['settings']['presets']['default']['validatorPresets']['TYPO3.FLOW3:Count']);
     $this->processedClassCode = \TYPO3\FormBackporter\Utility\TypoScript::writeString($configurationArray);
     return $this->processedClassCode;
 }
Exemplo n.º 2
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')));
    }
    /**
     * @return void
     */
    protected function processClassFiles()
    {
        $this->backporter->setCodeProcessorClassName('TYPO3\\FormBackporter\\CodeProcessor\\FormClassCodeProcessor');
        $replacePairs = array_merge($this->createClassNameReplacePairs(array('AbstractFormFactory' => $this->getClassPrefix() . 'Factory_AbstractFormFactory', 'AbstractRenderable' => $this->getClassPrefix() . 'Core_Model_Renderable_AbstractRenderable', 'AbstractSection' => $this->getClassPrefix() . 'Core_Model_AbstractSection', 'ActionRequest' => 'Tx_Extbase_MVC_Request', 'CompositeRenderableInterface' => $this->getClassPrefix() . 'Core_Model_Renderable_CompositeRenderableInterface', 'FinisherContext' => $this->getClassPrefix() . 'Core_Model_FinisherContext', 'FinisherInterface' => $this->getClassPrefix() . 'Core_Model_FinisherInterface', 'FormDefinition' => $this->getClassPrefix() . 'Core_Model_FormDefinition', 'FormElementInterface' => $this->getClassPrefix() . 'Core_Model_FormElementInterface', 'FormFactoryInterface' => $this->getClassPrefix() . 'Factory_FormFactoryInterface', 'FormPersistenceManagerInterface' => $this->getClassPrefix() . 'Persistence_FormPersistenceManagerInterface', 'FormRuntime' => $this->getClassPrefix() . 'Core_Runtime_FormRuntime', 'FormState' => $this->getClassPrefix() . 'Core_Runtime_FormState', 'GenericFormElement' => $this->getClassPrefix() . 'FormElements_GenericFormElement', 'Page' => $this->getClassPrefix() . 'Core_Model_Page', 'ProcessingRule' => $this->getClassPrefix() . 'Core_Model_ProcessingRule', 'Renderable\\AbstractCompositeRenderable' => $this->getClassPrefix() . 'Core_Model_Renderable_AbstractCompositeRenderable', 'Renderable\\AbstractRenderable' => $this->getClassPrefix() . 'Core_Model_Renderable_AbstractRenderable', 'Renderable\\RenderableInterface' => $this->getClassPrefix() . 'Core_Model_Renderable_RenderableInterface', 'Renderable\\CompositeRenderableInterface' => $this->getClassPrefix() . 'Core_Model_Renderable_CompositeRenderableInterface', 'RenderableInterface' => $this->getClassPrefix() . 'Core_Model_Renderable_RenderableInterface', 'RendererInterface' => $this->getClassPrefix() . 'Core_Renderer_RendererInterface', 'RootRenderableInterface' => $this->getClassPrefix() . 'Core_Model_Renderable_RootRenderableInterface', 'SupertypeResolver' => $this->getClassPrefix() . 'Utility_SupertypeResolver')), array('\\TYPO3\\FLOW3\\Cache\\Frontend\\PhpFrontend' => 't3lib_cache_frontend_PhpFrontend', '\\TYPO3\\Fluid\\Core\\ViewHelper\\AbstractViewHelper' => 'Tx_Fluid_Core_ViewHelper_AbstractViewHelper', 'TYPO3\\Fluid\\Core\\Parser\\Interceptor\\Escape' => 'Tx_Fluid_Core_Parser_Interceptor_Escape', '\\TYPO3\\FLOW3\\Configuration\\ConfigurationManager' => 'Tx_Extbase_Configuration_ConfigurationManager', '\\TYPO3\\FLOW3\\Exception' => 'Tx_Extbase_Exception', '\\TYPO3\\FLOW3\\Http\\Response' => 'Tx_Extbase_MVC_Response', '\\TYPO3\\FLOW3\\Mvc\\ActionRequest' => 'Tx_Extbase_MVC_Request', 'TYPO3\\FLOW3\\Mvc\\Controller\\ControllerContext' => 'Tx_Extbase_MVC_Controller_ControllerContext', 'TYPO3\\FLOW3\\Mvc\\View\\ViewInterface' => 'Tx_Extbase_MVC_View_ViewInterface', 'TYPO3\\FLOW3\\Mvc\\Web\\Request' => 'Tx_Extbase_MVC_Web_Request', 'TYPO3\\FLOW3\\Mvc\\Web\\Routing\\UriBuilder' => 'Tx_Extbase_MVC_Web_Routing_UriBuilder', 'TYPO3\\FLOW3\\Object\\ObjectManagerInterface' => 'Tx_Extbase_Object_ObjectManagerInterface', 'TYPO3\\FLOW3\\Persistence\\PersistenceManagerInterface' => 'Tx_Extbase_Persistence_ManagerInterface', 'TYPO3\\FLOW3\\Reflection\\ClassReflection' => 'Tx_Extbase_Reflection_ClassReflection', 'TYPO3\\FLOW3\\Reflection\\ObjectAccess' => 'Tx_Extbase_Reflection_ObjectAccess', 'TYPO3\\FLOW3\\Reflection\\ReflectionService' => 'Tx_Extbase_Reflection_Service', 'TYPO3\\FLOW3\\Tests\\UnitTestCase' => 'Tx_Extbase_Tests_Unit_BaseTestCase', '\\TYPO3\\FLOW3\\Utility\\Arrays' => 'Tx_Extbase_Utility_Arrays', '\\TYPO3\\FLOW3\\var_dump' => 'Tx_Extbase_Utility_Debugger::var_dump', '\\TYPO3\\FLOW3\\Validation\\Validator\\AbstractValidator' => 'Tx_Extbase_Validation_Validator_AbstractValidator', '\\TYPO3\\Fluid\\ViewHelpers\\Form\\AbstractFormFieldViewHelper' => 'Tx_Fluid_ViewHelpers_Form_AbstractFormFieldViewHelper', '\\TYPO3\\Fluid\\ViewHelpers\\FormViewHelper' => 'Tx_Fluid_ViewHelpers_FormViewHelper', '\\TYPO3\\SwiftMailer\\Message' => 't3lib_mail_Message', '\\TYPO3\\Fluid\\View\\TemplateView' => 'Tx_Fluid_View_TemplateView', '\\TYPO3\\FLOW3\\Mvc\\Controller\\Arguments' => 'Tx_Extbase_MVC_Controller_Arguments', '\\TYPO3\\FLOW3\\Mvc\\Routing\\UriBuilder' => 'Tx_Extbase_MVC_Web_Routing_UriBuilder', '\\TYPO3\\Fluid\\Core\\Parser\\Configuration' => 'Tx_Fluid_Core_Parser_Configuration', '\\TYPO3\\Fluid\\Core\\Parser\\Interceptor\\Escape' => 'Tx_Fluid_Core_Parser_Interceptor_Escape', '\\TYPO3\\FLOW3\\Security\\Cryptography\\HashService' => 'Tx_Extbase_Security_Cryptography_HashService', '\\TYPO3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer' => 'Tx_Fluid_Core_ViewHelper_TemplateVariableContainer', '\\TYPO3\\FLOW3\\Mvc\\FlashMessageContainer' => 'Tx_Extbase_MVC_Controller_FlashMessages', '\\TYPO3\\FLOW3\\Property\\PropertyMappingConfiguration' => 'Tx_Extbase_Property_PropertyMappingConfiguration', '\\TYPO3\\FLOW3\\Validation\\Validator\\ConjunctionValidator' => 'Tx_Extbase_Validation_Validator_ConjunctionValidator', '\\TYPO3\\FLOW3\\Property\\PropertyMapper' => 'Tx_Extbase_Property_PropertyMapper', '\\TYPO3\\FLOW3\\Validation\\Validator\\ValidatorInterface' => 'Tx_Extbase_Validation_Validator_ValidatorInterface', '\\TYPO3\\Fluid\\View\\Exception\\InvalidTemplateResourceException' => 'Tx_Fluid_View_Exception_InvalidTemplateResourceException', '\\TYPO3\\Fluid\\Core\\ViewHelper\\TagBuilder' => 'Tx_Fluid_Core_ViewHelper_TagBuilder', '\\TYPO3\\FLOW3\\Validation\\Validator\\ValidatorInterface' => 'Tx_Extbase_Validation_Validator_ValidatorInterface', '\\TYPO3\\FLOW3\\Error\\Result' => 'Tx_Extbase_Error_Result', '\\TYPO3\\FLOW3\\Validation\\Validator\\NotEmptyValidator' => 'Tx_Extbase_Validation_Validator_NotEmptyValidator', 'UUID' => 'UID', '$this->persistenceManager->getIdentifierByObject' => '$this->persistenceManager->getBackend()->getIdentifierByObject', '$this->persistenceManager->isNewObject(' => '$this->persistenceManager->getBackend()->isNewObject(', 'new \\SplObjectStorage()' => 't3lib_div::makeInstance(\'Tx_Extbase_Persistence_ObjectStorage\')', '\\SplObjectStorage' => 'Tx_Extbase_Persistence_ObjectStorage', '* @FLOW3\\Internal' => '* @internal', '* This script belongs to the FLOW3 package "TYPO3.Form".' => '* This script is backported from the FLOW3 package "TYPO3.Form".', '* @FLOW3\\Inject' => '* @inject', 'TYPO3.Form:' => $this->getClassPrefix()));
        $this->backporter->setReplacePairs($replacePairs);
        $this->backporter->setIncludeFilePatterns(array('#^Classes/.*$#', '#^Resources/.*$#', '#^Tests/.*$#'));
        $this->backporter->setExcludeFilePatterns(array('#^Classes/Package.php$#'));
        $this->backporter->setFileSpecificReplacePairs(array('Classes/ViewHelpers/RenderViewHelper.php' => array('\\TYPO3\\Form\\Persistence\\FormPersistenceManagerInterface' => $this->getClassPrefix() . 'Persistence_YamlPersistenceManager', '// TOKEN-1' => '/**
	 * @inject
	 * @var Tx_Extbase_Object_ObjectManager
	 */
	protected $objectManager;'), 'Classes/ViewHelpers/FormViewHelper.php' => array('return \'\'' => 'return $this->renderingContext->getTemplateVariableContainer()->get(\'form\')->getIdentifier();'), 'Classes/Factory/AbstractFormFactory.php' => array('$this->formSettings = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, \'TYPO3.Form\');' => '$this->formSettings = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, \'' . \TYPO3\FormBackporter\Utility\Extension::extKeyToName($this->extensionKey) . '\', \'Pi1\');'), 'Classes/Core/Model/FormDefinition.php' => array('* @param Page $page' => '* @param ' . $this->getClassPrefix() . 'Core_Model_Page $page', 'public function addPage(Page $page) {' => 'public function addPage(' . $this->getClassPrefix() . 'Core_Model_Page $page) {', 'return new \\TYPO3\\Form\\Core\\Runtime\\FormRuntime($this, $request, $response);' => '$runtime = $this->objectManager->create(\'' . $this->getClassPrefix() . 'Core_Runtime_FormRuntime\', $this, $request, $response);
		$runtime->initializeObject();
		return $runtime;'), 'Classes/Core/Renderer/FluidFormRenderer.php' => array('list($packageKey, $shortRenderableType) = explode(\':\', $renderableType);

		return strtr($renderingOptions[\'templatePathPattern\'], array(
			\'{@package}\' => $packageKey,
			\'{@type}\' => $shortRenderableType
		));' => '$shortRenderableType = str_replace(\'' . $this->getClassPrefix() . '\', \'\', $renderableType);

		return strtr($renderingOptions[\'templatePathPattern\'], array(
			\'EXT:\' => \'typo3conf/ext/\',
			\'{@type}\' => $shortRenderableType
		));', '// TOKEN-1' => 'public function __construct() {
		parent::__construct();
		$this->injectTemplateCompiler($this->objectManager->get(\'Tx_Fluid_Core_Compiler_TemplateCompiler\'));
	}'), 'Classes/Core/Runtime/Formstate.php' => array('return \\TYPO3\\FLOW3\\Utility\\Arrays::getValueByPath($this->formValues, $propertyPath);' => 'return Tx_Extbase_Utility_Arrays::getValueByPath($this->formValues, array($propertyPath));'), 'Classes/Core/Runtime/FormRuntime' => array('protected function getControllerContext() {
		$uriBuilder = new \\TYPO3\\FLOW3\\Mvc\\Routing\\UriBuilder();
		$uriBuilder->setRequest($this->request);

		return new \\TYPO3\\FLOW3\\Mvc\\Controller\\ControllerContext(
			$this->request,
			$this->response,
			new \\TYPO3\\FLOW3\\Mvc\\Controller\\Arguments(array()),
			$uriBuilder,
			$this->flashMessageContainer
		);
	}' => 'protected function getControllerContext() {
		$uriBuilder = t3lib_div::makeInstance(\'Tx_Extbase_MVC_Web_Routing_UriBuilder\');
		$uriBuilder->setRequest($this->request);
		$uriBuilder->injectExtensionService(t3lib_div::makeInstance(\'Tx_Extbase_Service_ExtensionService\'));
		$uriBuilder->injectConfigurationManager(t3lib_div::makeInstance(\'Tx_Extbase_Configuration_ConfigurationManager\'));
		$uriBuilder->initializeObject();

		$controllerContext = new Tx_Extbase_MVC_Controller_ControllerContext();
		$controllerContext->setRequest($this->request);
		$controllerContext->setResponse($this->response);
		$controllerContext->setArguments(new Tx_Extbase_MVC_Controller_Arguments(array()));
		$controllerContext->setUriBuilder($uriBuilder);
		$controllerContext->setFlashMessageContainer(t3lib_div::makeInstance(\'Tx_Extbase_MVC_Controller_FlashMessages\'));
		return $controllerContext;
	}', '$value = \\TYPO3\\FLOW3\\Utility\\Arrays::getValueByPath($requestArguments, $element->getIdentifier());' => '$value = Tx_Extbase_Utility_Arrays::getValueByPath($requestArguments, array($element->getIdentifier()));')));
        $this->backporter->processFiles($this->packageManager->getPackage('TYPO3.Form')->getPackagePath(), $this->settings['targetPath']);
    }