Example #1
0
 /**
  * @test
  */
 public function ifCommandCantBeResolvedTheHelpScreenIsShown()
 {
     // The following call is only made to satisfy PHPUnit. For some weird reason PHPUnit complains that the
     // mocked method ("getObjectNameByClassName") does not exist _if the mock object is not used_.
     $this->mockObjectManager->getObjectNameByClassName('Acme\\Test\\Command\\DefaultCommandController');
     $this->mockCommandManager->getCommandByIdentifier('acme.test:default:list');
     $mockCommandManager = $this->getMock('TYPO3\\FLOW3\\Cli\\CommandManager');
     $mockCommandManager->expects($this->any())->method('getCommandByIdentifier')->with('test:default:list')->will($this->throwException(new \TYPO3\FLOW3\Mvc\Exception\NoSuchCommandException()));
     $this->requestBuilder->injectCommandManager($mockCommandManager);
     $request = $this->requestBuilder->build('test:default:list');
     $this->assertSame('TYPO3\\FLOW3\\Command\\HelpCommandController', $request->getControllerObjectName());
 }
Example #2
0
 /**
  * Around advice, wrapping every method of a scope session object. It redirects
  * all method calls to the session object once there is one.
  *
  * @param \TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint The current join point
  * @return mixed
  * @FLOW3\Around("filter(TYPO3\FLOW3\Session\Aspect\SessionObjectMethodsPointcutFilter)")
  */
 public function callMethodOnOriginalSessionObject(\TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint)
 {
     $objectName = $this->objectManager->getObjectNameByClassName(get_class($joinPoint->getProxy()));
     $methodName = $joinPoint->getMethodName();
     $proxy = $joinPoint->getProxy();
     if (!isset($this->sessionOriginalInstances[$objectName])) {
         $this->sessionOriginalInstances[$objectName] = $this->objectManager->get($objectName);
     }
     if ($this->sessionOriginalInstances[$objectName] === $proxy) {
         return $joinPoint->getAdviceChain()->proceed($joinPoint);
     } else {
         return call_user_func_array(array($this->sessionOriginalInstances[$objectName], $methodName), $joinPoint->getMethodArguments());
     }
 }
Example #3
0
 /**
  * Starts or resumes a session
  *
  * @return mixed If a session was resumed, the number of seconds it has been inactive previously. If a new session was started: TRUE
  */
 protected function startOrResume()
 {
     session_start();
     $this->sessionId = session_id();
     $this->started = TRUE;
     $previousInactivityInSeconds = TRUE;
     if ($this->hasKey('TYPO3_FLOW3_Session_LastActivity')) {
         $previousInactivityInSeconds = time() - $this->getData('TYPO3_FLOW3_Session_LastActivity');
     }
     $this->putData('TYPO3_FLOW3_Session_LastActivity', time());
     if ($this->hasKey('TYPO3_FLOW3_Object_ObjectManager') === TRUE) {
         $sessionObjects = $this->getData('TYPO3_FLOW3_Object_ObjectManager');
         if (is_array($sessionObjects)) {
             foreach ($sessionObjects as $object) {
                 if ($object instanceof \TYPO3\FLOW3\Object\Proxy\ProxyInterface) {
                     $objectName = $this->objectManager->getObjectNameByClassName(get_class($object));
                     if ($this->objectManager->getScope($objectName) === ObjectConfiguration::SCOPE_SESSION) {
                         $this->objectManager->setInstance($objectName, $object);
                         $this->lazyLoadingAspect->registerSessionInstance($objectName, $object);
                         $object->__wakeup();
                     }
                 }
             }
         } else {
             // Fallback for some malformed session data, if it is no array but something else.
             // In this case, we reset all session objects (graceful degradation).
             $this->putData('TYPO3_FLOW3_Object_ObjectManager', array());
         }
     }
     return $previousInactivityInSeconds;
 }
Example #4
0
 /**
  * Builds a CLI request object from a command line.
  *
  * The given command line may be a string (e.g. "mypackage:foo do-that-thing --force") or
  * an array consisting of the individual parts. The array must not include the script
  * name (like in $argv) but start with command right away.
  *
  * @param mixed $commandLine The command line, either as a string or as an array
  * @return \TYPO3\FLOW3\Cli\Request The CLI request as an object
  */
 public function build($commandLine)
 {
     $request = new Request();
     $request->setControllerObjectName('TYPO3\\FLOW3\\Command\\HelpCommandController');
     $rawCommandLineArguments = is_array($commandLine) ? $commandLine : explode(' ', $commandLine);
     if (count($rawCommandLineArguments) === 0) {
         $request->setControllerCommandName('helpStub');
         return $request;
     }
     $commandIdentifier = trim(array_shift($rawCommandLineArguments));
     try {
         $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
     } catch (\TYPO3\FLOW3\Mvc\Exception\CommandException $exception) {
         $request->setArgument('exception', $exception);
         $request->setControllerCommandName('error');
         return $request;
     }
     $controllerObjectName = $this->objectManager->getObjectNameByClassName($command->getControllerClassName());
     $controllerCommandName = $command->getControllerCommandName();
     $request->setControllerObjectName($controllerObjectName);
     $request->setControllerCommandName($controllerCommandName);
     list($commandLineArguments, $exceedingCommandLineArguments) = $this->parseRawCommandLineArguments($rawCommandLineArguments, $controllerObjectName, $controllerCommandName);
     $request->setArguments($commandLineArguments);
     $request->setExceedingArguments($exceedingCommandLineArguments);
     return $request;
 }
 /**
  * Checks if the specified class and method matches against the filter
  *
  * @param string $className Name of the class to check against
  * @param string $methodName Name of the method to check against
  * @param string $methodDeclaringClassName Name of the class the method was originally declared in
  * @param mixed $pointcutQueryIdentifier Some identifier for this query - must at least differ from a previous identifier. Used for circular reference detection.
  * @return boolean TRUE if the class / method match, otherwise FALSE
  */
 public function matches($className, $methodName, $methodDeclaringClassName, $pointcutQueryIdentifier)
 {
     if ($methodName === NULL) {
         return FALSE;
     }
     $objectName = $this->objectManager->getObjectNameByClassName($className);
     if (empty($objectName)) {
         return FALSE;
     }
     if ($this->objectManager->getScope($objectName) !== ObjectConfiguration::SCOPE_SESSION) {
         return FALSE;
     }
     if (preg_match('/^__wakeup|__construct|__destruct|__sleep|__serialize|__unserialize|__clone|shutdownObject|initializeObject|inject.*$/', $methodName) !== 0) {
         return FALSE;
     }
     return TRUE;
 }
Example #6
0
 /**
  * Serializes an object as property array.
  *
  * @param object $object The object to store in the registry
  * @param boolean $isTopLevelItem Internal flag for managing the recursion
  * @return array The property array
  */
 public function serializeObjectAsPropertyArray($object, $isTopLevelItem = TRUE)
 {
     if ($isTopLevelItem) {
         $this->objectReferences = new \SplObjectStorage();
     }
     $this->objectReferences->attach($object);
     $className = get_class($object);
     $propertyArray = array();
     foreach ($this->reflectionService->getClassPropertyNames($className) as $propertyName) {
         if ($this->reflectionService->isPropertyTaggedWith($className, $propertyName, 'transient')) {
             continue;
         }
         $propertyReflection = new \TYPO3\FLOW3\Reflection\PropertyReflection($className, $propertyName);
         $propertyValue = $propertyReflection->getValue($object);
         if (is_object($propertyValue) && isset($this->objectReferences[$propertyValue])) {
             $propertyArray[$propertyName][self::TYPE] = 'object';
             $propertyArray[$propertyName][self::VALUE] = \spl_object_hash($propertyValue);
             continue;
         }
         $propertyClassName = is_object($propertyValue) ? get_class($propertyValue) : '';
         if ($propertyClassName === 'SplObjectStorage') {
             $propertyArray[$propertyName][self::TYPE] = 'SplObjectStorage';
             $propertyArray[$propertyName][self::VALUE] = array();
             foreach ($propertyValue as $storedObject) {
                 $propertyArray[$propertyName][self::VALUE][] = spl_object_hash($storedObject);
                 $this->serializeObjectAsPropertyArray($storedObject, FALSE);
             }
         } elseif (is_object($propertyValue) && $propertyValue instanceof \Doctrine\Common\Collections\Collection) {
             $propertyArray[$propertyName][self::TYPE] = 'Collection';
             $propertyArray[$propertyName][self::CLASSNAME] = get_class($propertyValue);
             $propertyArray[$propertyName][self::VALUE] = $this->buildStorageArrayForArrayProperty($propertyValue->toArray());
         } elseif (is_object($propertyValue) && $propertyValue instanceof \ArrayObject) {
             $propertyArray[$propertyName][self::TYPE] = 'ArrayObject';
             $propertyArray[$propertyName][self::VALUE] = $this->buildStorageArrayForArrayProperty($propertyValue->getArrayCopy());
         } elseif (is_object($propertyValue) && $this->persistenceManager->isNewObject($propertyValue) === FALSE && ($this->reflectionService->isClassAnnotatedWith($propertyClassName, 'TYPO3\\FLOW3\\Annotations\\Entity') || $this->reflectionService->isClassAnnotatedWith($propertyClassName, 'TYPO3\\FLOW3\\Annotations\\ValueObject') || $this->reflectionService->isClassAnnotatedWith($propertyClassName, 'Doctrine\\ORM\\Mapping\\Entity'))) {
             $propertyArray[$propertyName][self::TYPE] = 'persistenceObject';
             $propertyArray[$propertyName][self::VALUE] = get_class($propertyValue) . ':' . $this->persistenceManager->getIdentifierByObject($propertyValue);
         } elseif (is_object($propertyValue)) {
             $propertyObjectName = $this->objectManager->getObjectNameByClassName($propertyClassName);
             if ($propertyObjectName != '' && $this->objectManager->getScope($propertyObjectName) === \TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_SINGLETON) {
                 continue;
             }
             $propertyArray[$propertyName][self::TYPE] = 'object';
             $propertyArray[$propertyName][self::VALUE] = spl_object_hash($propertyValue);
             $this->serializeObjectAsPropertyArray($propertyValue, FALSE);
         } elseif (is_array($propertyValue)) {
             $propertyArray[$propertyName][self::TYPE] = 'array';
             $propertyArray[$propertyName][self::VALUE] = $this->buildStorageArrayForArrayProperty($propertyValue);
         } else {
             $propertyArray[$propertyName][self::TYPE] = 'simple';
             $propertyArray[$propertyName][self::VALUE] = $propertyValue;
         }
     }
     $this->objectsAsArray[spl_object_hash($object)] = array(self::CLASSNAME => $className, self::PROPERTIES => $propertyArray);
     if ($isTopLevelItem) {
         return $this->objectsAsArray;
     }
 }
Example #7
0
 /**
  * Renders a dump of the given object
  *
  * @param object $object
  * @param integer $level
  * @param boolean $renderProperties
  * @param boolean $plaintext
  * @param boolean $ansiColors
  * @return string
  */
 protected static function renderObjectDump($object, $level, $renderProperties = TRUE, $plaintext = FALSE, $ansiColors = FALSE)
 {
     $dump = '';
     $scope = '';
     $additionalAttributes = '';
     if ($object instanceof \Doctrine\Common\Collections\Collection) {
         return self::renderArrayDump(\Doctrine\Common\Util\Debug::export($object, 12), $level, $plaintext, $ansiColors);
     }
     // Objects returned from Doctrine's Debug::export function are stdClass with special properties:
     try {
         $objectIdentifier = ObjectAccess::getProperty($object, 'FLOW3_Persistence_Identifier', TRUE);
     } catch (\TYPO3\FLOW3\Reflection\Exception\PropertyNotAccessibleException $exception) {
         $objectIdentifier = spl_object_hash($object);
     }
     $className = $object instanceof \stdClass && isset($object->__CLASS__) ? $object->__CLASS__ : get_class($object);
     if (preg_match(self::$blacklistedClassNames, $className) !== 0 || isset(self::$renderedObjects[$objectIdentifier])) {
         $renderProperties = FALSE;
     }
     self::$renderedObjects[$objectIdentifier] = TRUE;
     if (self::$objectManager !== NULL) {
         $objectName = self::$objectManager->getObjectNameByClassName(get_class($object));
         if ($objectName !== FALSE) {
             switch (self::$objectManager->getScope($objectName)) {
                 case \TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_PROTOTYPE:
                     $scope = 'prototype';
                     break;
                 case \TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_SINGLETON:
                     $scope = 'singleton';
                     break;
                 case \TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_SESSION:
                     $scope = 'session';
                     break;
             }
         } else {
             $additionalAttributes .= ' debug-unregistered';
         }
     }
     if ($renderProperties === TRUE && !$plaintext) {
         if ($scope === '') {
             $scope = 'prototype';
         }
         $scope .= '<a id="o' . $objectIdentifier . '"></a>';
     }
     if ($plaintext) {
         $dump .= $className;
         $dump .= $scope !== '' ? ' ' . self::ansiEscapeWrap($scope, '44;37', $ansiColors) : '';
     } else {
         $dump .= '<span class="debug-object' . $additionalAttributes . '" title="' . $objectIdentifier . '">' . $className . '</span>';
         $dump .= $scope !== '' ? '<span class="debug-scope">' . $scope . '</span>' : '';
     }
     if (property_exists($object, 'FLOW3_Persistence_Identifier')) {
         $persistenceIdentifier = $objectIdentifier;
         $persistenceType = 'persistable';
     } else {
         $persistenceIdentifier = 'unknown';
         $persistenceType = 'object';
     }
     if ($plaintext) {
         $dump .= ' ' . self::ansiEscapeWrap($persistenceType, '42;37', $ansiColors);
     } else {
         $dump .= '<span class="debug-ptype" title="' . $persistenceIdentifier . '">' . $persistenceType . '</span>';
     }
     if ($object instanceof \TYPO3\FLOW3\Object\Proxy\ProxyInterface || isset($object->__IS_PROXY__) && $object->__IS_PROXY__ === TRUE) {
         if ($plaintext) {
             $dump .= ' ' . self::ansiEscapeWrap('proxy', '41;37', $ansiColors);
         } else {
             $dump .= '<span class="debug-proxy" title="' . $className . '">proxy</span>';
         }
     }
     if ($renderProperties === TRUE) {
         if ($object instanceof \SplObjectStorage) {
             $dump .= ' (' . (count($object) ?: 'empty') . ')';
             foreach ($object as $value) {
                 $dump .= chr(10);
                 $dump .= str_repeat(' ', $level);
                 $dump .= self::renderObjectDump($value, 0, FALSE, $plaintext, $ansiColors);
             }
         } else {
             $classReflection = new \ReflectionClass($className);
             $properties = $classReflection->getProperties();
             foreach ($properties as $property) {
                 if (preg_match(self::$blacklistedPropertyNames, $property->getName())) {
                     continue;
                 }
                 $dump .= chr(10);
                 $dump .= str_repeat(' ', $level) . ($plaintext ? '' : '<span class="debug-property">') . self::ansiEscapeWrap($property->getName(), '36', $ansiColors) . ($plaintext ? '' : '</span>') . ' => ';
                 $property->setAccessible(TRUE);
                 $value = $property->getValue($object);
                 if (is_array($value)) {
                     $dump .= self::renderDump($value, $level + 1, $plaintext, $ansiColors);
                 } elseif (is_object($value)) {
                     $dump .= self::renderObjectDump($value, $level + 1, TRUE, $plaintext, $ansiColors);
                 } else {
                     $dump .= self::renderDump($value, $level, $plaintext, $ansiColors);
                 }
             }
         }
     } elseif (isset(self::$renderedObjects[$objectIdentifier])) {
         if (!$plaintext) {
             $dump = '<a href="#o' . $objectIdentifier . '" onclick="document.location.hash=\'#o' . $objectIdentifier . '\'; return false;" class="debug-seeabove" title="see above">' . $dump . '</a>';
         }
     }
     return $dump;
 }