Download the PHP package remipelhate/distil without Composer

On this page you can find all versions of the php package remipelhate/distil. 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 distil

Build Status StyleCI

Distil provides a simple API to describe a variable number of conditions that should be met by a result set in PHP. This, for example, makes dynamically constructing queries through small value objects a breeze.

Getting Started

Simple Example

Let's consider the following scenario: you have a query object GetPosts that returns all posts of your blog by default. However, you only need to retrieve posts from a specific author on some places. The query itself is identical, you only need to strip out the ones that were created by anyone other than the given author. To do so, the query object can accept criteria that may or may not hold the "author" criterion:

The query object internals can then append statements to the query depending of the given criteria. Distil only describes the criteria, you can interpret them however you want. You're fully in control:

This approach comes in handy when you need to pass along a variable number of criteria to a single query. Imagine we'd use that GetPosts query object to expose those posts through an API and allow users to filter them by author, publish_date, ... and eventually sort them differently:

Requirements

Installation

You can install this package through Composer:

Concepts

Criteria

Criteria is a collection of conditionals that describe which records should be included within a result set (filtering, limiting, ...) or how it should be presented (e.g. sorting). Distil represents these single conditionals within the Distil\Criteria collection as Distil\Criterion instances (see next chapter).

Adding Criteria

Let's reconsider the example at the top of the docs. Imagine we'd want to retrieve all posts from author with ID 1 and sort them in ascending order of the publish_date. You can pass along Criterion instances on construction:

… or fluently through the add() method:

Each Criterion instance within the collection is unique by name. add() does not allow to overwrite an instance in the collection with another one carrying the same name. If you event need to overwrite one, you can use the set() method:

Getting Criteria

You can check if it contains a Criterion instance by name:

... and get it:

Array Access

Distil\Criteria implements PHP's ArrayAccess interface, meaning you can interact with it as an array:

Criterion

A Criterion is a single condition to which a result set should adhere. Think of a filter, a limit, sorting, ... Distil represents these as small value objects (identified by a unique name) that wrap around a single value. Those objects must implement the Distil\Criterion interface.

Example

Once more, let's go back to our example at the top of the docs and create that author filter for the query object. This filter holds the ID of an author:

Typed Criteria

Distil ships with a set of strictly typed abstract classes that you can use to add some default behaviour to your Criterion implementations:

Each of these can:

So, we can simplify our Author filter from above as such:

Keywords

When creating a Distil\Criterion from a string, you can't always cast that string value to the appropriate value type. Therefor, Distil allows you to define keywords for some specific values.

Working with keyword values

Let's illustrate this with an example and create a Limit filter. The value contained by this filter should either be an integer or null (aka, there is no limit):

If we were to offer this as a filter on, for example, a public API, we'd want to be able to resolve limit=unlimited to new Limit(null). 'unlimited' can't be naturally casted to a null value, so we need to register it as a keyword. To do so, our limit Criterion needs to implement the Distil\Keywords\HasKeywords interface, which requires you to define a keywords() method:

Note the usage of the Distil\Keywords\Keyword class in our fromString() constructor. It's a small value object that accepts the Criterion class name and the given string value on construction. Using the keywords() method, it can check whether or not the given string value is a keyword for another value. If it is, the actual value will be returned:

Now, imagine you'd want to be able to cast the Criterion value back to a string. Using the Distil\Keywords\Value class, you can easily derive the keyword for a value:

If the value is associated with a keyword, the keyword will be returned. If it isn't, we'll get null:

Note: Limit was simply used here as an example. It's actually available out of the box. Make sure to check out the Common Criteria section.

Keywords on Typed Criteria

As mentioned in the Typed Criteria section, any Criterion instance that extends either one of the Distil\Types automatically handles keywords when created from or casted to a string. This means you only need to implement the Distil\Keywords\HasKeywords interface without having to overwrite the fromString() or __toString() methods.

In addition, any instances of Distil\Types\BooleanCriterion will automatically handle 'true' and 'false' string values.

Common Criteria

Distil provides a couple of common criteria out of the box:

Limit

Distil\Common\Limit is Criterion implementation that wraps around an integer or null value. It does not extend a Criterion Type, but has the same capabilities as any of them:

In addition, Limit has a default value (being 10). So you can instantiate it without any arguments:

Sort

Distil\Common\Sort is an extension of Distil\Types\ListCriterion. It accepts a list of field or properties by which a result set should be sorted:

Note the usage of the "-" sign in front of the "name" property to indicate the result set should be sorted in descending order on that property.

Its value() method simply returns an array containing those sort fields, but you can also retrieve them as small Distil\Common\SortField value objects:

Factories

Criteria Factories

Any Criterion instance that extends either one of the Distil\Types can also be used as Distil\Criteria factories:

Under the hood, this named constructor will delegate its arguments to the Criterion's default constructor, and pass itself along a new Distil\Criteria instance.

If you want to enable using a Criterion as Criteria factory without extending any of the available Criterion Types, you can use the Distil\ActsAsCriteriaFactory trait.

CriterionFactory

In some cases, you may want to instantiate a Criterion by name. Take the following snippet from the example at the top of the docs:

Rather than doing this in every controller that may use the Sort and Limit criteria, you can register a resolvers for them in the Distil\CriterionFactory. A resolver is either a class name or a callable (e.g. named constructor, anonumous function, ...) that actually instantiates the Criterion:

Contributing

Please see the contributing file for details.

Changelog

You can see a list of changes for each release in our changelog file.

License

The MIT License. Please see the license file for more information.


All versions of distil with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
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 remipelhate/distil contains the following files

Loading the files please wait ....