Download the PHP package krixon/rules without Composer

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

Rules

Build Status Coverage Status Code Climate Latest Stable Version Latest Unstable Version License

A simple language for defining and building Specification Pattern objects.

Prerequisites

Installation

Install via composer

To install this library with Composer, run the following command:

You can see this library on Packagist.

Install from source

Supported Syntax

Refer to the syntax documentation for detailed information on the rule syntax.

Usage

The main task involved in using this library is implementing BaseCompiler::generate(). This method has the following signature:

Its job is to generate a Specification object from a ComparisonNode AST object.

A ComparisonNode consists of an IdentifierNode which identifies the data against which the specification should be checked, and a LiteralNode which contains the value to compare against. It also contains information about the type of comparison (equals, greater than, etc).

For example, imagine you have the following Specification which can be applied to a User object:

You can define a rule for this Specification as email is "[email protected]".

In this rule, email is an identifier which refers to the user's email address. It is up to you how to interpret a given identifier. The string value email is converted to an IdentifierNode AST node during parsing. This node can be accessed via ComparisonNode::identifier().

The comparison operator is is, which means "equals". You can use ComparisonNode::isEquals(), ComparisonNode::isLessThan() etc to determine the comparison type.

Finally, [email protected] is converted into a StringNode AST node during parsing. This node can be accessed via ComparisonNode::value().

Based on the above, the BaseCompiler::generate() method might be implemented as follows:

Delegating generation to services

Although extending BaseCompiler is convenient in simple cases, it becomes complicated when you have many specifications to support. In this case, you might want to delegate the generation work to dedicated services.

The DelegatingCompiler class is provided for this purpose. To use it, first create a class which implements the SpecificationGenerator interface, which defines a single method:

This is very similar to BaseCompiler::generate(), however returning a Specification is optional.

Next, register an instance of your class with the DelegatingCompiler:

When DelegatingCompiler::compile() is invoked, the DelegatingCompiler will loop through all registered generators and call SpecificationGenerator::attempt() with each ComparisonNode.

All SpecificationGenerators provided via the DelegatingCompiler's constructor share the same priority of 0, however they can also be registered with an explicit priority:

SpecificationGenerators with higher priority are invoked first.

The library provides some built-in specifications and corresponding generators which can be used if desired. These are also easy to extend with custom logic.

Negating comparisons

ComparisonNode does not expose negated comparisons like does not equal and does not match. However this is supported in the language by adding not before the comparison operator:

You do not need to write any code to handle these cases because the compiler will produce a Specification based on the non-negated comparison and then wrap the result in a Not specification which simply inverts the result of Specification::isSatisfiedBy returned by the wrapped Specification.

A shorthand syntax for not is can also be used by simply omitting the is:

Contributing

Please refer to CONTRIBUTING.md


All versions of rules with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-mbstring Version *
ext-ctype Version *
ext-intl Version *
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 krixon/rules contains the following files

Loading the files please wait ....