Author: Nicolas Grekas (p@tchwork.com)
Exemplo n.º 1
0
 /**
  * @param ModelBase $model
  * @param array $a
  * @param Stub $stub
  * @param bool $isNested
  *
  * @return array
  */
 public static function cast(ModelBase $model, array $a, Stub $stub, bool $isNested)
 {
     if ($isNested) {
         $a = Caster::filter($a, Caster::EXCLUDE_VERBOSE, ["" . '*' . "" . 'changedProperties']);
     }
     return $a;
 }
Exemplo n.º 2
0
 /**
  * @param Base $model
  * @param array $a
  * @param Stub $stub
  * @param bool $isNested
  *
  * @return array
  */
 public static function cast(Base $model, array $a, Stub $stub, bool $isNested)
 {
     if ($isNested) {
         $a = Caster::filter($a, Caster::EXCLUDE_VERBOSE, ["" . Base::class . "" . 'added', "" . Base::class . "" . 'removed']);
     }
     return $a;
 }
Exemplo n.º 3
0
 /** @dataProvider provideFilter */
 public function testFilter($filter, $expectedDiff, $listedProperties = null)
 {
     if (null === $listedProperties) {
         $filteredArray = Caster::filter($this->referenceArray, $filter);
     } else {
         $filteredArray = Caster::filter($this->referenceArray, $filter, $listedProperties);
     }
     $this->assertSame($expectedDiff, array_diff_assoc($this->referenceArray, $filteredArray));
 }
Exemplo n.º 4
0
 public static function castXmlReader(\XmlReader $reader, array $a, Stub $stub, $isNested)
 {
     $props = Caster::PREFIX_VIRTUAL . 'parserProperties';
     $info = array('localName' => $reader->localName, 'prefix' => $reader->prefix, 'nodeType' => new ConstStub(self::$nodeTypes[$reader->nodeType], $reader->nodeType), 'depth' => $reader->depth, 'isDefault' => $reader->isDefault, 'isEmptyElement' => \XmlReader::NONE === $reader->nodeType ? null : $reader->isEmptyElement, 'xmlLang' => $reader->xmlLang, 'attributeCount' => $reader->attributeCount, 'value' => $reader->value, 'namespaceURI' => $reader->namespaceURI, 'baseURI' => $reader->baseURI, $props => array('LOADDTD' => $reader->getParserProperty(\XmlReader::LOADDTD), 'DEFAULTATTRS' => $reader->getParserProperty(\XmlReader::DEFAULTATTRS), 'VALIDATE' => $reader->getParserProperty(\XmlReader::VALIDATE), 'SUBST_ENTITIES' => $reader->getParserProperty(\XmlReader::SUBST_ENTITIES)));
     if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, array(), $count)) {
         $info[$props] = new EnumStub($info[$props]);
         $info[$props]->cut = $count;
     }
     $info = Caster::filter($info, Caster::EXCLUDE_EMPTY, array(), $count);
     // +2 because hasValue and hasAttributes are always filtered
     $stub->cut += $count + 2;
     return $a + $info;
 }
Exemplo n.º 5
0
 public function __construct(OutputFormatter $formatter)
 {
     $this->dumper = new Dumper($formatter);
     $this->dumper->setStyles($this->styles);
     $this->cloner = new Cloner();
     $this->cloner->addCasters(array('*' => function ($obj, array $a, Stub $stub, $isNested, $filter = 0) {
         if ($filter || $isNested) {
             if ($obj instanceof \Exception) {
                 $a = Caster::filter($a, Caster::EXCLUDE_NOT_IMPORTANT | Caster::EXCLUDE_EMPTY, $this->exceptionsImportants);
             } else {
                 $a = Caster::filter($a, Caster::EXCLUDE_PROTECTED | Caster::EXCLUDE_PRIVATE);
             }
         }
         return $a;
     }));
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 /**
  * 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;
 }