/**
  * Dispatches a signal by calling the registered Slot methods
  *
  * @param string $signalClassName Name of the class containing the signal
  * @param string $signalMethodName Method name of the signal
  * @param array $signalArguments arguments passed to the signal method
  * @return void
  * @throws \F3\FLOW3\SignalSlot\Exception\InvalidSlotException if the slot is not valid
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function dispatch($signalClassName, $signalMethodName, array $signalArguments)
 {
     if (!isset($this->slots[$signalClassName][$signalMethodName])) {
         return;
     }
     $this->systemLogger->log(sprintf('Dispatching signal %s::%s ...', $signalClassName, $signalMethodName), LOG_DEBUG);
     foreach ($this->slots[$signalClassName][$signalMethodName] as $slotInformation) {
         if (isset($slotInformation['object'])) {
             $object = $slotInformation['object'];
         } else {
             if (!$this->objectManager->isObjectRegistered($slotInformation['class'])) {
                 throw new \F3\FLOW3\SignalSlot\Exception\InvalidSlotException('The given class "' . $slotInformation['class'] . '" is not a registered object.', 1245673367);
             }
             $object = $this->objectManager->getObject($slotInformation['class']);
         }
         $slotArguments = $signalArguments;
         if ($slotInformation['omitSignalInformation'] !== TRUE) {
             array_unshift($slotArguments, $signalClassName . '::' . $signalMethodName);
         }
         $this->systemLogger->log(sprintf('  to slot %s::%s.', get_class($object), $slotInformation['method']), LOG_DEBUG);
         if (!method_exists($object, $slotInformation['method'])) {
             throw new \F3\FLOW3\SignalSlot\Exception\InvalidSlotException('The slot method ' . get_class($object) . '->' . $slotInformation['method'] . '() does not exist.', 1245673368);
         }
         call_user_func_array(array($object, $slotInformation['method']), $slotArguments);
     }
 }
 /**
  * Create and set a validator conjunction
  *
  * @param array $objectNames Object names of the validators
  * @return \F3\FLOW3\MVC\Controller\Argument Returns $this (used for fluent interface)
  * @author Andreas Förthner <*****@*****.**>
  * @api
  */
 public function setNewValidatorConjunction(array $objectNames)
 {
     $this->validator = $this->objectFactory->create('F3\\FLOW3\\Validation\\Validator\\ConjunctionValidator');
     foreach ($objectNames as $objectName) {
         if (!$this->objectManager->isObjectRegistered($objectName)) {
             $objectName = 'F3\\FLOW3\\Validation\\Validator\\' . $objectName;
         }
         $this->validator->addValidator($this->objectManager->getObject($objectName));
     }
     return $this;
 }
 /**
  * Returns an object of an appropriate validator for the given type. If no
  * validator is available NULL is returned
  *
  * @param string $validatorType Either the fully qualified class name of the validator or the short name of a built-in validator
  * @return string Name of the validator object or FALSE
  * @author Robert Lemke <*****@*****.**>
  */
 protected function resolveValidatorObjectName($validatorType)
 {
     if ($this->objectManager->isObjectRegistered($validatorType)) {
         return $validatorType;
     }
     $possibleClassName = 'F3\\FLOW3\\Validation\\Validator\\' . $this->getValidatorType($validatorType) . 'Validator';
     if ($this->objectManager->isObjectRegistered($possibleClassName)) {
         return $possibleClassName;
     }
     return FALSE;
 }
 /**
  * Creates and sets the configured access decision voters
  *
  * @param array $voterClassNames Array of access decision voter class names
  * @return void
  * @author Andreas Förthner <*****@*****.**>
  */
 protected function createAccessDecisionVoters(array $voterClassNames)
 {
     foreach ($voterClassNames as $voterClassName) {
         if (!$this->objectManager->isObjectRegistered($voterClassName)) {
             throw new \F3\FLOW3\Security\Exception\VoterNotFoundException('No voter of type ' . $voterClassName . ' found!', 1222267934);
         }
         $voter = $this->objectManager->getObject($voterClassName);
         if (!$voter instanceof \F3\FLOW3\Security\Authorization\AccessDecisionVoterInterface) {
             throw new \F3\FLOW3\Security\Exception\VoterNotFoundException('The found voter class did not implement \\F3\\FLOW3\\Security\\Authorization\\AccessDecisionVoterInterface', 1222268008);
         }
         $this->accessDecisionVoters[] = $voter;
     }
 }
 /**
  * Analyzes the raw request and tries to find a request handler which can handle
  * it. If none is found, an exception is thrown.
  *
  * @return \F3\FLOW3\MVC\RequestHandler A request handler
  * @throws \F3\FLOW3\MVC\Exception
  * @author Robert Lemke <*****@*****.**>
  */
 public function resolveRequestHandler()
 {
     $availableRequestHandlerClassNames = $this->reflectionService->getAllImplementationClassNamesForInterface('F3\\FLOW3\\MVC\\RequestHandlerInterface');
     $suitableRequestHandlers = array();
     foreach ($availableRequestHandlerClassNames as $requestHandlerClassName) {
         if (!$this->objectManager->isObjectRegistered($requestHandlerClassName)) {
             continue;
         }
         $requestHandler = $this->objectManager->getObject($requestHandlerClassName);
         if ($requestHandler->canHandleRequest()) {
             $priority = $requestHandler->getPriority();
             if (isset($suitableRequestHandlers[$priority])) {
                 throw new \F3\FLOW3\MVC\Exception('More than one request handler with the same priority can handle the request, but only one handler may be active at a time!', 1176475350);
             }
             $suitableRequestHandlers[$priority] = $requestHandler;
         }
     }
     if (count($suitableRequestHandlers) === 0) {
         throw new \F3\FLOW3\MVC\Exception('No suitable request handler found.', 1205414233);
     }
     ksort($suitableRequestHandlers);
     return array_pop($suitableRequestHandlers);
 }
 /**
  * Creates a fresh instance of the object specified by $objectName.
  *
  * This factory method can only create objects of the scope prototype.
  * Singleton objects must be either injected by some type of Dependency Injection or
  * if that is not possible, be retrieved by the getObject() method of the
  * Object Manager
  *
  * You must use either Dependency Injection or this factory method for instantiation
  * of your objects if you need FLOW3's object management capabilities (including
  * AOP, Security and Persistence). It is absolutely okay and often advisable to
  * use the "new" operator for instantiation in your automated tests.
  *
  * @param string $objectName The name of the object to create
  * @return object The new object instance
  * @throws \InvalidArgumentException if the object name starts with a backslash
  * @throws \F3\FLOW3\Object\Exception\UnknownObjectException if an object with the given name does not exist
  * @throws \F3\FLOW3\Object\Exception\WrongScopeException if the specified object is not configured as Prototype
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function create($objectName)
 {
     if ($objectName[0] === '\\') {
         throw new \InvalidArgumentException('The object name must not start with a backslash, "' . $objectName . '" given.', 1243272770);
     }
     if (!$this->objectManager->isObjectRegistered($objectName)) {
         throw new \F3\FLOW3\Object\Exception\UnknownObjectException('Object "' . $objectName . '" is not registered.', 1166550023);
     }
     $objectConfiguration = $this->objectManager->getObjectConfiguration($objectName);
     if ($objectConfiguration->getScope() != 'prototype') {
         throw new \F3\FLOW3\Object\Exception\WrongScopeException('Object "' . $objectName . '" is of scope ' . $objectConfiguration->getScope() . ' but only prototype is supported by create()', 1225385285);
     }
     $overridingArguments = self::convertArgumentValuesToArgumentObjects(array_slice(func_get_args(), 1));
     $object = $this->objectBuilder->createObject($objectName, $objectConfiguration, $overridingArguments);
     $this->objectManager->registerShutdownObject($object, $objectConfiguration->getLifecycleShutdownMethodName());
     return $object;
 }
 /**
  * Parses the tokens, starting at the current index and replaces the "new"
  * operator with a call to the object manager if the class to be instantiated
  * is registered as an object.
  *
  * @param array $tokens Tokens to parse
  * @param integer &$index Token index to start at
  * @param string &$targetCode Target source code for replacement
  * @return boolean Returns TRUE if the new operator really has been replaced, otherwise FALSE
  * @author Robert Lemke <*****@*****.**>
  */
 protected function replaceNewOperator(array $tokens, &$index, &$targetCode)
 {
     $index++;
     $newOperatorHasBeenReplaced = FALSE;
     $whitespace = '';
     while ($tokens[$index][0] === T_WHITESPACE) {
         $whitespace .= $tokens[$index][1];
         $index++;
     }
     switch ($tokens[$index][0]) {
         case T_STRING:
             $className = $tokens[$index][1];
             if ($tokens[$index + 1][0] === '(') {
                 $index++;
                 $constructorArguments = $this->parseConstructorArguments($tokens, $index);
                 if ($this->objectManager->isObjectRegistered($className)) {
                     $targetCode .= '$GLOBALS[\'TYPO3\']->getObjectManager()->getObject' . '(\'' . $className . '\', ' . $constructorArguments . ')' . $whitespace;
                     $newOperatorHasBeenReplaced = TRUE;
                 } else {
                     $targetCode .= 'new' . $whitespace . $className . '(' . $constructorArguments . ')';
                 }
             } else {
                 if ($this->objectManager->isObjectRegistered($className)) {
                     $targetCode .= '$GLOBALS[\'TYPO3\']->getObjectManager()->getObject' . '(\'' . $className . '\')' . $whitespace;
                     $newOperatorHasBeenReplaced = TRUE;
                 } else {
                     $targetCode .= 'new' . $whitespace . $className;
                 }
             }
             break;
         case T_VARIABLE:
         default:
             $targetCode .= 'new' . $whitespace;
             $targetCode .= $tokens[$index][1];
     }
     return $newOperatorHasBeenReplaced;
 }