Casts objects to arrays and adds the dynamic property prefix.
public static castObject ( object $obj, ReflectionClass $reflector ) : array | ||
$obj | object | The object to cast |
$reflector | ReflectionClass | The class reflector to use for inspecting the object definition |
Результат | array | The array-cast of the object, with prefixed dynamic properties |
public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested) { $prefix = Caster::PREFIX_VIRTUAL; $class = $stub->class; $flags = $c->getFlags(); $b = array($prefix . 'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST), $prefix . 'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS), $prefix . 'iteratorClass' => $c->getIteratorClass(), $prefix . 'storage' => $c->getArrayCopy()); if ($class === 'ArrayObject') { $a = $b; } else { if (!($flags & \ArrayObject::STD_PROP_LIST)) { $c->setFlags(\ArrayObject::STD_PROP_LIST); $a = Caster::castObject($c, new \ReflectionClass($class)); $c->setFlags($flags); } $a += $b; } return $a; }
/** * Casts an object to an array representation. * * @param Stub $stub The Stub for the casted object * @param bool $isNested True if the object is nested in the dumped structure * * @return array The object casted as array */ protected function castObject(Stub $stub, $isNested) { $obj = $stub->value; $class = $stub->class; if (isset($class[15]) && "" === $class[15] && 0 === strpos($class, "class@anonymous")) { $stub->class = get_parent_class($class) . '@anonymous'; } if (isset($this->classInfo[$class])) { $classInfo = $this->classInfo[$class]; } else { $classInfo = array(new \ReflectionClass($class), array_reverse(array($class => $class) + class_parents($class) + class_implements($class) + array('*' => '*'))); $classInfo[1] = array_map('strtolower', $classInfo[1]); $this->classInfo[$class] = $classInfo; } $a = Caster::castObject($obj, $classInfo[0]); foreach ($classInfo[1] as $p) { if (!empty($this->casters[$p])) { foreach ($this->casters[$p] as $p) { $a = $this->callCaster($p, $obj, $a, $stub, $isNested); } } } return $a; }