Jsonq
in package
uses
JsonQueriable
Table of Contents
Properties
- $_baseContents : array<string|int, mixed>
- Stores base contents.
- $_conditions : array<string|int, mixed>
- Stores all conditions.
- $_except : array<string|int, mixed>
- contains column names for except
- $_isProcessed : bool
- $_map : mixed
- contain prepared data for process
- $_node : string|array<string|int, mixed>
- store node path
- $_rulesMap : array<string|int, mixed>
- map all conditions with methods
- $_select : array<string|int, mixed>
- contains column names
Methods
- __construct() : mixed
- this constructor set main json file path otherwise create it and read file contents and decode as an array and store it in $this->_data
- at() : $this
- Alias of from() method
- avg() : string
- getting average value from prepared data
- chunk() : object|array<string|int, mixed>|bool
- getting chunk values from prepared data
- collect() : jsonq
- import parsed data from raw json
- column() : object|array<string|int, mixed>
- getting specific key's value from prepared data
- copy() : Jsonq
- Deep copy current instance
- count() : int
- count prepared data
- countGroupBy() : mixed
- each() : mixed
- take action of each element of prepared data
- except() : $this
- select desired column for except
- exists() : bool
- check data exists in system
- fetch() : array<string|int, mixed>|object
- alias of get method
- filter() : mixed|array<string|int, mixed>
- filtered each element of prepared data
- find() : mixed
- getting data from desire path
- first() : object|array<string|int, mixed>|null
- getting first element of prepared data
- from() : $this
- Set node path, where JsonQ start to prepare
- get() : array<string|int, mixed>|object
- getting prepared data
- groupBy() : $this
- getting group data from specific column
- implode() : string|array<string|int, mixed>
- implode resulting data from desire key and delimeter
- import() : bool
- import data from file
- isJson() : bool|array<string|int, mixed>
- Check given value is valid JSON
- json() : jsonq
- import raw JSON data for process
- keys() : object|array<string|int, mixed>
- getting all keys from prepared data
- last() : object|array<string|int, mixed>|null
- getting last element of prepared data
- macro() : bool
- make macro for custom where clause
- max() : int
- getting max value from prepared data
- min() : string
- getting min value from prepared data
- nth() : object|array<string|int, mixed>|null
- getting nth number of element of prepared data
- orWhere() : $this
- make WHERE clause with OR
- pipe() : object|array<string|int, mixed>
- pipe send output in next pipe
- reProcess() : $this
- Our system will cache processed data and prevend multiple time processing. If you want to reprocess this method can help you
- reset() : jsonq
- reset given data to the $_map
- select() : $this
- select desired column
- size() : int
- size is an alias of count
- sort() : Jsonq
- Sort an array value
- sortBy() : object|array<string|int, mixed>|null
- sorting from prepared data
- sortByCallable() : object|array<string|int, mixed>|null
- Sort prepared data using a custom sort function.
- sum() : int
- sum prepared data
- takeColumn() : mixed
- then() : jsonq
- then method set position of working data
- toJson() : string
- getting raw JSON from prepared data
- transform() : object|array<string|int, mixed>
- transform prepared data by using callable function
- values() : object|array<string|int, mixed>
- getting all values from prepared data
- where() : $this
- make WHERE clause
- whereBool() : $this
- make WHERE Boolean clause
- whereContains() : $this
- make WHERE CONTAINS clause
- whereDate() : $this
- make WHERE DATE clause
- whereEndsWith() : $this
- make WHERE ENDS WITH clause
- whereIn() : $this
- make WHERE IN clause
- whereMatch() : $this
- make WHERE MATCH clause
- whereMonth() : $this
- make WHERE month clause
- whereNotIn() : $this
- make WHERE NOT IN clause
- whereNotNull() : $this
- make WHERE NOT NULL clause
- whereNull() : $this
- make WHERE NULL clause
- whereStartsWith() : $this
- make WHERE START WITH clause
- whereYear() : $this
- make WHERE Year clause
- exceptColumn() : array<string|int, mixed>
- selecting specific column
- getData() : mixed
- get data from node path
- getDataFromFile() : bool|string|array<string|int, mixed>
- Read JSON data from file
- getFromNested() : bool|array<string|int, mixed>|mixed
- Get data from nested array
- isMultiArray() : bool
- Check given value is multidimensional array
- makeImplode() : string|null
- process implode from resulting data
- makeWhere() : $this
- generator for AND and OR where
- objectToArray() : array<string|int, mixed>|mixed
- Parse object to array
- prepare() : $this
- Prepare data from desire conditions
- prepareResult() : array<string|int, mixed>|mixed
- Prepare data for result
- processConditions() : array<string|int, mixed>|string|object
- process AND and OR conditions
- selectColumn() : array<string|int, mixed>
- selecting specific column
Properties
$_baseContents
Stores base contents.
protected
array<string|int, mixed>
$_baseContents
= []
$_conditions
Stores all conditions.
protected
array<string|int, mixed>
$_conditions
= []
$_except
contains column names for except
protected
array<string|int, mixed>
$_except
= []
$_isProcessed
protected
bool
$_isProcessed
= false
$_map
contain prepared data for process
protected
mixed
$_map
$_node
store node path
protected
string|array<string|int, mixed>
$_node
= ''
$_rulesMap
map all conditions with methods
protected
static array<string|int, mixed>
$_rulesMap
= ['=' => 'equal', 'eq' => 'equal', '==' => 'strictEqual', 'seq' => 'strictEqual', '!=' => 'notEqual', 'neq' => 'notEqual', '!==' => 'strictNotEqual', 'sneq' => 'strictNotEqual', '>' => 'greaterThan', 'gt' => 'greaterThan', '<' => 'lessThan', 'lt' => 'lessThan', '>=' => 'greaterThanOrEqual', 'gte' => 'greaterThanOrEqual', '<=' => 'lessThanOrEqual', 'lte' => 'lessThanOrEqual', 'in' => 'in', 'notin' => 'notIn', 'null' => 'isNull', 'notnull' => 'isNotNull', 'startswith' => 'startWith', 'endswith' => 'endWith', 'match' => 'match', 'contains' => 'contains', 'dates' => 'dateEqual', 'month' => 'monthEqual', 'year' => 'yearEqual']
$_select
contains column names
protected
array<string|int, mixed>
$_select
= []
Methods
__construct()
this constructor set main json file path otherwise create it and read file contents and decode as an array and store it in $this->_data
public
__construct([null $jsonFile = null ]) : mixed
Parameters
- $jsonFile : null = null
Tags
at()
Alias of from() method
public
at([null $node = null ]) : $this
Parameters
- $node : null = null
Tags
Return values
$thisavg()
getting average value from prepared data
public
avg([int $column = null ]) : string
Parameters
- $column : int = null
Tags
Return values
stringchunk()
getting chunk values from prepared data
public
chunk(int $amount[, mixed $fn = null ]) : object|array<string|int, mixed>|bool
Parameters
- $amount : int
- $fn : mixed = null
Tags
Return values
object|array<string|int, mixed>|boolcollect()
import parsed data from raw json
public
collect(array<string|int, mixed>|object $data) : jsonq
Parameters
- $data : array<string|int, mixed>|object
Return values
jsonqcolumn()
getting specific key's value from prepared data
public
column(string $column) : object|array<string|int, mixed>
Parameters
- $column : string
Tags
Return values
object|array<string|int, mixed>copy()
Deep copy current instance
public
copy() : Jsonq
Return values
Jsonqcount()
count prepared data
public
count() : int
Tags
Return values
intcountGroupBy()
public
countGroupBy(mixed $column) : mixed
Parameters
- $column : mixed
each()
take action of each element of prepared data
public
each(callable $fn) : mixed
Parameters
- $fn : callable
Tags
except()
select desired column for except
public
except() : $this
Return values
$thisexists()
check data exists in system
public
exists() : bool
Tags
Return values
boolfetch()
alias of get method
public
fetch([bool $object = true ]) : array<string|int, mixed>|object
Parameters
- $object : bool = true
Tags
Return values
array<string|int, mixed>|objectfilter()
filtered each element of prepared data
public
filter(callable $fn[, bool $key = false ]) : mixed|array<string|int, mixed>
Parameters
- $fn : callable
- $key : bool = false
Tags
Return values
mixed|array<string|int, mixed>find()
getting data from desire path
public
find(string $path[, bool $object = false ]) : mixed
Parameters
- $path : string
- $object : bool = false
Tags
first()
getting first element of prepared data
public
first([bool $object = false ]) : object|array<string|int, mixed>|null
Parameters
- $object : bool = false
Tags
Return values
object|array<string|int, mixed>|nullfrom()
Set node path, where JsonQ start to prepare
public
from([null $node = null ]) : $this
Parameters
- $node : null = null
Tags
Return values
$thisget()
getting prepared data
public
get([bool $object = false ]) : array<string|int, mixed>|object
Parameters
- $object : bool = false
Tags
Return values
array<string|int, mixed>|objectgroupBy()
getting group data from specific column
public
groupBy(string $column) : $this
Parameters
- $column : string
Tags
Return values
$thisimplode()
implode resulting data from desire key and delimeter
public
implode(string|array<string|int, mixed> $key[, string $delimiter = ',' ]) : string|array<string|int, mixed>
Parameters
- $key : string|array<string|int, mixed>
- $delimiter : string = ','
Tags
Return values
string|array<string|int, mixed>import()
import data from file
public
import([string|null $file = null ]) : bool
Parameters
- $file : string|null = null
Tags
Return values
boolisJson()
Check given value is valid JSON
public
isJson(string $value[, bool $isReturnMap = false ]) : bool|array<string|int, mixed>
Parameters
- $value : string
- $isReturnMap : bool = false
Return values
bool|array<string|int, mixed>json()
import raw JSON data for process
public
json(string $data) : jsonq
Parameters
- $data : string
Return values
jsonqkeys()
getting all keys from prepared data
public
keys() : object|array<string|int, mixed>
Tags
Return values
object|array<string|int, mixed>last()
getting last element of prepared data
public
last([bool $object = false ]) : object|array<string|int, mixed>|null
Parameters
- $object : bool = false
Tags
Return values
object|array<string|int, mixed>|nullmacro()
make macro for custom where clause
public
static macro(string $name, callable $fn) : bool
Parameters
- $name : string
- $fn : callable
Return values
boolmax()
getting max value from prepared data
public
max([int $column = null ]) : int
Parameters
- $column : int = null
Tags
Return values
intmin()
getting min value from prepared data
public
min([int $column = null ]) : string
Parameters
- $column : int = null
Tags
Return values
stringnth()
getting nth number of element of prepared data
public
nth(int $index[, bool $object = false ]) : object|array<string|int, mixed>|null
Parameters
- $index : int
- $object : bool = false
Tags
Return values
object|array<string|int, mixed>|nullorWhere()
make WHERE clause with OR
public
orWhere([string $key = null ][, string $condition = null ][, mixed $value = null ]) : $this
Parameters
- $key : string = null
- $condition : string = null
- $value : mixed = null
Return values
$thispipe()
pipe send output in next pipe
public
pipe(callable $fn[, string|null $class = null ]) : object|array<string|int, mixed>
Parameters
- $fn : callable
- $class : string|null = null
Tags
Return values
object|array<string|int, mixed>reProcess()
Our system will cache processed data and prevend multiple time processing. If you want to reprocess this method can help you
public
reProcess() : $this
Return values
$thisreset()
reset given data to the $_map
public
reset([mixed $data = null ][, bool $instance = false ]) : jsonq
Parameters
- $data : mixed = null
- $instance : bool = false
Return values
jsonqselect()
select desired column
public
select() : $this
Return values
$thissize()
size is an alias of count
public
size() : int
Tags
Return values
intsort()
Sort an array value
public
sort([string $order = 'asc' ]) : Jsonq
Parameters
- $order : string = 'asc'
Return values
JsonqsortBy()
sorting from prepared data
public
sortBy(string $column[, string $order = 'asc' ]) : object|array<string|int, mixed>|null
Parameters
- $column : string
- $order : string = 'asc'
Tags
Return values
object|array<string|int, mixed>|nullsortByCallable()
Sort prepared data using a custom sort function.
public
sortByCallable(callable $sortFunc) : object|array<string|int, mixed>|null
Parameters
- $sortFunc : callable
Tags
Return values
object|array<string|int, mixed>|nullsum()
sum prepared data
public
sum([int $column = null ]) : int
Parameters
- $column : int = null
Tags
Return values
inttakeColumn()
public
takeColumn(mixed $array) : mixed
Parameters
- $array : mixed
then()
then method set position of working data
public
then(string $node) : jsonq
Parameters
- $node : string
Tags
Return values
jsonqtoJson()
getting raw JSON from prepared data
public
toJson() : string
Tags
Return values
stringtransform()
transform prepared data by using callable function
public
transform(callable $fn) : object|array<string|int, mixed>
Parameters
- $fn : callable
Tags
Return values
object|array<string|int, mixed>values()
getting all values from prepared data
public
values() : object|array<string|int, mixed>
Tags
Return values
object|array<string|int, mixed>where()
make WHERE clause
public
where(string $key[, string $condition = null ][, mixed $value = null ]) : $this
Parameters
- $key : string
- $condition : string = null
- $value : mixed = null
Return values
$thiswhereBool()
make WHERE Boolean clause
public
whereBool(string $key, mixed $value) : $this
Parameters
- $key : string
- $value : mixed
Return values
$thiswhereContains()
make WHERE CONTAINS clause
public
whereContains(string $key, string $value) : $this
Parameters
- $key : string
- $value : string
Return values
$thiswhereDate()
make WHERE DATE clause
public
whereDate(string $key, string $value) : $this
Parameters
- $key : string
- $value : string
Return values
$thiswhereEndsWith()
make WHERE ENDS WITH clause
public
whereEndsWith(string $key, string $value) : $this
Parameters
- $key : string
- $value : string
Return values
$thiswhereIn()
make WHERE IN clause
public
whereIn([string $key = null ][, array<string|int, mixed> $value = [] ]) : $this
Parameters
- $key : string = null
- $value : array<string|int, mixed> = []
Return values
$thiswhereMatch()
make WHERE MATCH clause
public
whereMatch(string $key, string $value) : $this
Parameters
- $key : string
- $value : string
Return values
$thiswhereMonth()
make WHERE month clause
public
whereMonth(string $key, string $value) : $this
Parameters
- $key : string
- $value : string
Return values
$thiswhereNotIn()
make WHERE NOT IN clause
public
whereNotIn([string $key = null ][, mixed $value = [] ]) : $this
Parameters
- $key : string = null
- $value : mixed = []
Return values
$thiswhereNotNull()
make WHERE NOT NULL clause
public
whereNotNull([string $key = null ]) : $this
Parameters
- $key : string = null
Return values
$thiswhereNull()
make WHERE NULL clause
public
whereNull([string $key = null ]) : $this
Parameters
- $key : string = null
Return values
$thiswhereStartsWith()
make WHERE START WITH clause
public
whereStartsWith(string $key, string $value) : $this
Parameters
- $key : string
- $value : string
Return values
$thiswhereYear()
make WHERE Year clause
public
whereYear(string $key, string $value) : $this
Parameters
- $key : string
- $value : string
Return values
$thisexceptColumn()
selecting specific column
protected
exceptColumn(mixed $array) : array<string|int, mixed>
Parameters
- $array : mixed
Return values
array<string|int, mixed>getData()
get data from node path
protected
getData() : mixed
getDataFromFile()
Read JSON data from file
protected
getDataFromFile(string $file[, string $type = 'application/json' ]) : bool|string|array<string|int, mixed>
Parameters
- $file : string
- $type : string = 'application/json'
Tags
Return values
bool|string|array<string|int, mixed>getFromNested()
Get data from nested array
protected
getFromNested(mixed $map, mixed $node) : bool|array<string|int, mixed>|mixed
Parameters
- $map : mixed
-
array
- $node : mixed
-
string
Return values
bool|array<string|int, mixed>|mixedisMultiArray()
Check given value is multidimensional array
protected
isMultiArray(array<string|int, mixed> $arr) : bool
Parameters
- $arr : array<string|int, mixed>
Return values
boolmakeImplode()
process implode from resulting data
protected
makeImplode(string $key, string $delimiter) : string|null
Parameters
- $key : string
- $delimiter : string
Return values
string|nullmakeWhere()
generator for AND and OR where
protected
makeWhere(string $key[, string $condition = null ][, mixed $value = null ]) : $this
Parameters
- $key : string
- $condition : string = null
- $value : mixed = null
Return values
$thisobjectToArray()
Parse object to array
protected
objectToArray(object $obj) : array<string|int, mixed>|mixed
Parameters
- $obj : object
Return values
array<string|int, mixed>|mixedprepare()
Prepare data from desire conditions
protected
prepare() : $this
Tags
Return values
$thisprepareResult()
Prepare data for result
protected
prepareResult(mixed $data, bool $isObject) : array<string|int, mixed>|mixed
Parameters
- $data : mixed
- $isObject : bool
Return values
array<string|int, mixed>|mixedprocessConditions()
process AND and OR conditions
protected
processConditions() : array<string|int, mixed>|string|object
Tags
Return values
array<string|int, mixed>|string|objectselectColumn()
selecting specific column
protected
selectColumn(mixed $array) : array<string|int, mixed>
Parameters
- $array : mixed