/**
  * Set user information on the raven context
  */
 protected function setUserContext()
 {
     $objectManager = \TYPO3\Flow\Core\Bootstrap::$staticObjectManager;
     /** @var \TYPO3\Flow\Security\Context $securityContext */
     $securityContext = $objectManager->get('TYPO3\\Flow\\Security\\Context');
     $userContext = array();
     if ($securityContext->isInitialized()) {
         $account = $securityContext->getAccount();
         if ($account !== NULL) {
             $userContext['username'] = $account->getAccountIdentifier();
         }
         $party = $securityContext->getParty();
         if ($party instanceof Person && $party->getPrimaryElectronicAddress() !== NULL) {
             $userContext['email'] = (string) $party->getPrimaryElectronicAddress();
         } elseif ($party !== NULL && ObjectAccess::isPropertyGettable($party, 'emailAddress')) {
             $userContext['email'] = (string) ObjectAccess::getProperty($party, 'emailAddress');
         }
     }
     if ($userContext !== array()) {
         $this->client->user_context($userContext);
     }
 }
 /**
  * Returns the specified property.
  *
  * If the node has a content object attached, the property will be fetched
  * there if it is gettable.
  *
  * @param string $propertyName Name of the property
  * @param boolean $returnNodesAsIdentifiers If enabled, references to nodes are returned as node identifiers instead of NodeData objects
  * @param \TYPO3\TYPO3CR\Domain\Service\Context $context An optional Context if $returnNodesAsIdentifiers === TRUE
  * @return mixed value of the property
  * @throws \TYPO3\TYPO3CR\Exception\NodeException if the content object exists but does not contain the specified property.
  */
 public function getProperty($propertyName, $returnNodesAsIdentifiers = FALSE, \TYPO3\TYPO3CR\Domain\Service\Context $context = NULL)
 {
     if (!is_object($this->contentObjectProxy)) {
         $value = isset($this->properties[$propertyName]) ? $this->properties[$propertyName] : NULL;
         if (!empty($value)) {
             // TODO: The next two lines are workarounds, actually a NodeData cannot correctly return references but should always return identifier. Node should then apply the context and return the real Node objects.
             $dimensions = $context !== NULL ? $context->getDimensions() : array();
             $workspace = $context !== NULL ? $context->getWorkspace() : $this->getWorkspace();
             switch ($this->getNodeType()->getPropertyType($propertyName)) {
                 case 'references':
                     $nodeDatas = array();
                     if (!is_array($value)) {
                         $value = array();
                     }
                     $valueNeedsToBeFixed = FALSE;
                     foreach ($value as $nodeIdentifier) {
                         // in cases where a reference is a NodeData instance, fix this
                         if ($nodeIdentifier instanceof NodeData) {
                             $nodeIdentifier = $nodeIdentifier->getIdentifier();
                             $valueNeedsToBeFixed = TRUE;
                         }
                         if ($returnNodesAsIdentifiers === FALSE) {
                             $nodeData = $this->nodeDataRepository->findOneByIdentifier($nodeIdentifier, $workspace, $dimensions);
                             if ($nodeData instanceof NodeData) {
                                 $nodeDatas[] = $nodeData;
                             }
                         } else {
                             $nodeDatas[] = $nodeIdentifier;
                         }
                     }
                     if ($valueNeedsToBeFixed === TRUE) {
                         $fixedValue = array();
                         foreach ($value as $nodeIdentifier) {
                             if ($nodeIdentifier instanceof NodeData) {
                                 $fixedValue[] = $nodeIdentifier->getIdentifier();
                             } else {
                                 $fixedValue[] = $nodeIdentifier;
                             }
                         }
                         $this->properties[$propertyName] = $fixedValue;
                         $this->update();
                     }
                     $value = $nodeDatas;
                     break;
                 case 'reference':
                     // in cases where a reference is a NodeData instance, fix this
                     if ($value instanceof NodeData) {
                         $value = $value->getIdentifier();
                         $this->properties[$propertyName] = $value;
                         $this->update();
                     }
                     if ($returnNodesAsIdentifiers === FALSE) {
                         $nodeData = $this->nodeDataRepository->findOneByIdentifier($value, $workspace, $dimensions);
                         if ($nodeData instanceof NodeData) {
                             $value = $nodeData;
                         } else {
                             $value = NULL;
                         }
                     }
                     break;
             }
         }
         return $value;
     } elseif (ObjectAccess::isPropertyGettable($this->contentObjectProxy->getObject(), $propertyName)) {
         return ObjectAccess::getProperty($this->contentObjectProxy->getObject(), $propertyName);
     }
     throw new \TYPO3\TYPO3CR\Exception\NodeException(sprintf('Property "%s" does not exist in content object of type %s.', $propertyName, get_class($this->contentObjectProxy->getObject())), 1291286995);
 }
 /**
  * Load the property value to be used for validation.
  *
  * In case the object is a doctrine proxy, we need to load the real instance first.
  *
  * @param object $object
  * @param string $propertyName
  * @return mixed
  */
 protected function getPropertyValue($object, $propertyName)
 {
     if ($object instanceof \Doctrine\ORM\Proxy\Proxy) {
         $object->__load();
     }
     if (ObjectAccess::isPropertyGettable($object, $propertyName)) {
         return ObjectAccess::getProperty($object, $propertyName);
     } else {
         return ObjectAccess::getProperty($object, $propertyName, true);
     }
 }
 /**
  * Returns the specified property.
  *
  * If the node has a content object attached, the property will be fetched
  * there if it is gettable.
  *
  * @param string $propertyName Name of the property
  * @return mixed value of the property
  * @throws \TYPO3\TYPO3CR\Exception\NodeException if the content object exists but does not contain the specified property.
  */
 public function getProperty($propertyName)
 {
     if (!is_object($this->contentObjectProxy)) {
         $value = isset($this->properties[$propertyName]) ? $this->properties[$propertyName] : null;
         if (!empty($value)) {
             if ($this->getNodeType()->getPropertyType($propertyName) === 'references') {
                 if (!is_array($value)) {
                     $value = array();
                 }
             }
         }
         return $value;
     } elseif (ObjectAccess::isPropertyGettable($this->contentObjectProxy->getObject(), $propertyName)) {
         return ObjectAccess::getProperty($this->contentObjectProxy->getObject(), $propertyName);
     }
     throw new \TYPO3\TYPO3CR\Exception\NodeException(sprintf('Property "%s" does not exist in content object of type %s.', $propertyName, get_class($this->contentObjectProxy->getObject())), 1291286995);
 }
Esempio n. 5
0
 /**
  * @param $current
  * @param $new
  * @param $key
  * @return array|bool
  */
 public static function diffString($current, $new, $key)
 {
     $result = array();
     if ($current === $new) {
         // unchanged string, we don't need a diff
         return FALSE;
     } else {
         // values are not identical
         if (is_string($current) && is_string($new)) {
             // string to new string
             $result['reason'] = 'A';
             $result['key'] = ucfirst($key);
             $result['current'] = $current;
             $result['new'] = $new;
         } elseif (!$current && is_string($new)) {
             // NULL to string
             $result['reason'] = 'C';
             $result['key'] = ucfirst($key);
             $result['new'] = $new;
         } elseif (is_array($current)) {
             // array to empty, array to string
             $result['reason'] = 'D';
             $result['key'] = ucfirst($key);
             $result['current'] = implode("\n", $current);
             $result['new'] = $new;
         } elseif (is_object($current)) {
             if (ObjectAccess::isPropertyGettable($current, 'filename')) {
                 $filename = ObjectAccess::getProperty($current, 'filename');
                 // file resource to empty
                 $result['reason'] = 'J';
                 $result['key'] = ucfirst($key);
                 $result['current'] = $filename;
                 $result['new'] = $new;
             }
         } else {
             return FALSE;
         }
     }
     return $result;
 }
 /**
  * @test
  */
 public function isPropertyGettableWorksOnStdClass()
 {
     $stdClassObject = new \stdClass();
     $stdClassObject->property = 'foo';
     $this->assertTrue(ObjectAccess::isPropertyGettable($stdClassObject, 'property'));
     $this->assertFalse(ObjectAccess::isPropertyGettable($stdClassObject, 'undefinedProperty'));
 }
 /**
  * Load the property value to be used for validation.
  *
  * In case the object is a doctrine proxy, we need to load the real instance first.
  *
  * @param object $object
  * @param string $propertyName
  * @return mixed
  */
 protected function getPropertyValue($object, $propertyName)
 {
     if ($object instanceof \Doctrine\ORM\Proxy\Proxy) {
         $object->__load();
     }
     if (\TYPO3\Flow\Reflection\ObjectAccess::isPropertyGettable($object, $propertyName)) {
         return \TYPO3\Flow\Reflection\ObjectAccess::getProperty($object, $propertyName);
     } else {
         return \TYPO3\Flow\Reflection\ObjectAccess::getProperty($object, $propertyName, TRUE);
     }
 }