Marcelgwerder\ApiHandler\Parser::parse PHP Метод

parse() публичный Метод

Either for a single dataset or multiple.
public parse ( mixed $options, boolean $multiple = false ) : void
$options mixed
$multiple boolean
Результат void
    public function parse($options, $multiple = false)
    {
        $this->multiple = $multiple;
        if ($multiple) {
            $fullTextSearchColumns = $options;
            //Parse and apply offset using the laravel "offset" function
            if ($offset = $this->getParam('offset')) {
                $offset = intval($offset);
                $this->query->offset($offset);
            }
            //Parse and apply limit using the laravel "limit" function
            if ($limit = $this->getParam('limit')) {
                $limit = intval($limit);
                $this->query->limit($limit);
            }
            //Parse and apply the filters using the different laravel "where" functions
            //Every parameter that has not a predefined functionality gets parsed as a filter
            if ($filterParams = $this->getFilterParams()) {
                $this->parseFilter($filterParams);
            }
            //Parse an apply the fulltext search using the different laravel "where" functions
            //The fulltext search is only applied to the columns passed by $fullTextSearchColumns.
            if ($this->getParam('q') !== false) {
                $this->parseFulltextSearch($this->getParam('q'), $fullTextSearchColumns);
            }
        } else {
            $identification = $options;
            if (is_numeric($identification)) {
                $this->query->where('id', $identification);
            } else {
                if (is_array($identification)) {
                    foreach ($identification as $column => $value) {
                        $this->query->where($column, $value);
                    }
                }
            }
        }
        //Parse and apply field elements using the laravel "select" function
        //The needed fields for the with function (Primary and foreign keys) have to be added accordingly
        if ($fields = $this->getParam('fields')) {
            $this->parseFields($fields);
        }
        //Parse and apply sort elements using the laravel "orderBy" function
        if ($sort = $this->getParam('sort')) {
            $this->parseSort($sort);
        }
        //Parse and apply with elements using the Laravel "with" function
        if (($with = $this->getParam('with')) && $this->isEloquentBuilder) {
            $this->parseWith($with);
        }
        //Parse the config params
        if ($config = $this->getParam('config')) {
            $this->parseConfig($config);
        }
        if ($this->isEloquentBuilder) {
            //Attach the query builder object back to the eloquent builder object
            $this->builder->setQuery($this->query);
        }
    }

Usage Example

 /**
  * Return a new Result object for multiple datasets
  *
  * @param  mixed            $queryBuilder          Some kind of query builder instance
  * @param  array            $fullTextSearchColumns Columns to search in fulltext search
  * @param  array|boolean    $queryParams           A list of query parameter
  * @return Result
  */
 public function parseMultiple($queryBuilder, $fullTextSearchColumns = array(), $queryParams = false)
 {
     if ($queryParams === false) {
         $queryParams = Input::get();
     }
     $parser = new Parser($queryBuilder, $queryParams);
     $parser->parse($fullTextSearchColumns, true);
     return new Result($parser);
 }