/**
  * Sets up a request builder for testing
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 protected function setUpRequestBuilder()
 {
     $this->mockRequestUri = $this->getMock('F3\\FLOW3\\Property\\DataType\\Uri', array(), array(), '', FALSE);
     $this->mockRequestUri->expects($this->once())->method('getArguments')->will($this->returnValue(array('someArgument' => 'GETArgument')));
     $this->mockEnvironment = $this->getMock('F3\\FLOW3\\Utility\\Environment', array(), array(), '', FALSE);
     $this->mockEnvironment->expects($this->any())->method('getRequestUri')->will($this->returnValue($this->mockRequestUri));
     $this->mockRequest = $this->getMock('F3\\FLOW3\\MVC\\Web\\Request', array(), array(), '', FALSE);
     $this->mockRequest->expects($this->any())->method('getRequestUri')->will($this->returnValue($this->mockRequestUri));
     $mockObjectFactory = $this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface');
     $mockObjectFactory->expects($this->once())->method('create')->will($this->returnValue($this->mockRequest));
     $this->mockConfigurationManager = $this->getMock('F3\\FLOW3\\Configuration\\ConfigurationManager', array('getConfiguration'), array(), '', FALSE);
     $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array()));
     $this->mockRouter = $this->getMock('F3\\FLOW3\\MVC\\Web\\Routing\\RouterInterface', array('route', 'setRoutesConfiguration', 'resolve'));
     $this->builder = new \F3\FLOW3\MVC\Web\RequestBuilder();
     $this->builder->injectObjectFactory($mockObjectFactory);
     $this->builder->injectEnvironment($this->mockEnvironment);
     $this->builder->injectConfigurationManager($this->mockConfigurationManager);
     $this->builder->injectRouter($this->mockRouter);
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
         }
     }
 }
Esempio n. 5
0
 /**
  * Runs the the FLOW3 Framework by resolving an appropriate Request Handler and passing control to it.
  * If the Framework is not initialized yet, it will be initialized.
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function run()
 {
     if (!$this->siteLocked) {
         $requestHandlerResolver = $this->objectManager->getObject('F3\\FLOW3\\MVC\\RequestHandlerResolver');
         $requestHandler = $requestHandlerResolver->resolveRequestHandler();
         $requestHandler->handleRequest();
         if ($this->settings['persistence']['enable'] === TRUE) {
             $this->objectManager->getObject('F3\\FLOW3\\Persistence\\PersistenceManagerInterface')->persistAll();
         }
         $this->emitFinishedNormalRun();
         $this->systemLogger->log('Shutting down ...', LOG_INFO);
         $this->configurationManager->shutdown();
         $this->objectManager->shutdown();
         $this->reflectionService->shutdown();
         $this->objectManager->getObject('F3\\FLOW3\\Object\\SessionRegistry')->writeDataToSession();
         $this->objectManager->getObject('F3\\FLOW3\\Session\\SessionInterface')->close();
     } else {
         header('HTTP/1.1 503 Service Temporarily Unavailable');
         readfile('package://FLOW3/Private/Core/LockHoldingStackPage.html');
         $this->systemLogger->log('Site is locked, exiting.', LOG_NOTICE);
     }
 }
 /**
  * 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);
             }
         }
     }
 }