예제 #1
0
 /**
  * Insert one new record using the Entity class.
  * @param Mandango $mandango
  */
 public function execute(Mandango $mandango, $insertedEntities)
 {
     $metadata = $mandango->getMetadata($this->class);
     $obj = $mandango->create($this->class);
     foreach ($this->columnFormatters as $column => $format) {
         if (null !== $format) {
             $value = is_callable($format) ? $format($insertedEntities, $obj) : $format;
             if (isset($metadata['fields'][$column]) || isset($metadata['referencesOne'][$column])) {
                 $obj->set($column, $value);
             }
             if (isset($metadata['referencesMany'][$column])) {
                 $adder = 'add' . ucfirst($column);
                 $obj->{$adder}($value);
             }
         }
     }
     $mandango->persist($obj);
     return $obj;
 }