Download the PHP package rafaelnajera/matcher without Composer

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

Matcher

Matcher implements a regexp-like matching system that can be used with user-devised tokens

Installation

Install the latest version with

Usage

The main class is Matcher, which allows you to match a sequence of tokens against a pattern specified in a regexp-like manner.

Matcher works on a Pattern object, which stands for a regexp-like pattern that can be matched.

The following sets up a Pattern object to match '^ab(cd)*e':

The tokens used to set up the pattern can be of any type. Matching is done by strict comparison with the input tokens. Tokens can also be objects that implement the Token interface, in which case the token's matches($someInput) method will be called. The input in this case can be anything as long as the token's matches() method knows how to determine a match.

Once set up, a Matcher object can be created and input tokens can be fed to the it one by one with the match method:

Here $r will be false if the input does not match the pattern. $r will be true if the sequence is still "alive", that is, if the sequence still matches the pattern in $matcher. When a full match is found the matchFound() method returns true:

The public variable $matcher->matched at this point will contain the actual sequence of matched tokens or, if tokens implement the Token interface, whatever the token's matched($someInput) method returns. This array of matched token information can be manipulated during the matching process with callbacks as explained below.

The reset() method, resets the internal state of the pattern matcher as if no token had been fed to it.

Input tokens can also be given in an array:

By default this method resets the matcher before starting to match the elements of the given array. An optional flag can be given to change this behaviour:

Callbacks

A callback can be provided that will be called when a full match occurs. The callback function is called with $matcher->matched as its only argument and its output will overwrite $matcher->matched.

The following code, for example, will cause $matcher->matched to be 'abc' instead of the array ['a', 'b', 'c']:

Callbacks are retained in their proper places when patterns are added. This allows sub-patterns with specific callbacks to be created. For example:

In this case, every time the 'cd' subpattern is matched, the callback will be called.

End Token

The special constant Token::EOF stands for the end of input. It can be used to set up patterns and also to signal the matcher the end of the input.

Parallel Matching

The class matches input tokens against a set of patterns. Once a match is found in one of the patterns, the matcher saves that pattern's match sequence and starts matching again. This effectively considers a valid input stream as a sequence of matched patterns.

The constructor simply takes an array of objects. Then the method can be called on input tokens as with the class.

Example:

The method can be used to match an array of tokens against the patterns. It returns true if the input sequence was matched perfectly and false if there was any error. The number of matched patterns can be found with

Example:


All versions of matcher with dependencies

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

Loading the files please wait ....