2017 © Pedro Peláez
 

library matchmaker

Ultra-fresh PHP matching class (in PHP 7.x OOP)

image

c0de8/matchmaker

Ultra-fresh PHP matching class (in PHP 7.x OOP)

  • Sunday, January 7, 2018
  • by C0DE8
  • Repository
  • 0 Watchers
  • 3 Stars
  • 2,921 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 8 Versions
  • 2 % Grown

The README.md

matchmaker

Total Downloads Latest Stable Version, (*1)

License, (*2)

PHP Objects/methods that help you validate structure of complex nested PHP arrays. Like XML or JSON Schema., (*3)


use C0DE8\MatchMaker\Manager; use C0DE8\MatchMaker\Exception\InvalidValueTypeException; use C0DE8\MatchMaker\Exception\KeyMatcherFailException; use C0DE8\MatchMaker\Exception\KeyMatchFailException; use C0DE8\MatchMaker\Exception\MatcherException; $books = [ [ 'type' => 'book', 'title' => 'Geography book', 'chapters' => [ 'eu' => ['title' => 'Europe', 'interesting' => true], 'as' => ['title' => 'America', 'interesting' => false] ], 'price' => 19.99 ], [ 'type' => 'book', 'title' => 'Foreign languages book', 'chapters' => [ 'de' => ['title' => 'Deutsch'] ], 'price' => 29.99 ] ]; $pattern = [ '*' => [ 'type' => 'book', 'title' => ':string contains(book)', 'chapters' => [ ':string length(2) {1,3}' => [ 'title' => ':string', 'interesting?' => ':bool', ] ], 'price' => ':float' ] ]; try { (new Manager)->matchAgainst($books, $pattern); // return true (otherwise throws an exception) } catch (\InvalidArgumentException $excetpion) { echo $exception->getMessage(); } catch (InvalidValueTypeException $excetpion) { echo $exception->getMessage(); } catch (KeyMatcherFailException $excetpion) { echo $exception->getMessage(); } catch (MatcherException $excetpion) { echo $exception->getMessage(); } catch (\Exception $excetpion) { echo $exception->getMessage(); }

It could be used to check scalar values, objects or arrays from different sources (JSON, XML, Post Data)., (*4)

Matching rules

Matching rules are strings that start with ':' (_colon_). You can use multiple matchers joined with space. Matcher could be any callable (name of function or closure). You can add your own rules or replace standard ones., (*5)

  • General, (*6)

    • empty
    • nonempty
    • required
    • in(a, b, ...)
    • mixed
    • any
  • Types, (*7)

    • array
    • bool
    • boolean
    • callable
    • double
    • float
    • int
    • integer
    • long
    • numeric
    • number
    • object
    • real
    • resource
    • scalar
    • string
  • Numbers, (*8)

    • gt(n)
    • gte(n)
    • lt(n)
    • lte(n)
    • negative
    • positive
    • between(a, b)
  • Strings, (*9)

    • alnum
    • alpha
    • cntrl
    • digit
    • graph
    • lower
    • print
    • punct
    • space
    • upper
    • xdigit
    • regexp(pattern)
    • email
    • url
    • ip
    • length(n)
    • min(n)
    • max(n)
    • contains(needle)
    • starts(s)
    • ends(s)
    • json
    • date
  • Arrays, (*10)

    • count(n)
    • keys(key1, key2, ...)
  • Objects, (*11)

    • instance(class)
    • class_exists(className)
    • property(name, value)
    • method(name, value)

More details you can find here, (*12)

Quantifiers for keys

  • ! - one key required (default)
  • ? - optional key
  • * - any count of keys
  • {3} - strict count of keys
  • {1,5} - range

For matchers (i.e. ':string') default quantifier is *, (*13)

Installation

  • Install matchmaker via composer for your project:

stable, (*14)

composer require c0de8/matchmaker:*

development, (*15)

composer require c0de8/matchmaker:dev-master

PHPUnit

This package expects (uses) PHPUnit Version 6.x.x. Site, (*16)

(but PHPUnit Version 5.x.x also works), (*17)

License

Copyright (c) 2017 Bjoern Ellebrecht, (*18)

Copyright (c) 2014 Petr Trofimov, (*19)

MIT License, (*20)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*21)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*22)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*23)

The Versions

07/01 2018

dev-master

9999999-dev https://github.com/c0de8/matchmaker

Ultra-fresh PHP matching class (in PHP 7.x OOP)

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Daniel Rubin

schema json validation array pattern matcher matchmaker

14/05 2017

2.0.5

2.0.5.0 https://github.com/c0de8/matchmaker

Ultra-fresh PHP matching class (in PHP 7.x OOP)

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Daniel Rubin

schema json validation array pattern matcher matchmaker

14/05 2017

2.0.4

2.0.4.0 https://github.com/c0de8/matchmaker

Ultra-fresh PHP matching class (in PHP 7.x OOP)

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Daniel Rubin

schema json validation array pattern matcher matchmaker

13/05 2017

2.0.3

2.0.3.0 https://github.com/c0de8/matchmaker

Ultra-fresh PHP matching class (in PHP 7.x OOP)

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Daniel Rubin

schema json validation array pattern matcher matchmaker

13/05 2017

2.0.2

2.0.2.0 https://github.com/c0de8/matchmaker

Ultra-fresh PHP matching functions (in PHP 7.x OOP)

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Daniel Rubin

schema json validation array pattern matcher matchmaker

13/05 2017

2.0.1

2.0.1.0 https://github.com/c0de8/matchmaker

Ultra-fresh PHP matching functions (in PHP 7.x OOP)

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Daniel Rubin

schema json validation array pattern matcher matchmaker

13/05 2017

2.0

2.0.0.0 https://github.com/c0de8/matchmaker

Ultra-fresh PHP matching functions (in PHP 7.x OOP)

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Daniel Rubin

schema json validation array pattern matcher matchmaker

28/06 2014

1.0

1.0.0.0 https://github.com/ptrofimov/matchmaker

Ultra-fresh PHP matching functions

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

schema json validation array pattern matcher matchmaker