Add matches operator

This commit is contained in:
Kévin Gomez 2015-11-13 14:37:58 +01:00
parent 5c514b0be3
commit a6e27f7466
6 changed files with 47 additions and 11 deletions

View File

@ -58,7 +58,7 @@
"scheb/two-factor-bundle": "~1.4",
"grandt/phpepub": "~4.0",
"wallabag/php-mobi": "~1.0.0",
"kphoen/rulerz-bundle": "~0.9,>=0.9.1"
"kphoen/rulerz-bundle": "~0.10"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "~2.2.0",

18
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "9372aa161ce94f8b5506d7e9cc73a884",
"content-hash": "e703c21d623d708ff9528c298d7ab05f",
"hash": "fed9468f6c830b0f81899daad7670af7",
"content-hash": "394f8a6ca5162f2d2756dbbee0ff5aae",
"packages": [
{
"name": "doctrine/annotations",
@ -2731,22 +2731,22 @@
},
{
"name": "kphoen/rulerz-bundle",
"version": "0.9.1",
"version": "0.11.0",
"source": {
"type": "git",
"url": "https://github.com/K-Phoen/RulerZBundle.git",
"reference": "0d8d6ca57ebf2c914c967bc13cdf13c5ebb2de62"
"reference": "dcaaed69d8252fa1e3a25802f8cf697947570778"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/K-Phoen/RulerZBundle/zipball/0d8d6ca57ebf2c914c967bc13cdf13c5ebb2de62",
"reference": "0d8d6ca57ebf2c914c967bc13cdf13c5ebb2de62",
"url": "https://api.github.com/repos/K-Phoen/RulerZBundle/zipball/dcaaed69d8252fa1e3a25802f8cf697947570778",
"reference": "dcaaed69d8252fa1e3a25802f8cf697947570778",
"shasum": ""
},
"require": {
"kphoen/rulerz": "~0.1, >=0.13.0",
"symfony/framework-bundle": "~2.3",
"symfony/validator": "~2.3"
"symfony/framework-bundle": "~2.3|~3.0",
"symfony/validator": "~2.3|~3.0"
},
"require-dev": {
"matthiasnoback/symfony-dependency-injection-test": "~0.7",
@ -2777,7 +2777,7 @@
"rulerz",
"specification"
],
"time": "2015-11-11 15:37:07"
"time": "2015-11-13 13:00:14"
},
{
"name": "kriswallsmith/assetic",

View File

@ -30,7 +30,7 @@ class TaggingRule
* @Assert\NotBlank()
* @RulerZAssert\ValidRule(
* allowed_variables={"title", "url", "isArchived", "isStared", "content", "language", "mimetype", "readingTime", "domainName"},
* allowed_operators={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or"}
* allowed_operators={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or", "matches"}
* )
* @ORM\Column(name="rule", type="string", nullable=false)
*/

View File

@ -0,0 +1,15 @@
<?php
namespace Wallabag\CoreBundle\Operator\Doctrine;
class Matches
{
public function __invoke($subject, $pattern)
{
if ($pattern[0] === "'") {
$pattern = sprintf("'%%%s%%'", substr($pattern, 1, -1));
}
return sprintf('UPPER(%s) LIKE UPPER(%s)', $subject, $pattern);
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace Wallabag\CoreBundle\Operator\PHP;
class Matches
{
public function __invoke($subject, $pattern)
{
return stripos($subject, $pattern) !== false;
}
}

View File

@ -91,3 +91,13 @@ services:
arguments:
- %wallabag_url%
- src/Wallabag/CoreBundle/Resources/views/themes/_global/public/img/appicon/apple-touch-icon-152.png
wallabag.operator.array.matches:
class: Wallabag\CoreBundle\Operator\PHP\Matches
tags:
- { name: rulerz.operator, executor: rulerz.executor.array, operator: matches }
wallabag.operator.doctrine.matches:
class: Wallabag\CoreBundle\Operator\Doctrine\Matches
tags:
- { name: rulerz.operator, executor: rulerz.executor.doctrine, operator: matches, inline: true }