Beispiel #1
0
 /**
  * @test
  */
 public function isPropertyGettableWorksOnStdClass()
 {
     $stdClassObject = new \stdClass();
     $stdClassObject->property = 'foo';
     $this->assertTrue(\TYPO3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($stdClassObject, 'property'));
     $this->assertFalse(\TYPO3\FLOW3\Reflection\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) {
         $reflectionLoadMethod = new \ReflectionMethod($object, '__load');
         $reflectionLoadMethod->setAccessible(TRUE);
         $reflectionLoadMethod->invoke($object);
     }
     if (\TYPO3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($object, $propertyName)) {
         return \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($object, $propertyName);
     } else {
         return \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($object, $propertyName, TRUE);
     }
 }
 public function getStringByProperties($source)
 {
     $properties = $this->getProperties($source);
     $strings = array();
     $count = 0;
     foreach ($properties as $key => $meta) {
         if ($count > 3) {
             break;
         }
         if ($key !== "FLOW3_Persistence_Identifier") {
             if (\TYPO3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($source, $key)) {
                 $value = \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($source, $key);
                 if (is_string($value)) {
                     $strings[] = $value;
                     $count++;
                 } elseif (is_object($value) && $this->nestingLevel < 3) {
                     $this->nestingLevel++;
                     $string = $this->convertFrom($value, "string");
                     if (!is_null($string)) {
                         $strings[] = $string;
                         $count++;
                     }
                     $this->nestingLevel--;
                 }
             }
         }
     }
     if (!empty($strings)) {
         return implode(", ", $strings);
     }
     return false;
 }