/**
  * @param array $module
  * @return void
  * @FLOW3\SkipCsrfProtection
  */
 public function indexAction(array $module)
 {
     $moduleRequest = new ActionRequest($this->request);
     $moduleRequest->setArgumentNamespace('moduleArguments');
     $moduleRequest->setControllerObjectName($module['controller']);
     $moduleRequest->setControllerActionName($module['action']);
     if ($this->request->hasArgument($moduleRequest->getArgumentNamespace()) === TRUE && is_array($this->request->getArgument($moduleRequest->getArgumentNamespace()))) {
         $moduleRequest->setArguments($this->request->getArgument($moduleRequest->getArgumentNamespace()));
     }
     foreach ($this->request->getPluginArguments() as $argumentNamespace => $argument) {
         $moduleRequest->setArgument('--' . $argumentNamespace, $argument);
     }
     $modules = explode('/', $module['module']);
     $moduleConfiguration = \TYPO3\FLOW3\Utility\Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $modules));
     $moduleConfiguration['path'] = $module['module'];
     $moduleBreadcrumb = array();
     $path = array();
     foreach ($modules as $moduleIdentifier) {
         array_push($path, $moduleIdentifier);
         $config = \TYPO3\FLOW3\Utility\Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $path));
         $moduleBreadcrumb[implode('/', $path)] = $config['label'];
     }
     $moduleRequest->setArgument('__moduleConfiguration', $moduleConfiguration);
     $moduleRequest->setArgument('__moduleBreadcrumb', $moduleBreadcrumb);
     $moduleResponse = new Response($this->response);
     $this->dispatcher->dispatch($moduleRequest, $moduleResponse);
     $this->view->assignMultiple(array('moduleClass' => implode('-', $modules), 'moduleContents' => $moduleResponse->getContent(), 'title' => $moduleRequest->hasArgument('title') ? $moduleRequest->getArgument('title') : $moduleConfiguration['label'], 'rootModule' => array_shift($modules), 'submodule' => array_shift($modules), 'moduleConfiguration' => $moduleConfiguration));
 }
 /**
  * Returns a fresh or existing instance of the object specified by $objectName.
  *
  * This specialized get() method is able to do setter injection for properties
  * defined in the object configuration of the specified object.
  *
  * @param string $objectName The name of the object to return an instance of
  * @return object The object instance
  * @throws \TYPO3\FLOW3\Object\Exception\CannotBuildObjectException
  * @throws \TYPO3\FLOW3\Object\Exception\UnresolvedDependenciesException
  * @throws \TYPO3\FLOW3\Object\Exception\UnknownObjectException
  */
 public function get($objectName)
 {
     if (isset($this->objects[$objectName]['i'])) {
         return $this->objects[$objectName]['i'];
     }
     if (isset($this->objectConfigurations[$objectName]) && count($this->objectConfigurations[$objectName]->getArguments()) > 0) {
         throw new Exception\CannotBuildObjectException('Cannot build object "' . $objectName . '" because constructor injection is not available in the compile time Object Manager. Refactor your code to use setter injection instead. Configuration source: ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . '. Build stack: ' . implode(', ', $this->objectNameBuildStack), 1297090026);
     }
     if (!isset($this->objects[$objectName])) {
         throw new Exception\UnknownObjectException('Cannot build object "' . $objectName . '" because it is unknown to the compile time Object Manager.', 1301477694);
     }
     if ($this->objects[$objectName]['s'] !== Configuration::SCOPE_SINGLETON) {
         throw new Exception\CannotBuildObjectException('Cannot build object "' . $objectName . '" because the get() method in the compile time Object Manager only supports singletons.', 1297090027);
     }
     $this->objectNameBuildStack[] = $objectName;
     $object = parent::get($objectName);
     foreach ($this->objectConfigurations[$objectName]->getProperties() as $propertyName => $property) {
         if ($property->getAutowiring() !== Configuration::AUTOWIRING_MODE_ON) {
             continue;
         }
         switch ($property->getType()) {
             case Property::PROPERTY_TYPES_STRAIGHTVALUE:
                 $value = $property->getValue();
                 break;
             case Property::PROPERTY_TYPES_SETTING:
                 $value = \TYPO3\FLOW3\Utility\Arrays::getValueByPath($this->allSettings, explode('.', $property->getValue()));
                 break;
             case Property::PROPERTY_TYPES_OBJECT:
                 $propertyObjectName = $property->getValue();
                 if (!is_string($propertyObjectName)) {
                     throw new Exception\CannotBuildObjectException('The object definition of "' . $objectName . '::' . $propertyName . '" is too complex for the compile time Object Manager. You can only use plain object names, not factories and the like. Check configuration in ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . ' and objects which depend on ' . $objectName . '.', 1297099659);
                 }
                 $value = $this->get($propertyObjectName);
                 break;
             default:
                 throw new Exception\CannotBuildObjectException('Invalid property type.', 1297090029);
                 break;
         }
         if (method_exists($object, $setterMethodName = 'inject' . ucfirst($propertyName))) {
             $object->{$setterMethodName}($value);
         } elseif (method_exists($object, $setterMethodName = 'set' . ucfirst($propertyName))) {
             $object->{$setterMethodName}($value);
         } else {
             throw new Exception\UnresolvedDependenciesException('Could not inject configured property "' . $propertyName . '" into "' . $objectName . '" because no injection method exists, but for compile time use this is required. Configuration source: ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . '.', 1297110953);
         }
     }
     $initializationLifecycleMethodName = $this->objectConfigurations[$objectName]->getLifecycleInitializationMethodName();
     if (method_exists($object, $initializationLifecycleMethodName)) {
         $object->{$initializationLifecycleMethodName}();
     }
     $shutdownLifecycleMethodName = $this->objectConfigurations[$objectName]->getLifecycleShutdownMethodName();
     if (method_exists($object, $shutdownLifecycleMethodName)) {
         $this->shutdownObjects[$object] = $shutdownLifecycleMethodName;
     }
     array_pop($this->objectNameBuildStack);
     return $object;
 }
Example #3
0
 /**
  * FIXME: Not yet completely refactored to new proxy mechanism
  *
  * @param array $argumentConfigurations
  * @return string
  */
 protected function buildMethodParametersCode(array $argumentConfigurations)
 {
     $preparedArguments = array();
     foreach ($argumentConfigurations as $argument) {
         if ($argument === NULL) {
             $preparedArguments[] = 'NULL';
         } else {
             $argumentValue = $argument->getValue();
             switch ($argument->getType()) {
                 case \TYPO3\FLOW3\Object\Configuration\ConfigurationArgument::ARGUMENT_TYPES_OBJECT:
                     if ($argumentValue instanceof \TYPO3\FLOW3\Object\Configuration\Configuration) {
                         $argumentValueObjectName = $argumentValue->getObjectName();
                         if ($this->objectConfigurations[$argumentValueObjectName]->getScope() === \TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_PROTOTYPE) {
                             $preparedArguments[] = '$this->getPrototype(\'' . $argumentValueObjectName . '\', array(' . $this->buildMethodParametersCode($argumentValue->getArguments(), $this->objectConfigurations) . '))';
                         } else {
                             $preparedArguments[] = '\\TYPO3\\FLOW3\\Core\\Bootstrap::$staticObjectManager->get(\'' . $argumentValueObjectName . '\')';
                         }
                     } else {
                         if (strpos($argumentValue, '.') !== FALSE) {
                             $settingPath = explode('.', $argumentValue);
                             $settings = Arrays::getValueByPath($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS), array_shift($settingPath));
                             $argumentValue = Arrays::getValueByPath($settings, $settingPath);
                         }
                         $preparedArguments[] = '\\TYPO3\\FLOW3\\Core\\Bootstrap::$staticObjectManager->get(\'' . $argumentValue . '\')';
                     }
                     break;
                 case \TYPO3\FLOW3\Object\Configuration\ConfigurationArgument::ARGUMENT_TYPES_STRAIGHTVALUE:
                     $preparedArguments[] = var_export($argumentValue, TRUE);
                     break;
                 case \TYPO3\FLOW3\Object\Configuration\ConfigurationArgument::ARGUMENT_TYPES_SETTING:
                     $preparedArguments[] = '\\TYPO3\\FLOW3\\Core\\Bootstrap::$staticObjectManager->getSettingsByPath(explode(\'.\', \'' . $argumentValue . '\'))';
                     break;
             }
         }
     }
     return implode(', ', $preparedArguments);
 }
Example #4
0
 /**
  * @test
  */
 public function getValueByPathReturnsNullIfThePathHasMoreSegmentsThanTheGivenArray()
 {
     $array = array('Foo' => array('Bar' => array('Baz' => 'the value')));
     $this->assertNULL(\TYPO3\FLOW3\Utility\Arrays::getValueByPath($array, array('Foo', 'Bar', 'Baz', 'Bux')));
 }
Example #5
0
 /**
  * Returns all parent roles for the given role, that are configured in the policy.
  *
  * @param \TYPO3\FLOW3\Security\Policy\Role $role The role to get the parents for
  * @return array<TYPO3\Security\Policy\Role> Array of parent roles
  */
 public function getAllParentRoles(\TYPO3\FLOW3\Security\Policy\Role $role)
 {
     $result = array();
     $parentRoles = \TYPO3\FLOW3\Utility\Arrays::getValueByPath($this->policy, 'roles.' . $role);
     if (is_array($parentRoles)) {
         foreach ($this->policy['roles'][(string) $role] as $currentIdentifier) {
             $currentParent = new \TYPO3\FLOW3\Security\Policy\Role($currentIdentifier);
             if (!in_array($currentParent, $result)) {
                 $result[] = $currentParent;
             }
             foreach ($this->getAllParentRoles($currentParent) as $currentGrandParent) {
                 if (!in_array($currentGrandParent, $result)) {
                     $result[] = $currentGrandParent;
                 }
             }
         }
     }
     return $result;
 }
 /**
  * Generate a schema for the given configuration or YAML file.
  *
  * ./flow3 configuration:generateschema --type Settings --path TYPO3.FLOW3.persistence
  *
  * The schema will be output to standard output.
  *
  * @param string $type Configuration type to create a schema for
  * @param string $path path to the subconfiguration separated by "." like "TYPO3.FLOW3"
  * @param string $yaml YAML file to create a schema for
  * @return void
  */
 public function generateSchemaCommand($type = NULL, $path = NULL, $yaml = NULL)
 {
     $data = NULL;
     if ($yaml !== NULL && is_file($yaml) && is_readable($yaml)) {
         $data = \Symfony\Component\Yaml\Yaml::parse($yaml);
     } elseif ($type !== NULL) {
         $data = $this->configurationManager->getConfiguration($type);
         if ($path !== NULL) {
             $data = \TYPO3\FLOW3\Utility\Arrays::getValueByPath($data, $path);
         }
     }
     if (empty($data)) {
         $this->outputLine('Data was not found or is empty');
         return;
     }
     $yaml = \Symfony\Component\Yaml\Yaml::dump($this->schemaGenerator->generate($data), 99);
     $this->output($yaml . chr(10));
 }
Example #7
0
 /**
  * Transforms the convoluted _FILES superglobal into a manageable form.
  *
  * @param array $convolutedFiles The _FILES superglobal
  * @return array Untangled files
  */
 protected function untangleFilesArray(array $convolutedFiles)
 {
     $untangledFiles = array();
     $fieldPaths = array();
     foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) {
         if (!is_array($fieldInformation['error'])) {
             $fieldPaths[] = array($firstLevelFieldName);
         } else {
             $newFieldPaths = $this->calculateFieldPaths($fieldInformation['error'], $firstLevelFieldName);
             array_walk($newFieldPaths, function (&$value, $key) {
                 $value = explode('/', $value);
             });
             $fieldPaths = array_merge($fieldPaths, $newFieldPaths);
         }
     }
     foreach ($fieldPaths as $fieldPath) {
         if (count($fieldPath) === 1) {
             $fileInformation = $convolutedFiles[$fieldPath[0]];
         } else {
             $fileInformation = array();
             foreach ($convolutedFiles[$fieldPath[0]] as $key => $subStructure) {
                 $fileInformation[$key] = Arrays::getValueByPath($subStructure, array_slice($fieldPath, 1));
             }
         }
         if (isset($fileInformation['error']) && $fileInformation['error'] !== \UPLOAD_ERR_NO_FILE) {
             $untangledFiles = Arrays::setValueByPath($untangledFiles, $fieldPath, $fileInformation);
         }
     }
     return $untangledFiles;
 }
Example #8
0
 /**
  * Invokes the Factory defined in the object configuration of the specified object in order
  * to build an instance. Arguments which were defined in the object configuration are
  * passed to the factory method.
  *
  * @param string $objectName Name of the object to build
  * @return object The built object
  */
 protected function buildObjectByFactory($objectName)
 {
     $factory = $this->get($this->objects[$objectName]['f'][0]);
     $factoryMethodName = $this->objects[$objectName]['f'][1];
     $factoryMethodArguments = array();
     foreach ($this->objects[$objectName]['fa'] as $index => $argumentInformation) {
         switch ($argumentInformation['t']) {
             case ObjectConfigurationArgument::ARGUMENT_TYPES_SETTING:
                 $settingPath = explode('.', $argumentInformation['v']);
                 $factoryMethodArguments[$index] = \TYPO3\FLOW3\Utility\Arrays::getValueByPath($this->allSettings, $settingPath);
                 break;
             case ObjectConfigurationArgument::ARGUMENT_TYPES_STRAIGHTVALUE:
                 $factoryMethodArguments[$index] = $argumentInformation['v'];
                 break;
             case ObjectConfigurationArgument::ARGUMENT_TYPES_OBJECT:
                 $factoryMethodArguments[$index] = $this->get($argumentInformation['v']);
                 break;
         }
     }
     if (count($factoryMethodArguments) === 0) {
         return $factory->{$factoryMethodName}();
     } else {
         return call_user_func_array(array($factory, $factoryMethodName), $factoryMethodArguments);
     }
 }
Example #9
0
 /**
  * Loads special configuration defined in the specified packages and merges them with
  * those potentially existing in the global configuration folders. The result is stored
  * in the configuration manager's configuration registry and can be retrieved with the
  * getConfiguration() method.
  *
  * @param string $configurationType The kind of configuration to load - must be one of the CONFIGURATION_TYPE_* constants
  * @param array $packages An array of Package objects (indexed by package key) to consider
  * @return void
  * @throws \TYPO3\FLOW3\Configuration\Exception\InvalidConfigurationTypeException
  */
 protected function loadConfiguration($configurationType, array $packages)
 {
     $this->cacheNeedsUpdate = TRUE;
     switch ($configurationType) {
         case self::CONFIGURATION_TYPE_SETTINGS:
             // Make sure that the FLOW3 package is the first item of the packages array:
             if (isset($packages['TYPO3.FLOW3'])) {
                 $flow3Package = $packages['TYPO3.FLOW3'];
                 unset($packages['TYPO3.FLOW3']);
                 $packages = array_merge(array('TYPO3.FLOW3' => $flow3Package), $packages);
                 unset($flow3Package);
             }
             $settings = array();
             foreach ($packages as $packageKey => $package) {
                 if (Arrays::getValueByPath($settings, $packageKey) === NULL) {
                     $settings = Arrays::setValueByPath($settings, $packageKey, array());
                 }
                 $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load($package->getConfigurationPath() . self::CONFIGURATION_TYPE_SETTINGS));
             }
             $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . self::CONFIGURATION_TYPE_SETTINGS));
             foreach ($this->orderedListOfContextNames as $contextName) {
                 foreach ($packages as $package) {
                     $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . self::CONFIGURATION_TYPE_SETTINGS));
                 }
                 $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $contextName . '/' . self::CONFIGURATION_TYPE_SETTINGS));
             }
             if ($this->configurations[self::CONFIGURATION_TYPE_SETTINGS] !== array()) {
                 $this->configurations[self::CONFIGURATION_TYPE_SETTINGS] = Arrays::arrayMergeRecursiveOverrule($this->configurations[self::CONFIGURATION_TYPE_SETTINGS], $settings);
             } else {
                 $this->configurations[self::CONFIGURATION_TYPE_SETTINGS] = $settings;
             }
             $this->configurations[self::CONFIGURATION_TYPE_SETTINGS]['TYPO3']['FLOW3']['core']['context'] = (string) $this->context;
             break;
         case self::CONFIGURATION_TYPE_OBJECTS:
             $this->configurations[$configurationType] = array();
             foreach ($packages as $packageKey => $package) {
                 $configuration = $this->configurationSource->load($package->getConfigurationPath() . $configurationType);
                 $configuration = Arrays::arrayMergeRecursiveOverrule($configuration, $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $configurationType));
                 foreach ($this->orderedListOfContextNames as $contextName) {
                     $configuration = Arrays::arrayMergeRecursiveOverrule($configuration, $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType));
                     $configuration = Arrays::arrayMergeRecursiveOverrule($configuration, $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $contextName . '/' . $configurationType));
                 }
                 $this->configurations[$configurationType][$packageKey] = $configuration;
             }
             break;
         case self::CONFIGURATION_TYPE_CACHES:
         case self::CONFIGURATION_TYPE_POLICY:
             $this->configurations[$configurationType] = array();
             foreach ($packages as $package) {
                 $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load($package->getConfigurationPath() . $configurationType));
             }
             $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $configurationType));
             foreach ($this->orderedListOfContextNames as $contextName) {
                 foreach ($packages as $package) {
                     $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType));
                 }
                 $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $contextName . '/' . $configurationType));
             }
             break;
         case self::CONFIGURATION_TYPE_ROUTES:
             // load subroutes
             $subRoutesConfiguration = array();
             foreach ($packages as $packageKey => $package) {
                 $subRoutesConfiguration[$packageKey] = array();
                 foreach (array_reverse($this->orderedListOfContextNames) as $contextName) {
                     $subRoutesConfiguration[$packageKey] = array_merge($subRoutesConfiguration[$packageKey], $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType));
                 }
                 $subRoutesConfiguration[$packageKey] = array_merge($subRoutesConfiguration[$packageKey], $this->configurationSource->load($package->getConfigurationPath() . $configurationType));
             }
             // load main routes
             $this->configurations[self::CONFIGURATION_TYPE_ROUTES] = array();
             foreach (array_reverse($this->orderedListOfContextNames) as $contextName) {
                 $this->configurations[self::CONFIGURATION_TYPE_ROUTES] = array_merge($this->configurations[self::CONFIGURATION_TYPE_ROUTES], $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $contextName . '/' . $configurationType));
             }
             $this->configurations[self::CONFIGURATION_TYPE_ROUTES] = array_merge($this->configurations[self::CONFIGURATION_TYPE_ROUTES], $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $configurationType));
             // Merge routes with subroutes
             $this->mergeRoutesWithSubRoutes($this->configurations[$configurationType], $subRoutesConfiguration);
             break;
         default:
             throw new \TYPO3\FLOW3\Configuration\Exception\InvalidConfigurationTypeException('Configuration type "' . $configurationType . '" cannot be loaded with loadConfiguration().', 1251450613);
     }
     $this->postProcessConfiguration($this->configurations[$configurationType]);
 }