예제 #1
0
 protected function copyData(Builder $copy)
 {
     foreach ($this->fields as $name => $field) {
         $new = $field->copy();
         if ($new->isType(Field::TYPE_RELATION)) {
             $new->getRelated()->setParent($copy);
         }
         $copy->fields[$name] = $new;
     }
     $copy->listeners = $this->listeners;
     if ($this->constr !== null) {
         $copy->constr = $this->constr->copy();
         $copy->constr->setParent($copy);
     }
     $copy->parent_links = $this->parent_links;
 }
예제 #2
0
 /**
  * @param \ReflectionMethod $constructor
  * @param array             $data
  * @return array
  * @throws SampleException
  */
 private function alignArgs(\ReflectionMethod $constructor, array $data, ConstructorBuilder $builder)
 {
     if ($builder->isPositional()) {
         $aligned = $data;
     } else {
         $aligned = [];
         foreach ($constructor->getParameters() as $param) {
             if (isset($data[$param->getName()])) {
                 $aligned[] = $data[$param->getName()];
             } else {
                 try {
                     $aligned[] = $param->getDefaultValue();
                 } catch (\ReflectionException $e) {
                     throw new SampleException("No value provided for argument {$param->getName()}", 0, $e);
                 }
             }
         }
     }
     if (count($aligned) < $constructor->getNumberOfRequiredParameters()) {
         throw new SampleException("Not enough arguments provided for constructing the object");
     }
     return $aligned;
 }