示例#1
0
 /**
  * @test
  */
 public function parseSetsDefaultValueOfRoutePartsRecursively()
 {
     $this->route->setUriPattern('{foo.bar}');
     $this->route->setRoutePartsConfiguration(array('foo.bar' => array('handler' => 'SomeRoutePartHandler')));
     $this->route->setDefaults(array('foo' => array('bar' => 'SomeDefaultValue')));
     $mockRoutePartHandler = $this->getMock('TYPO3\\FLOW3\\Mvc\\Routing\\DynamicRoutePartInterface');
     $mockRoutePartHandler->expects($this->once())->method('setDefaultValue')->with('SomeDefaultValue');
     $this->mockObjectManager->expects($this->once())->method('get')->with('SomeRoutePartHandler')->will($this->returnValue($mockRoutePartHandler));
     $this->route->parse();
 }
示例#2
0
 /**
  * Flush all caches
  *
  * The flush command flushes all caches (including code caches) which have been
  * registered with FLOW3's Cache Manager. It also removes any session data.
  *
  * If fatal errors caused by a package prevent the compile time bootstrap
  * from running, the removal of any temporary data can be forced by specifying
  * the option <b>--force</b>.
  *
  * This command does not remove the precompiled data provided by frozen
  * packages unless the <b>--force</b> option is used.
  *
  * @param boolean $force Force flushing of any temporary data
  * @return void
  * @see typo3.flow3:cache:warmup
  * @see typo3.flow3:package:freeze
  * @see typo3.flow3:package:refreeze
  */
 public function flushCommand($force = FALSE)
 {
     // Internal note: the $force option is evaluated early in the FLOW3
     // bootstrap in order to reliably flush the temporary data before any
     // other code can cause fatal errors.
     $currentSessionImplementation = $this->objectManager->getClassNameByObjectName('TYPO3\\FLOW3\\Session\\SessionInterface');
     $result = $currentSessionImplementation::destroyAll($this->bootstrap);
     if ($result === NULL) {
         $sessionDestroyMessage = ' and removed all potentially existing session data.';
     } elseif ($result > 0) {
         $sessionDestroyMessage = sprintf(' and removed data of %s.', $result === 1 ? 'the one existing session' : 'the ' . $result . ' existing sessions');
     } else {
         $sessionDestroyMessage = '.';
     }
     $this->cacheManager->flushCaches();
     $this->outputLine('Flushed all caches for "' . $this->bootstrap->getContext() . '" context' . $sessionDestroyMessage);
     if ($this->lockManager->isSiteLocked()) {
         $this->lockManager->unlockSite();
     }
     $frozenPackages = array();
     foreach (array_keys($this->packageManager->getActivePackages()) as $packageKey) {
         if ($this->packageManager->isPackageFrozen($packageKey)) {
             $frozenPackages[] = $packageKey;
         }
     }
     if ($frozenPackages !== array()) {
         $this->outputFormatted(PHP_EOL . 'Please note that the following package' . (count($frozenPackages) === 1 ? ' is' : 's are') . ' currently frozen: ' . PHP_EOL);
         $this->outputFormatted(implode(PHP_EOL, $frozenPackages) . PHP_EOL, array(), 2);
         $message = 'As code and configuration changes in these packages are not detected, the application may respond ';
         $message .= 'unexpectedly if modifications were done anyway or the remaining code relies on these changes.' . PHP_EOL . PHP_EOL;
         $message .= 'You may call <b>package:refreeze all</b> in order to refresh frozen packages or use the <b>--force</b> ';
         $message .= 'option of this <b>cache:flush</b> command to flush caches if FLOW3 becomes unresponsive.' . PHP_EOL;
         $this->outputFormatted($message, array($frozenPackages));
     }
     $this->sendAndExit(0);
 }
示例#3
0
 /**
  * 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;
 }