public function objectToScalar($object, $path = NULL)
 {
     $className = $this->reflectionService->getClassNameByObject($object);
     $methods = $this->getGetterMethodsForClass($className);
     $result = [];
     foreach ($methods as $key => $methodName) {
         $result[$key] = $object->{$methodName}();
     }
     return $result;
 }
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param array $configuration Configuration for transforming the given object
  * @param boolean $onlyIdentifier
  * @param boolean $enableSideLoading
  * @return array Object structure as an array
  * @todo implement sideloading
  */
 protected function transformObject($object, array $configuration, $onlyIdentifier = TRUE, $enableSideLoading = TRUE)
 {
     if ($object instanceof \DateTime) {
         return $object->format('Y-m-d\\TH:i:s');
     } elseif ($onlyIdentifier === TRUE) {
         return $this->persistenceManager->getIdentifierByObject($object);
     } else {
         $transformedObject = array('id' => $this->persistenceManager->getIdentifierByObject($object));
         $objectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($object));
         foreach (ObjectAccess::getGettablePropertyNames($object) as $propertyName) {
             if ($this->isPropertyIgnored($objectName, $propertyName)) {
                 continue;
             }
             $propertyValue = ObjectAccess::getProperty($object, $propertyName);
             if (is_array($propertyValue) || $propertyValue instanceof \ArrayAccess) {
                 $propertyValue = $this->transformValue($propertyValue, array(), TRUE, $enableSideLoading);
                 if ($this->isRelation($objectName, $propertyName)) {
                     $this->addLink($transformedObject, $propertyName, $propertyValue);
                     if ($enableSideLoading === TRUE && !$this->reflectionService->isPropertyAnnotatedWith($objectName, $propertyName, 'TYPO3\\Flow\\Annotations\\Lazy')) {
                         $propertyTags = $this->reflectionService->getPropertyTagValues($objectName, $propertyName, 'var');
                         $propertyObjectType = TypeHandling::parseType($propertyTags[0]);
                         $this->sideLoad($propertyObjectType['elementType'], $propertyValue);
                     }
                     $propertyValue = NULL;
                 } elseif (empty($propertyValue)) {
                     $propertyValue = NULL;
                 }
             } elseif ($this->isSimpleValue($propertyValue)) {
                 if (is_object($propertyValue)) {
                     $propertyValue = $this->transformObject($propertyValue, $configuration, FALSE, $enableSideLoading);
                 }
             } elseif (is_object($propertyValue)) {
                 $propertyObjectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($propertyValue));
                 if (!$this->isObjectIgnored($propertyObjectName)) {
                     $propertyValue = $this->transformObject($propertyValue, $configuration, TRUE, $enableSideLoading);
                     if ($this->isRelation($objectName, $propertyName)) {
                         $this->addLink($transformedObject, $propertyName, $propertyValue);
                         if ($enableSideLoading === TRUE && !$this->reflectionService->isPropertyAnnotatedWith($objectName, $propertyName, 'TYPO3\\Flow\\Annotations\\Lazy')) {
                             $this->sideLoad($propertyObjectName, $propertyValue);
                         }
                         $propertyValue = NULL;
                     } elseif (empty($propertyValue)) {
                         $propertyValue = NULL;
                     }
                 }
             }
             if ($propertyValue !== NULL) {
                 if (is_object($propertyValue)) {
                     $propertyObjectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($propertyValue));
                     if (!$this->isObjectIgnored($propertyObjectName)) {
                         $transformedObject[$propertyName] = $propertyValue;
                     }
                 } else {
                     $transformedObject[$propertyName] = $propertyValue;
                 }
             }
         }
         return $transformedObject;
     }
 }
 /**
  * Returns the ElasticSearch type for a specific object, by its annotation
  *
  * @param $object
  * @param \Flowpack\ElasticSearch\Domain\Model\Client $client
  *
  * @return \Flowpack\ElasticSearch\Domain\Model\GenericType
  */
 protected function getIndexTypeForObject($object, Client $client = null)
 {
     if ($client === null) {
         $client = $this->client;
     }
     $className = $this->reflectionService->getClassNameByObject($object);
     $indexAnnotation = $this->indexInformer->getClassAnnotation($className);
     if ($indexAnnotation === null) {
         return null;
     }
     $index = $client->findIndex($indexAnnotation->indexName);
     $type = new GenericType($index, $indexAnnotation->typeName);
     return $type;
 }
 /**
  * An onFlush event listener used to validate entities upon persistence.
  *
  * @param \Doctrine\ORM\Event\OnFlushEventArgs $eventArgs
  * @return void
  */
 public function onFlush(\Doctrine\ORM\Event\OnFlushEventArgs $eventArgs)
 {
     $unitOfWork = $this->entityManager->getUnitOfWork();
     $entityInsertions = $unitOfWork->getScheduledEntityInsertions();
     $validatedInstancesContainer = new \SplObjectStorage();
     $knownValueObjects = array();
     foreach ($entityInsertions as $entity) {
         if ($this->reflectionService->getClassSchema($entity)->getModelType() === \TYPO3\Flow\Reflection\ClassSchema::MODELTYPE_VALUEOBJECT) {
             $identifier = $this->getIdentifierByObject($entity);
             $className = $this->reflectionService->getClassNameByObject($entity);
             if (isset($knownValueObjects[$className][$identifier]) || $unitOfWork->getEntityPersister($className)->exists($entity)) {
                 unset($entityInsertions[spl_object_hash($entity)]);
                 continue;
             }
             $knownValueObjects[$className][$identifier] = TRUE;
         }
         $this->validateObject($entity, $validatedInstancesContainer);
     }
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($unitOfWork, 'entityInsertions', $entityInsertions, TRUE);
     foreach ($unitOfWork->getScheduledEntityUpdates() as $entity) {
         $this->validateObject($entity, $validatedInstancesContainer);
     }
 }
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param array $configuration Configuration for transforming the given object or NULL
  * @return array Object structure as an array
  */
 protected function transformObject($object, array $configuration)
 {
     if ($object instanceof \DateTime) {
         return $object->format(\DateTime::ISO8601);
     } else {
         $propertyNames = \TYPO3\Flow\Reflection\ObjectAccess::getGettablePropertyNames($object);
         $propertiesToRender = array();
         foreach ($propertyNames as $propertyName) {
             if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) {
                 continue;
             }
             if (isset($configuration['_exclude']) && is_array($configuration['_exclude']) && in_array($propertyName, $configuration['_exclude'])) {
                 continue;
             }
             $propertyValue = \TYPO3\Flow\Reflection\ObjectAccess::getProperty($object, $propertyName);
             if (!is_array($propertyValue) && !is_object($propertyValue)) {
                 $propertiesToRender[$propertyName] = $propertyValue;
             } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) {
                 $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]);
             }
         }
         if (isset($configuration['_exposeObjectIdentifier']) && $configuration['_exposeObjectIdentifier'] === TRUE) {
             if (isset($configuration['_exposedObjectIdentifierKey']) && strlen($configuration['_exposedObjectIdentifierKey']) > 0) {
                 $identityKey = $configuration['_exposedObjectIdentifierKey'];
             } else {
                 $identityKey = '__identity';
             }
             $propertiesToRender[$identityKey] = $this->persistenceManager->getIdentifierByObject($object);
         }
         if (isset($configuration['_exposeClassName']) && ($configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED || $configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_UNQUALIFIED)) {
             $className = $this->reflectionService->getClassNameByObject($object);
             $classNameParts = explode('\\', $className);
             $propertiesToRender['__class'] = $configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED ? $className : array_pop($classNameParts);
         }
         return $propertiesToRender;
     }
 }
 /**
  * Checks, if the given constraint holds for the passed result.
  *
  * @param array $constraintDefinition The constraint definition array
  * @param object $result The result object returned by the persistence manager
  * @return boolean TRUE if the query result is valid for the given constraint
  * @throws \TYPO3\Flow\Security\Exception\InvalidQueryRewritingConstraintException
  */
 protected function checkSingleConstraintDefinitionOnResultObject(array $constraintDefinition, $result)
 {
     $referenceToThisFound = FALSE;
     if (!is_array($constraintDefinition['leftValue']) && strpos($constraintDefinition['leftValue'], 'this.') === 0) {
         $referenceToThisFound = TRUE;
         $propertyPath = substr($constraintDefinition['leftValue'], 5);
         $leftOperand = $this->getObjectValueByPath($result, $propertyPath);
     } else {
         $leftOperand = $this->getValueForOperand($constraintDefinition['leftValue']);
     }
     if (!is_array($constraintDefinition['rightValue']) && strpos($constraintDefinition['rightValue'], 'this.') === 0) {
         $referenceToThisFound = TRUE;
         $propertyPath = substr($constraintDefinition['rightValue'], 5);
         $rightOperand = $this->getObjectValueByPath($result, $propertyPath);
     } else {
         $rightOperand = $this->getValueForOperand($constraintDefinition['rightValue']);
     }
     if ($referenceToThisFound === FALSE) {
         throw new InvalidQueryRewritingConstraintException('An entity security constraint must have at least one operand that references to "this.". Got: "' . $constraintDefinition['leftValue'] . '" and "' . $constraintDefinition['rightValue'] . '"', 1277218400);
     }
     if (is_object($leftOperand) && ($this->reflectionService->isClassAnnotatedWith($this->reflectionService->getClassNameByObject($leftOperand), 'TYPO3\\Flow\\Annotations\\Entity') || $this->reflectionService->isClassAnnotatedWith($this->reflectionService->getClassNameByObject($leftOperand), 'Doctrine\\ORM\\Mapping\\Entity'))) {
         $originalLeftOperand = $leftOperand;
         $leftOperand = $this->persistenceManager->getIdentifierByObject($leftOperand);
     }
     if (is_object($rightOperand) && ($this->reflectionService->isClassAnnotatedWith($this->reflectionService->getClassNameByObject($rightOperand), 'TYPO3\\Flow\\Annotations\\Entity') || $this->reflectionService->isClassAnnotatedWith($this->reflectionService->getClassNameByObject($rightOperand), 'Doctrine\\ORM\\Mapping\\Entity'))) {
         $originalRightOperand = $rightOperand;
         $rightOperand = $this->persistenceManager->getIdentifierByObject($rightOperand);
     }
     switch ($constraintDefinition['operator']) {
         case '!=':
             return $leftOperand !== $rightOperand;
             break;
         case '==':
             return $leftOperand === $rightOperand;
             break;
         case '<':
             return $leftOperand < $rightOperand;
             break;
         case '>':
             return $leftOperand > $rightOperand;
             break;
         case '<=':
             return $leftOperand <= $rightOperand;
             break;
         case '>=':
             return $leftOperand >= $rightOperand;
             break;
         case 'in':
             if ($rightOperand instanceof Collection) {
                 return $rightOperand->contains(isset($originalLeftOperand) ? $originalLeftOperand : $leftOperand);
             }
             return in_array(isset($originalLeftOperand) ? $originalLeftOperand : $leftOperand, $rightOperand);
             break;
         case 'contains':
             if ($leftOperand instanceof Collection) {
                 return $leftOperand->contains(isset($originalRightOperand) ? $originalRightOperand : $rightOperand);
             }
             return in_array(isset($originalRightOperand) ? $originalRightOperand : $rightOperand, $leftOperand);
             break;
         case 'matches':
             if ($leftOperand instanceof Collection) {
                 $leftOperand = $leftOperand->toArray();
             }
             if ($rightOperand instanceof Collection) {
                 $rightOperand = $rightOperand->toArray();
             }
             return count(array_intersect($leftOperand, $rightOperand)) !== 0;
             break;
     }
     throw new InvalidQueryRewritingConstraintException('The configured operator of the entity constraint is not valid. Got: ' . $constraintDefinition['operator'], 1277222521);
 }