Example #1
0
 /**
  * Creates entity object of resource, runs it method and return response
  *
  * @param  string   $entity_properties Properties of entity
  * @param  string   $parent_name       Parent entity name
  * @param  array    $parent_data       Parent entity data
  * @return Response Response or null
  */
 private function getResponseFromEntity($entity_properties, $parent_name = null, $parent_data = null)
 {
     $response = null;
     $entity = $this->getObjectByEntity($entity_properties);
     /**
      * Fake entity can't have parent
      */
     if ($entity !== null || isset($this->fake_entities[$entity_properties['name']]) && !$parent_data) {
         if (!empty($parent_data['data'])) {
             $entity->setParentName($parent_name);
             $entity->setParentData($parent_data['data']);
         }
         if (!empty($entity_properties['id']) && !$entity->isValidIdentifier($entity_properties['id'])) {
             $response = null;
         } elseif (!empty($entity_properties['child_entity'])) {
             $parent_result = array('status' => Response::STATUS_FORBIDDEN);
             if ($this->checkAccess($entity, 'index')) {
                 $parent_result = $entity->index($entity_properties['id']);
             }
             if (Response::isSuccessStatus($parent_result['status'])) {
                 $name = $entity_properties['name'];
                 $entity_properties = $this->getEntityFromPath($entity_properties['child_entity']);
                 $response = $this->getResponseFromEntity($entity_properties, $name, $parent_result);
             } else {
                 $response = new Response($parent_result['status']);
             }
         } else {
             $response = $this->exec($entity, $entity_properties);
         }
     } else {
         $response = new Response(Response::STATUS_NOT_FOUND, __('object_not_found', array('[object]' => __('entity') . ' ' . $entity_properties['name'])), $this->request->getAcceptType());
     }
     return $response;
 }