isPropertyArray() public static method

Determine if a property in a given class is a collection type.
public static isPropertyArray ( string $class, string $propertyName ) : string
$class string
$propertyName string
return string
Esempio n. 1
0
 /**
  * @param array $map
  * @param string $prefix
  */
 public function init(array $map = array(), $prefix = '')
 {
     if (empty($map)) {
         return;
     }
     $map = PPUtils::lowerKeys($map);
     foreach (get_object_vars($this) as $property => $defaultValue) {
         if (array_key_exists($propKey = strtolower($prefix . $property), $map) && $this->isBuiltInType($type = PPUtils::propertyType($this, $property))) {
             $type = PPUtils::propertyType($this, $property);
             $this->{$property} = urldecode($map[$propKey]);
             continue;
             // string
         } elseif (!($filtered = PPUtils::filterKeyPrefix($map, $propKey))) {
             continue;
             // NULL
         }
         if (!class_exists($type = PPUtils::propertyType($this, $property)) && !$this->isBuiltInType($type)) {
             trigger_error("Class {$type} not found.", E_USER_NOTICE);
             continue;
             // just ignore
         }
         if (is_array($defaultValue) || PPUtils::isPropertyArray($this, $property)) {
             // array of objects
             if ($this->isBuiltInType($type)) {
                 // Array of simple types
                 foreach ($filtered as $key => $value) {
                     $this->{$property}[trim($key, "()")] = urldecode($value);
                 }
             } else {
                 // Array of complex objects
                 $delim = '.';
                 for ($i = 0; $itemValues = PPUtils::filterKeyPrefix($filtered, "({$i})"); $i++) {
                     $this->{$property}[$i] = $item = new $type();
                     $item->init(PPUtils::filterKeyPrefix($itemValues, "."));
                     if (array_key_exists("", $itemValues)) {
                         $item->value = urldecode($itemValues[""]);
                     }
                 }
                 // Handle cases where we have a list of objects
                 // with just the value present and all attributes values are null
                 foreach ($filtered as $key => $value) {
                     $idx = trim($key, "()");
                     if (is_numeric($idx) && (is_null($this->{$property}) || !array_key_exists($idx, $this->{$property}))) {
                         $this->{$property}[$idx] = new $type();
                         $this->{$property}[$idx]->value = urldecode($value);
                     }
                 }
             }
         } else {
             // one object
             $this->{$property} = new $type();
             $this->{$property}->init(PPUtils::filterKeyPrefix($filtered, '.'));
             // unprefix
             if (array_key_exists("", $filtered)) {
                 $this->{$property}->value = urldecode($filtered[""]);
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * @test
  */
 public function testGetPropertyType()
 {
     $this->assertEquals('string', PPUtils::propertyType('MockReflectionTestType', 'noAnnotations'));
     $this->assertEquals('SomeType', PPUtils::propertyType('MockReflectionTestType', 'value'));
     $this->assertEquals(true, PPUtils::isPropertyArray('MockReflectionTestType', 'arrayMember'));
     $this->assertEquals(false, PPUtils::isPropertyArray('MockReflectionTestType', 'value'));
 }
Esempio n. 3
0
 /**
  * @param array $map intermediate array representation of XML message to deserialize
  * @param string $isRoot true if this is a root class for SOAP deserialization
  */
 public function init(array $map = array(), $isRoot = true)
 {
     if ($isRoot) {
         if (stristr($map[0]['name'], ":fault")) {
             throw new PPTransformerException("soapfault");
         } else {
             $map = $map[0]['children'];
         }
     }
     if (empty($map)) {
         return;
     }
     if (($first = reset($map)) && !is_array($first) && !is_numeric(key($map))) {
         parent::init($map, false);
         return;
     }
     $propertiesMap = PPUtils::objectProperties($this);
     $arrayCtr = array();
     foreach ($map as $element) {
         if (empty($element) || empty($element['name'])) {
             continue;
         } elseif (!array_key_exists($property = strtolower($element['name']), $propertiesMap)) {
             if (!preg_match('~^(.+)[\\[\\(](\\d+)[\\]\\)]$~', $property, $m)) {
                 continue;
             }
             $element['name'] = $m[1];
             $element['num'] = $m[2];
         }
         $element['name'] = $propertiesMap[strtolower($element['name'])];
         if (PPUtils::isPropertyArray($this, $element['name'])) {
             $arrayCtr[$element['name']] = isset($arrayCtr[$element['name']]) ? $arrayCtr[$element['name']] + 1 : 0;
             $element['num'] = $arrayCtr[$element['name']];
         }
         if (!empty($element["attributes"]) && is_array($element["attributes"])) {
             foreach ($element["attributes"] as $key => $val) {
                 $element["children"][] = array('name' => $key, 'text' => $val);
             }
             if (isset($element['text'])) {
                 $element["children"][] = array('name' => 'value', 'text' => $element['text']);
             }
             $this->fillRelation($element['name'], $element);
         } elseif (isset($element['text']) && !is_null($element['text'])) {
             if (isset($element['num'])) {
                 $this->{$element['name']}[$element['num']] = $element['text'];
             } else {
                 $this->{$element['name']} = $element['text'];
             }
         } elseif (!empty($element["children"]) && is_array($element["children"])) {
             $this->fillRelation($element['name'], $element);
         }
     }
 }