Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $blueprint = ['stub' => $this->argument('stub'), 'namespace' => $this->argument('namespace'), 'class' => $this->argument('class'), 'path' => $this->argument('path')];
     $result = $this->b->fromArray($blueprint);
     if ($result = true) {
         $this->info('Class ' . $this->argument('class') . ' is created successfully.');
     } else {
         $this->info('Failed to create ' . $this->argument('class') . ' in ' . addslashes($this->argument('path')));
     }
 }
Ejemplo n.º 2
0
 /**
  * Populates the given object with data from the given array.
  *
  * @param object $object Object to be populated.
  * @param array  $data   Data to populate the object with.
  */
 public function fromArray($object, array $data)
 {
     $object->fromArray($data);
 }
Ejemplo n.º 3
0
 /**
  * Patch update fields
  * 
  * @param object $entity
  * @todo Support patching of transformed form params
  */
 protected function patch($entity)
 {
     if (empty($this->patchWhitelist)) {
         return $this->view(array('errors' => array('No field is allowed to be patch updated.')), 400);
     }
     $parameters = array();
     foreach ($this->getRequest()->request->all() as $k => $v) {
         // whitelist
         if (in_array($k, $this->patchWhitelist)) {
             $parameters[$k] = $v;
         }
     }
     if (0 === count($parameters)) {
         return $this->view(array('errors' => array('Invalid parameters.')), 400);
     }
     $entity->fromArray($parameters);
     $errors = $this->get('validator')->validate($entity);
     if (0 < count($errors)) {
         return $this->view(array('errors' => $errors), 400);
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($entity);
     try {
         $em->flush();
     } catch (\Exception $e) {
         return $this->view($e->getMessage(), 400);
     }
 }