Пример #1
0
 /**
  * @return array|bool
  * @throws BadRequestException
  */
 protected function handleGET()
 {
     if (empty($this->resource)) {
         return parent::handleGET();
     }
     $payload = $this->request->getPayloadData();
     if (false !== strpos($this->resource, '(')) {
         $inlineParams = strstr($this->resource, '(');
         $name = rtrim(strstr($this->resource, '(', true));
         $params = ArrayUtils::get($payload, 'params', trim($inlineParams, '()'));
     } else {
         $name = $this->resource;
         $params = ArrayUtils::get($payload, 'params', []);
     }
     $returns = ArrayUtils::get($payload, 'returns');
     $wrapper = ArrayUtils::get($payload, 'wrapper');
     $schema = ArrayUtils::get($payload, 'schema');
     return $this->callProcedure($name, $params, $returns, $schema, $wrapper);
 }
Пример #2
0
 /**
  * @return array
  * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
  * @throws \DreamFactory\Core\Exceptions\NotFoundException
  * @throws \DreamFactory\Core\Exceptions\RestException
  */
 protected function handleGet()
 {
     if (empty($this->resource)) {
         return parent::handleGET();
     }
     if (false === ($tableName = $this->doesTableExist($this->resource, true))) {
         throw new NotFoundException('Table "' . $this->resource . '" does not exist in the database.');
     }
     if (!empty($this->resourceId)) {
         //	Single resource by ID
         $result = $this->retrieveRecordById($tableName, $this->resourceId, $this->options);
         $this->triggerActionEvent($result);
         return $result;
     }
     if (!empty($ids = ArrayUtils::get($this->options, ApiOptions::IDS))) {
         //	Multiple resources by ID
         $result = $this->retrieveRecordsByIds($tableName, $ids, $this->options);
     } elseif (!empty($records = ResourcesWrapper::unwrapResources($this->payload))) {
         // passing records to have them updated with new or more values, id field required
         $result = $this->retrieveRecords($tableName, $records, $this->options);
     } else {
         $filter = ArrayUtils::get($this->options, ApiOptions::FILTER);
         $params = ArrayUtils::get($this->options, ApiOptions::PARAMS, []);
         $result = $this->retrieveRecordsByFilter($tableName, $filter, $params, $this->options);
     }
     $meta = ArrayUtils::get($result, 'meta');
     unset($result['meta']);
     $asList = $this->request->getParameterAsBool(ApiOptions::AS_LIST);
     $idField = $this->request->getParameter(ApiOptions::ID_FIELD, $this->getResourceIdentifier());
     $result = ResourcesWrapper::cleanResources($result, $asList, $idField, ApiOptions::FIELDS_ALL, !empty($meta));
     if (!empty($meta)) {
         $result['meta'] = $meta;
     }
     $this->triggerActionEvent($result);
     return $result;
 }
Пример #3
0
 /**
  * @return array|bool
  * @throws \DreamFactory\Core\Exceptions\NotFoundException
  */
 protected function handleGET()
 {
     $refresh = $this->request->getParameterAsBool(ApiOptions::REFRESH);
     if (empty($this->resource)) {
         $tables = $this->request->getParameter(ApiOptions::IDS);
         if (empty($tables)) {
             $tables = ResourcesWrapper::unwrapResources($this->request->getPayloadData());
         }
         if (!empty($tables)) {
             $result = $this->describeTables($tables, $refresh);
             $result = ResourcesWrapper::wrapResources($result);
         } else {
             $result = parent::handleGET();
         }
     } else {
         if (false === ($tableName = $this->doesTableExist($this->resource, true))) {
             throw new NotFoundException('Table "' . $this->resource . '" does not exist in the database.');
         }
         if (empty($this->resourceId)) {
             $result = $this->describeTable($tableName, $refresh);
         } else {
             $result = $this->describeField($tableName, $this->resourceId, $refresh);
         }
     }
     return $result;
 }