Skip to content

zweifisch/php-pattern-matching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

match Build Status

pattern matching for php

install via composer

composer require 'zweifisch/match:*'

destruct value

$array = [1,[2,[3,4]]];
extract(\match\destruct(['a',['b',['c','d']]], $array)) or die("match failed");
echo "$a $b $c $d"; // "1 2 3 4"

passing to a function

$input = ['method'=>'foo', 'params'=>['bar']];
$pattern = ['method'=>'func', 'params'=>['arg1']];
$result = \match\let($pattern, $input, function($arg1, $func){
	return "$func $arg1";
});
// "foo bar"

destruct multiple values

$input = ['method'=>'foo', 'params'=>['bar']];
$result = \match\let(
	['method'=>'func', 'params'=>['arg1']], $input
	'now', time(),
	function($func, $arg1, $now){
		return "$func $arg1 $now";
	}
);

tests

composer install --dev
vendor/bin/phpunit -c tests

About

pattern matching for php

Resources

Stars

Watchers

Forks

Packages

No packages published