Download the PHP package functional-php/pattern-matching without Composer

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

Pattern Matching

pattern-matching CI StyleCI Code Coverage Average time to resolve an issue Percentage of issues still open Chat on Gitter

Pattern matching is the process of checking a series of token against a pattern. It is different from pattern recognition as the match needs to be exact. The process does not only match as a switch statement does, it also assigns the value a bit like the list construct in PHP, a process called destructuring.

Most functional languages implement it as a core feature. Here is are some small examples in Haskell:

If you want to read more about the topic, you can head over to Wikipedia : Pattern matching

Installation

composer require functional-php/pattern-matching

Basic Usage

As we cannot extend the syntax of PHP, the choice was made to use a syntax based on arrays. The key representes the pattern and the value is the function to call with the value or a constant if you want to do nothing with it.

Let's see how we could implement our 3 Haskell examples:

You can also use the match function if you want to have a beefed up version of the switch statement or if you don't like anonymous functions:

If you are just interested in destructuring your values, there is also a helper for that:

Patterns

Here is a quick recap of the available patterns:

Name Format Example
Constant Any scalar value (int, float, string, boolean) 1.0, 42, "test"
Variable identifier a, name, anything
Array [<pattern>, ..., <pattern>] [], [a], [a, b, c]
Cons (identifier:list-identifier) (x:xs), (x:y:z:xs)
Wildcard _ _
As identifier@(<pattern>) all@(x:xs)

Testing

You can run the test suite for the library using:

composer test

A test report will be available in the reports directory.

Contributing

Any contribution welcome :


All versions of pattern-matching with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.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 functional-php/pattern-matching contains the following files

Loading the files please wait ....