Пример #1
0
 /**
  * @param array   $data
  * @param Builder $builder
  * @return array|object
  * @throws SampleException
  */
 private function insertInObject(array $data, Builder $builder)
 {
     // special case for arrays: just return the array data
     if ($builder->getType() === 'array' || $builder->getType() === '__construct') {
         return $this->replaceLinksInArray($data, $builder);
     }
     // special case for generic objects (objects of type stdClass): just cast as an object
     if ($builder->getType() === 'object' || $builder->getType() === 'stdClass') {
         return $this->replaceLinksInObject((object) $data, $builder);
     }
     $refl = new \ReflectionClass($builder->getClass());
     $obj = $this->constructObject($refl, $builder);
     foreach ($data as $key => $val) {
         $this->setObjectProperty($obj, $key, $val, $builder);
     }
     return $obj;
 }