2017 © Pedro Peláez
 

package easyparse

query sting parser for rest apis supports filterations, sorting, fields, embeds

image

yehiahamid/easyparse

query sting parser for rest apis supports filterations, sorting, fields, embeds

  • Saturday, July 1, 2017
  • by yehiaa
  • Repository
  • 1 Watchers
  • 2 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 2 % Grown

The README.md

easyparser

Build Status, (*1)

easyparser is a simple query string parser for rest api php., (*2)

it's simply convert the QS to structured types., (*3)

you can parse your query string to filter, sort, get certain fields and embed resources, (*4)

installation using composer

composer require yehiahamid/easyparse, (*5)

Usage


//values must be inside single or double quotes if it contains white spaces or special chars 'what ever' | "what ever" $queryStringFilters = "@filters=name eq 'what ever',surname ne 'what ever'"; // otherwise you can use use the value without quotes // ex : $queryStringFilters = "@filters=id eq 12"; $queryStringFilters = "@filters=id eq anyWordsWithoutspacesOrSpecialChars"; //fields $queryStringFields = "@fields=name,surname,code"; //name is assc , surname desc $queryStringOrderBy = "@orderby=name,-surname"; //embed can contains fields,filters,sort and paging $queryStringEmbed = "@embed=resourceOne(@fields=name,code)(@filters=nameembed eq 'what ever'),mobiles(@orderby=sortFieldOne)"; $queryString = $queryStringFilters . "&" . $queryStringFields . "&" . $queryStringOrderBy . "&" . $queryStringEmbed; //in real app you would use $_SERVER['QUERY_STRING']; //this is optional param if not set it will use server query string $parser = new yehiaHamid\easyParse\QueryStringParser($queryString); $parser->fields(); //return array of fields | null if empty $parser->orderBy(); //return array of order by object | null if empty //Or you can set default value // use - before field for desc order $parser->orderBy("fieldOne,-field"); $filtersResult = $parser->filters(); //the filter object has three fields // the used query string in ex : "@filters=name eq 'what ever',surname ne 'what ever'" $filtersResult[0]->field // name $filtersResult[0]->operator // eq $filtersResult[0]->getOperator() // "=" $filtersResult[0]->value // 'what ever' $filtersResult[1]->field // surname $filtersResult[1]->operator // ne $filtersResult[1]->getOperator() // "!=" $filtersResult[1]->value // 'what ever' //Or you can set default value for each of the following $parser->offset(); $parser->limit(); $parser->perPage(); $parser->page(); // this new function return the value of required key , the key shouldn't be in reserved key words // reserved key words "field", "fields", "embed", "embeds", "filter", "filters", "orderby", "orderBy", "direction", "search" $parser->get("key"); // ex: $qs = "@anthThing=the value"; $parser->get("anthThing"); //returns the value // also you can pass second param for default value $parser->search(); //embed $embedResult = $parser->embed(); //return array of embed each object contains filters , sort , fields | empty array // the used query string in ex : //"@embed=resourceOne(@fields=name,code)(@filters=nameembed eq 'what ever'),mobiles(@orderby=sortFieldOne)" $embedResult[0]->resource // resourceOne $embedResult[0]->fields // array of fields [name,code] $embedResult[0]->filters // array of filters or empty array $embedResult[1]->resource // mobiles $embedResult[1]->orderBy // array of order by objects

available filtering operator

in Query string in result object
eq =
ne !=
gt >
lt <
like like
ilike ilike
le <=
ge >=

The Versions

01/07 2017

dev-master

9999999-dev

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid

01/07 2017

v1.0.8

1.0.8.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid

18/06 2017

v1.0.7

1.0.7.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

by Yehia Abdul Hamid

23/05 2016

v1.0.6

1.0.6.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

by Yehia Abdul Hamid

23/05 2016

dev-test-ci

dev-test-ci

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid

12/01 2016

v1.0.5

1.0.5.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid

27/12 2015

v1.0.4

1.0.4.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid

26/12 2015

v1.0.3

1.0.3.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid

22/12 2015

v1.0.2

1.0.2.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid

17/12 2015

v1.0.1

1.0.1.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid

16/12 2015

v1.0.0

1.0.0.0

query sting parser for rest apis supports filterations, sorting, fields, embeds

  Sources   Download

The Development Requires

by Yehia Abdul Hamid