示例#1
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;
 }
 /**
  * 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;
 }
示例#3
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;
     }
 }
示例#4
0
 /**
  * Builds a base validator conjunction for the given data type.
  *
  * The base validation rules are those which were declared directly in a class (typically
  * a model) through some validate annotations on properties.
  *
  * If a property holds a class for which a base validator exists, that property will be
  * checked as well, regardless of a validate annotation
  *
  * Additionally, if a custom validator was defined for the class in question, it will be added
  * to the end of the conjunction. A custom validator is found if it follows the naming convention
  * "Replace '\Model\' by '\Validator\' and append 'Validator'".
  *
  * Example: $targetClassName is TYPO3\Foo\Domain\Model\Quux, then the validator will be found if it has the
  * name TYPO3\Foo\Domain\Validator\QuuxValidator
  *
  * @param string $indexKey The key to use as index in $this->baseValidatorConjunctions; calculated from target class name and validation groups
  * @param string $targetClassName The data type to build the validation conjunction for. Needs to be the fully qualified class name.
  * @param array $validationGroups The validation groups to build the validator for
  * @return void
  * @throws Exception\NoSuchValidatorException
  * @throws \InvalidArgumentException
  */
 protected function buildBaseValidatorConjunction($indexKey, $targetClassName, array $validationGroups)
 {
     $conjunctionValidator = new ConjunctionValidator();
     $this->baseValidatorConjunctions[$indexKey] = $conjunctionValidator;
     if (class_exists($targetClassName)) {
         // Model based validator
         $objectValidator = new GenericObjectValidator(array());
         foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $classPropertyName) {
             $classPropertyTagsValues = $this->reflectionService->getPropertyTagsValues($targetClassName, $classPropertyName);
             try {
                 $parsedType = \TYPO3\FLOW3\Utility\TypeHandling::parseType(trim(implode('', $classPropertyTagsValues['var']), ' \\'));
             } catch (\TYPO3\FLOW3\Utility\Exception\InvalidTypeException $exception) {
                 throw new \InvalidArgumentException(sprintf(' @var annotation of ' . $exception->getMessage(), 'class "' . $targetClassName . '", property "' . $classPropertyName . '"'), 1315564744);
             }
             $propertyTargetClassName = $parsedType['type'];
             if (\TYPO3\FLOW3\Utility\TypeHandling::isCollectionType($propertyTargetClassName) === TRUE) {
                 $collectionValidator = $this->createValidator('TYPO3\\FLOW3\\Validation\\Validator\\CollectionValidator', array('elementType' => $parsedType['elementType'], 'validationGroups' => $validationGroups));
                 $objectValidator->addPropertyValidator($classPropertyName, $collectionValidator);
             } elseif (class_exists($propertyTargetClassName) && $this->objectManager->isRegistered($propertyTargetClassName) && $this->objectManager->getScope($propertyTargetClassName) === \TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_PROTOTYPE) {
                 $validatorForProperty = $this->getBaseValidatorConjunction($propertyTargetClassName, $validationGroups);
                 if (count($validatorForProperty) > 0) {
                     $objectValidator->addPropertyValidator($classPropertyName, $validatorForProperty);
                 }
             }
             $validateAnnotations = $this->reflectionService->getPropertyAnnotations($targetClassName, $classPropertyName, 'TYPO3\\FLOW3\\Annotations\\Validate');
             foreach ($validateAnnotations as $validateAnnotation) {
                 if (count(array_intersect($validateAnnotation->validationGroups, $validationGroups)) === 0) {
                     // In this case, the validation groups for the property do not match current validation context
                     continue;
                 }
                 $newValidator = $this->createValidator($validateAnnotation->type, $validateAnnotation->options);
                 if ($newValidator === NULL) {
                     throw new \TYPO3\FLOW3\Validation\Exception\NoSuchValidatorException('Invalid validate annotation in ' . $targetClassName . '::' . $classPropertyName . ': Could not resolve class name for  validator "' . $validateAnnotation->type . '".', 1241098027);
                 }
                 $objectValidator->addPropertyValidator($classPropertyName, $newValidator);
             }
         }
         if (count($objectValidator->getPropertyValidators()) > 0) {
             $conjunctionValidator->addValidator($objectValidator);
         }
         // Custom validator for the class
         $possibleValidatorClassName = str_replace('\\Model\\', '\\Validator\\', $targetClassName) . 'Validator';
         $customValidator = $this->createValidator($possibleValidatorClassName);
         if ($customValidator !== NULL) {
             $conjunctionValidator->addValidator($customValidator);
         }
     }
 }
示例#5
0
文件: Debugger.php 项目: nxpthx/FLOW3
 /**
  * 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;
 }