Bolt\Storage\Query\QueryParameterParser::addValueMatcher PHP Метод

addValueMatcher() публичный Метод

This gives the ability to define additional value -> operator matches
public addValueMatcher ( string $token, array $params = [], boolean $priority = null )
$token string Regex pattern to match against
$params array Options to provide to the matched param
$priority boolean If set item will be prepended to start of list
    public function addValueMatcher($token, $params = [], $priority = null)
    {
        if ($priority) {
            array_unshift($this->valueMatchers, ['token' => $token, 'params' => $params]);
        } else {
            $this->valueMatchers[] = ['token' => $token, 'params' => $params];
        }
    }

Usage Example

Пример #1
0
 public function testAddingCustomMatcher()
 {
     $app = $this->getApp();
     $expr = $app['storage']->createExpressionBuilder();
     // In this test we'll make a custom matcher that allows a new syntax: username: '******' as an alias for a like query
     $p = new QueryParameterParser($expr);
     $p->addValueMatcher('\\~(\\w+)', ['value' => '%$1%', 'operator' => 'like'], true);
     $filter = $p->getFilter('username', '~test');
     $this->assertEquals('username LIKE :username_1', $filter->getExpression());
     $this->assertEquals(['%test%'], array_values($filter->getParameters()));
 }