Download the PHP package nicmart/universal-matcher without Composer

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

Universal Matcher

Build Status Coverage Status Scrutinizer Quality Score

UniversalMatcher is a library that simplifies and abstracts the construction of custom matchers. A Matcher acts like a filter that transforms an arbitrary value to another, following the business rules you specify in the matcher definition. The "match" is intended to be between the input value and the rule that is applied to that value.

For installing instructions (composer!) please go to the end of this README

Changelog

Example

Instantiate the matcher, and define some maps:

The FluentFunction simplifies the construction of maps, but it is completely optional. The number in the third definition specifies a priority. Default is 0, so the example above the last map has the highest priority.

Then you define the rules. Each rule is attached to a previously defined map and to an expected map value, and specifies a value that will be returned when the rule matches:

The setDefault call defines the value taht will be returned when no rule matches.

Now you can use your matcher:

Documentation

Summary

A matcher is defined by a set of maps and a set of rules.

When you invoke the matcher, the input value is transformed by the registered map with highest priority. If there is a registered rule for that map that has the expected value (second argument of rule method) equal to the transformed value, then the matcher returns the return value of that rule (third argument of the rule method).

If no rules match for that map, the matcher will pass to the next (in priority order) map, and so on until there is a rule match.

When the matcher has cycled throughout all the registered maps without finding a matching rule, a default value is returned.

Maps

You register a map with the MapMatcher::defineMap() method. The first argument is the map name that the rules will use to refer to the map, and the second is the real map, that can be any valid php callable:

Priority

defineMap accepts also a third optional argument to specify a priority. Default is 0, and the rules that corresponds to higher priority maps will win. If two maps have the same priority, the first defined wins.

You can retrieve the priority of a registered map with the MapMatcher::priority method. So if you want, for example, to be sure to define a map with prioriy higher that the baz map, you can do

FluentFunction

With a FluentFunction you can define and compose more easily some very common callables:

Concatenation is easy too:

Rules

A rule is composed of three arguments: the name of the map that will transform the input value, the expected returned value, and the value to be returned on match.

The order of the rules, unlike the maps definitions, has no effect on matching.

Skip the map definition

If a map is intended to be used with only one rule, you can skip the definition of the map and directly define the rule with the callbackRule method:

Default return value

You can set the return value of the matcher when no rules match with the setDefault method. Default is null.

Performance considerations

MapMatcher has been designed to minimize cycles between rules. Indeed, the cost of a match is independent on the number of rules, but only on the number of registered maps (and of course on the cost of each map).

So there should not be issues if the number of rules is high but the number of maps remains low.

Measuring the cost on php array accesses, we have, given the number of maps M, that

as you can see, the cost is linear on the number of maps.

Where is it used

I use UniversalMatcher in the compiler definitions of the DomainSpecificQuery component. The Universal matcher allowed us to minimize rules checks while mantaining maximum flexibility on the compiler definition.

Install

The best way to install UniversalMatcher is through composer.

Just create a composer.json file for your project:

Then you can run these two commands to install it:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

or simply run composer install if you have have already installed the composer globally.

Then you can include the autoloader, and you will have access to the library classes:


All versions of universal-matcher with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
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 nicmart/universal-matcher contains the following files

Loading the files please wait ....