/** * Builds a web request object from the raw HTTP information * * @return \F3\FLOW3\MVC\Web\Request The web request as an object * @author Robert Lemke <*****@*****.**> * @author Bastian Waidelich <*****@*****.**> */ public function build() { $request = $this->objectFactory->create('F3\\FLOW3\\MVC\\Web\\Request'); $request->injectEnvironment($this->environment); $request->setRequestUri($this->environment->getRequestUri()); $request->setMethod($this->environment->getRequestMethod()); $this->setArgumentsFromRawRequestData($request); $routesConfiguration = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_ROUTES); $this->router->setRoutesConfiguration($routesConfiguration); $this->router->route($request); return $request; }
/** * Activates a package * * @param string $packageKey The package to activate * @throws \F3\FLOW3\Package\Exception\InvalidPackageStateException If the specified package is already active * @author Thomas Hempel <*****@*****.**> * @author Christopher Hlubek <*****@*****.**> * @api */ public function activatePackage($packageKey) { if (!$this->isPackageActive($packageKey)) { $package = $this->getPackage($packageKey); $this->activePackages[$packageKey] = $package; $packageStatesConfiguration = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_PACKAGESTATES); $packageStatesConfiguration[$packageKey]['state'] = 'active'; $packageStatesConfiguration = $this->configurationManager->setConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_PACKAGESTATES, $packageStatesConfiguration); $this->configurationManager->saveConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_PACKAGESTATES); } else { throw new \F3\FLOW3\Package\Exception\InvalidPackageStateException('Package "' . $packageKey . '" is already active.', 1244620776); } }
/** * Initializes the cache framework * * @return void * @author Robert Lemke <*****@*****.**> * @see initialize() */ public function initializeCache() { $this->cacheManager = $this->objectManager->getObject('F3\\FLOW3\\Cache\\CacheManager'); $this->cacheManager->setCacheConfigurations($this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_CACHES)); $this->cacheManager->initialize(); $cacheFactory = $this->objectManager->getObject('F3\\FLOW3\\Cache\\CacheFactory'); $cacheFactory->setCacheManager($this->cacheManager); $coreCache = $this->cacheManager->getCache('FLOW3_Core'); $cachedRevision = $coreCache->has('revision') ? $coreCache->get('revision') : NULL; $currentRevision = $this->packageManager->getPackage('FLOW3')->getPackageMetaData()->getVersion() . ' (r' . substr(self::REVISION, 11, -2) . ')'; if ($cachedRevision !== $currentRevision) { $this->systemLogger->log('The caches are based on FLOW3 ' . $cachedRevision . ' not matching ' . $currentRevision . ', therefore flushing all caches.', LOG_NOTICE); $this->cacheManager->flushCaches(); $coreCache->set('revision', $currentRevision); } }
/** * Checks, resolves and injects dependencies as properties through calling the setter methods or setting * properties directly through reflection. * * @param array $properties Array of \F3\FLOW3\Object\Configuration\ConfigurationProperty for the current object * @param object $object The recently created instance of the current object. Dependencies will be injected to it. * @return void * @author Robert Lemke <*****@*****.**> */ protected function injectProperties($properties, $object) { foreach ($properties as $propertyName => $property) { $propertyValue = $property->getValue(); switch ($property->getType()) { case \F3\FLOW3\Object\Configuration\ConfigurationProperty::PROPERTY_TYPES_OBJECT: if ($propertyValue instanceof \F3\FLOW3\Object\Configuration\Configuration) { $preparedValue = $this->createObject($propertyValue->getObjectName(), $propertyValue); } else { if (strpos($propertyValue, '.') !== FALSE) { $settingPath = explode('.', $propertyValue); $settings = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, array_shift($settingPath)); $propertyValue = \F3\FLOW3\Utility\Arrays::getValueByPath($settings, $settingPath); } $preparedValue = $this->objectManager->getObject($propertyValue); } break; case \F3\FLOW3\Object\Configuration\ConfigurationProperty::PROPERTY_TYPES_STRAIGHTVALUE: $preparedValue = $propertyValue; break; case \F3\FLOW3\Object\Configuration\ConfigurationProperty::PROPERTY_TYPES_SETTING: if (strpos($propertyValue, '.') !== FALSE) { $settingPath = explode('.', $propertyValue); $settings = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, array_shift($settingPath)); $preparedValue = \F3\FLOW3\Utility\Arrays::getValueByPath($settings, $settingPath); } else { $preparedValue = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $propertyValue); } break; } $setterMethodName = 'inject' . ucfirst($propertyName); if (method_exists($object, $setterMethodName)) { $object->{$setterMethodName}($preparedValue); continue; } $setterMethodName = 'set' . ucfirst($propertyName); if (method_exists($object, $setterMethodName)) { $object->{$setterMethodName}($preparedValue); continue; } if (property_exists($object, $propertyName)) { $propertyReflection = new \ReflectionProperty($object, $propertyName); $propertyReflection->setAccessible(TRUE); $propertyReflection->setValue($object, $preparedValue); } } }
/** * Traverses through all active packages and registers their classes as * objects at the object manager. Finally the object configuration * defined by the package is loaded and applied to the registered objects. * * @param array $packages The packages whose classes should be registered * @return void * @author Robert Lemke <*****@*****.**> */ protected function registerAndConfigureAllPackageObjects(array $packages) { $objectTypes = array(); $availableClassNames = array(); foreach ($packages as $packageKey => $package) { foreach (array_keys($package->getClassFiles()) as $className) { if (!$this->classNameIsBlacklisted($className)) { $availableClassNames[] = $className; } } } foreach ($availableClassNames as $className) { if (substr($className, -9, 9) === 'Interface') { $objectTypes[] = $className; if (!isset($this->registeredObjects[$className])) { $this->registerObjectType($className); } } else { if (!isset($this->registeredObjects[$className])) { if (!$this->reflectionService->isClassAbstract($className)) { $this->registerObject($className, $className); } } } } foreach (array_keys($packages) as $packageKey) { $rawObjectConfigurations = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_OBJECTS, $packageKey); foreach ($rawObjectConfigurations as $objectName => $rawObjectConfiguration) { $objectName = str_replace('_', '\\', $objectName); if (!isset($this->registeredObjects[$objectName])) { throw new \F3\FLOW3\Object\Exception\InvalidObjectConfigurationException('Tried to configure unknown object "' . $objectName . '" in package "' . $packageKey . '".', 1184926175); } if (is_array($rawObjectConfiguration)) { $existingObjectConfiguration = isset($this->objectConfigurations[$objectName]) ? $this->objectConfigurations[$objectName] : NULL; $this->objectConfigurations[$objectName] = \F3\FLOW3\Object\Configuration\ConfigurationBuilder::buildFromConfigurationArray($objectName, $rawObjectConfiguration, 'Package ' . $packageKey, $existingObjectConfiguration); } } } }