Exemplo n.º 1
0
 protected function export()
 {
     $cols = func_get_args();
     // add cols
     if (method_exists($this, 'hasRef') && $this->hasRef()) {
         $cols = array_merge(['$ref'], $cols);
     }
     // flatten array
     $fields = [];
     array_walk_recursive($cols, function ($a) use(&$fields) {
         $fields[] = $a;
     });
     $out = [];
     $refl = new \ReflectionClass(get_class($this));
     foreach ($fields as $field) {
         if ($field == 'tags') {
             $val = $this->exportTags();
         } else {
             $prop = $refl->getProperty($field == '$ref' ? 'ref' : $field);
             $prop->setAccessible(true);
             $val = $prop->getValue($this);
             if ($val instanceof Collection) {
                 $val = CollectionUtils::toArrayRecursive($val);
             } else {
                 if (is_object($val) && method_exists($val, 'toArray')) {
                     $val = $val->toArray();
                 }
             }
         }
         if ($field == 'required' && is_bool($val) || !empty($val)) {
             $out[$field] = $val;
         }
     }
     if (method_exists($this, 'getExtensions')) {
         $out = array_merge($out, $this->getExtensions()->toArray());
     }
     return $out;
 }
Exemplo n.º 2
0
 public function toArray()
 {
     return array_merge(CollectionUtils::toArrayRecursive($this->operations), CollectionUtils::toArrayRecursive($this->getExtensions()));
 }
Exemplo n.º 3
0
 public function testToRecursiveArray()
 {
     $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => ['x' => 'y', 'z' => 'zz']];
     $collection = CollectionUtils::fromCollection($data);
     $this->assertEquals($data, CollectionUtils::toArrayRecursive($collection));
 }
Exemplo n.º 4
0
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->headers);
 }
Exemplo n.º 5
0
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->definitions);
 }
Exemplo n.º 6
0
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->schemes);
 }
Exemplo n.º 7
0
 public function toArray()
 {
     $responses = clone $this->responses;
     $responses->setAll($this->getExtensions());
     return CollectionUtils::toArrayRecursive($responses);
 }