boyhagemann/matcher



Documentation

Matcher

With Matcher you can match an object to specified rules and get data returned.

Example usage

// Add some rules
$matcher->whenProperty('title')->contains('Hi')->provide(['foo' => 'bar']);

// Get an object to match against
$object = Your\Object;
$object->title = 'Hi';

// Check if the object matches the rules
$data = $matcher->match($object); // Will return "array(array('foo' => 'bar'))"

Rule logic

Every rule can match using different logics. For now, these are the implemented logics:

// Applied the a Rule object
$rule->equals('foo'); // Default logic
$rule->startsWith('foo');
$rule->endsWith('foo');
$rule->contains('foo');

//Applied to a Container object using the fluent interface
$matcher->whenProperty('title')->equals('foo');
$matcher->whenProperty('title')->startsWith('foo');
$matcher->whenProperty('title')->endsWith('foo');
$matcher->whenProperty('title')->contains('foo');

Documentation will be updated with:

  • Using tags
  • Unique fields
  • Match logic explained
  • Match against multiple values
  • Setting default values
  • Helpful scenarios when you can use this library