Ejemplo n.º 1
0
 /**
  * Dump resource
  * Supported: array of objects, object, instance of Pager
  *
  * @param mixed $resource
  * 
  * @return Response
  */
 public function dump($resource)
 {
     $isPager = $resource instanceof Pager;
     $isArray = is_array($resource);
     if ($isPager || $isArray) {
         $r = new Records();
         $toStoreFunction = null;
         if ($isPager) {
             $entities = $resource->getEntities();
             $toStoreFunction = $resource->getToStoreFunction();
         } else {
             $entities = $resource;
         }
         $records = array();
         if (!empty($entities)) {
             foreach ($entities as $entity) {
                 if (!is_object($entity)) {
                     $records[] = $entity;
                 } else {
                     if (null === $toStoreFunction) {
                         $records[] = $this->dumpObject($entity);
                     } else {
                         $records[] = $toStoreFunction($entity);
                     }
                 }
             }
         }
         $r->result($records);
         if ($isPager) {
             $r->limit($resource->getLimit());
             $r->total($resource->getCount());
             $r->start($resource->getStart());
         }
         return $r;
     } elseif ($resource instanceof ArrayCollection || $resource instanceof PersistentCollection) {
         $records = array();
         foreach ($resource as $element) {
             $records[] = $this->dumpObject($element);
         }
         $r = new Success();
         $r->set("record", $records);
     } elseif (is_object($resource)) {
         $r = new Success();
         $r->set("record", $this->dumpObject($resource, array(), 'single'));
     } else {
         $r = new Success();
         $r->set("record", $resource);
     }
     return $r;
 }
 public function afterLoginAction()
 {
     $success = new Success();
     $content = json_encode($success->toArray());
     return new Response($content);
 }