filter() публичный статический Метод

By default, a single match in the $filter bit field filters properties out, following an "or" logic. When EXCLUDE_STRICT is set, an "and" logic is applied: all bits must match for a property to be removed.
public static filter ( array $a, integer $filter, array $listedProperties = [], &$count ) : array
$a array The array containing the properties to filter
$filter integer A bit field of Caster::EXCLUDE_* constants specifying which properties to filter out
$listedProperties array List of properties to exclude when Caster::EXCLUDE_VERBOSE is set, and to preserve when Caster::EXCLUDE_NOT_IMPORTANT is set
Результат array The filtered array
Пример #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;
 }
Пример #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;
 }
Пример #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));
 }
Пример #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;
 }
Пример #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;
     }));
 }