2017 © Pedro Peláez
 

library phpmatch

.

image

iannsp/phpmatch

.

  • Sunday, April 30, 2017
  • by iannsp
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Pattern Matching programming

Build Status, (*1)

How to

  • install: composer require 'iannsp/phpmatch'
  • use:
    use phpmatch;
    use \phpmatch\Match as M;// to made easier use domains constants.

Match Function

Matches start with match function. This function receive the values you need
test the matches., (*2)

Simple Scalar Matching

    $a = 1;
    $b = 1;
    match($a)->with($b); // true.
    match($variableUnsigned)->with(null); // true

Array Matching

    $a = [1   , 2, 3];
    $b = ["anything", 2, 3];

    // because $b[0]
    match($a)->with($b); // false 

    // you can ignore $b[0] using M::_
    $c = [M::_, 2, 3];
    match($c)->with($b)); // true

    // and replace $d[0] with $b[0] using M::r
    $d = [M::r, 2, 3];
    match($d)->with($b); // true
    echo $d[0]; // "anything"

    //you can do the same with associative arrays.
    $e = ["first"=> M::r, 2, 3];
    match($e)->with(["first"=>"anything", 2, 3]);// true
    echo $e["first"]; // "anything" 

    // THE MATCH PARAM NEED BE A VARIABLE.
    match([null,2,3])->with($b); // Fatal error:Only variables can be passed by reference

TODO

  • Case
$a = 1;
match($a)
    ->incase(   1   )->doIt(function(){ echo "a is 1";})
    ->incase([1,2,3])->doIt(function(){echo "a is array [1,2,3];});

  • Guards
$a = 1;
match($a)
    ->incase(   1   )->when(true)->doIt(function(){ echo "a is 1";})
    ->incase([1,"y"=> M::r,3])->when($y > 10)->doIt(function(){echo "a is array [1,2,3];});

The Versions

30/04 2017

dev-master

9999999-dev

.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.6

 

The Development Requires

30/04 2017

1.0.1

1.0.1.0

.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.6

 

The Development Requires

14/04 2017

1.0.0

1.0.0.0

.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.6

 

The Development Requires