1. Go to this page and download the library: Download nicmart/universal-matcher library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nicmart / universal-matcher example snippets
use UniversalMatcher\FluentFunction\FluentFunction;
use UniversalMatcher\MapMatcher;
$f = new FluentFunction;
$matcher = (new MapMatcher)
->defineMap('featured', $f->value('featured'))
->defineMap('type', $f->value('type'))
->defineMap('type-featured', function($v) { return [$v['type'], $v['value']]; }, 100)
;
$matcher
->defineMap('bar', function($v) { return $v->bar; }, -100) //This will be the last checked
->defineMap('baz', function($v) { return $v->baz; }, 100) //This will be the first
;
use UniversalMatcher\FluentFunction\FluentFunction;
$f = new FluentFunction;
// Returns a property of the input object
$h = $f->prop('foo');
$h($object); //Returns $object->foo;
// Returns the return value of a method of the input object
$h = $f->method('method');
$h($object); //Returns $object->method();
// ... with arguments too:
$h = $f->method('method', $arg1, $arg2, ...);
$h($object); //Returns $object->method($arg1, $arg2);
//Returns the value of an array or of an `ArrayAccess` instance:
$h = $f->value('key');
$h(['key' => 'value']); //Returns 'value'
//Regexpes
$h = $f->regexp('/^[0-9]+$/');
$h('abc0123'); // False
$h('123456') // True