Download the PHP package penobit/linq without Composer

On this page you can find all versions of the php package penobit/linq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package linq

LinQ

Language-Integrated Query (LINQ) for PHP language

Installation

Usage

You can start using this package right away by importing your JSON data from a file:

Importing data from a PHP array or json string:

Or using short handed function

Example JSON Data

Let's have a quick example:

Let's say we want to get the Summation of price of the Queried result. We can do it easily by calling the sum() method instead of get():

That was easy, wasn't it?

API

Here is the list of available methods for querying.

Following API examples are shown based on the sample JSON data given here

List of API:

fetch()

This method will execute queries and will return the resulted data. You need to call it finally after using some query methods. Details can be found in other API examples like get().

find(path)

You don't need to call fetch() method after this. Because this method will fetch and return the data by itself.

caveat: You can't chain further query methods after it. If you need that, you should use at() or from() method.

example:

Let's say you want to get the value of 'cities' property of your Json Data. You can do it like this:

If you want to traverse to more deep in hierarchy, you can do it like:

from(path)

By default, query would be started from the root of the JSON Data you've given. If you want to first move to a nested path hierarchy of the data from where you want to start your query, you would use this method. Skipping the path parameter or giving '.' as parameter will also start query from the root Data.

Difference between this method and find() is that, find() method will return the data from the given path hierarchy. On the other hand, this method will return the Object instance, so that you can further chain query methods after it.

example:

Let's say you want to start query over the values of 'vendor.name' property of your JSON Data. You can do it like this:

If you want to traverse to more deep in hierarchy, you can do it like:

at(path)

This is an alias method of from() and will behave exactly like that.

where(key, condition, val)

example:

where(key, op, val)

Let's say you want to find the 'users' who has id of 1. You can do it like this:

You can add multiple where conditions. It'll give the result by AND-ing between these multiple where conditions.

callableWhere(fn)

Parameter of callableWhere() is callable function that should return a bool (true/false)

orCallableWhere(fn)

Parameter and behaviour of orCallableWhere() is the same as callableWhere()

orWhere(key, op, val)

Parameters of orWhere() are the same as where(). The only difference between where() and orWhere() is: condition given by the orWhere() method will OR-ed the result with other conditions.

For example, if you want to find the users with id of 1 or 2, you can do it like this:

whereIn(key, val)

This method will behave like where(key, 'in', val) method call.

whereNotIn(key, val)

This method will behave like where(key, 'notin', val) method call.

whereNull(key)

This method will behave like where(key, 'null') or where(key, '=', null) method call.

whereNotNull(key)

This method will behave like where(key, 'notnull') or where(key, '!=', null) method call.

whereStartsWith(key, val)

This method will behave like where(key, 'startswith', val) method call.

whereEndsWith(key, val)

This method will behave like where(key, 'endswith', val) method call.

whereContains(key, val)

This method will behave like where(key, 'contains', val) method call.

sum(column)

example:

Let's say you want to find the sum of the 'price' of the 'products'. You can do it like this:

If the data you are aggregating is plain array, you don't need to pass the 'column' parameter.

count()

It will return the number of elements in the collection.

example:

Let's say you want to find how many elements are in the 'products' property. You can do it like:

See detail example here.

size()

This is an alias method of count().

max(column)

example:

Let's say you want to find the maximum of the 'price' of the 'products'. You can do it like this:

If the data you are querying is plain array, you don't need to pass the 'column' parameter.

min(column)

example:

Let's say you want to find the minimum of the 'price' of the 'products'. You can do it like this:

If the data you are querying is plain array, you don't need to pass the 'property' parameter.

avg(column)

example:

Let's say you want to find the average of the 'price' of the 'products'. You can do it like this:

If the data you are querying is plain array, you don't need to pass the 'column' parameter.

first()

It will return the first element of the collection.

example:

last()

It will return the last element of the collection.

example:

nth(index)

It will return the nth element of the collection. If the given index is a positive value, it will return the nth element from the beginning. If the given index is a negative value, it will return the nth element from the end.

example:

exists()

It will return true if the element is not empty or not null or not an empty array or not an empty object.

example:

Let's say you want to find how many elements are in the 'products' property. You can do it like:

groupBy(column)

example:

Let's say you want to group the 'users' data based on the 'location' property. You can do it like:

See detail example here.

sort(order)

Note: This method should be used for plain Array. If you want to sort an Array of Objects you should use the sortBy() method described later.

example:

Let's say you want to sort the 'arr' data. You can do it like:

See detail example here.

sortBy(column, order)

Note: This method should be used for Array of Objects. If you want to sort a plain Array you should use the sort() method described earlier.

example:

Let's say you want to sort the 'price' data of 'products'. You can do it like:

reset(data)

At any point, you might want to reset the Object instance to a completely different set of data and then query over it. You can use this method in that case.

copy()

It will return a complete clone of the Object instance.

Example Files

There will be an example file for any of above methods soon.


All versions of linq with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
ext-json Version *
myclabs/deep-copy Version ^1.8
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package penobit/linq contains the following files

Loading the files please wait ....