-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension point for matching using custom conditions or standards.
* Add comparison type implementations * Centralize the comparison at the right place * enable a new extension place to provide custom operators. * Add MatchClosure Expression
- Loading branch information
Showing
18 changed files
with
770 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
lib/Doctrine/Common/Collections/Expr/Comparison/Contains.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\Common\Collections\Expr\Comparison; | ||
|
||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor; | ||
use Doctrine\Common\Collections\Expr\Comparison; | ||
use Doctrine\Common\Collections\Expr\Value; | ||
|
||
/** | ||
* @author Yannick Voyer (http://github.com/yvoyer) | ||
*/ | ||
final class Contains extends Comparison | ||
{ | ||
/** | ||
* @param string $field | ||
* @param mixed|Value $value | ||
*/ | ||
public function __construct($field, $value) | ||
{ | ||
parent::__construct($field, Comparison::CONTAINS, $value); | ||
} | ||
|
||
/** | ||
* @return callable | ||
*/ | ||
public function getFilterCallback() | ||
{ | ||
$value = $this->getValue()->getValue(); | ||
$field = $this->getField(); | ||
|
||
return function ($object) use ($value, $field) { | ||
return false !== strpos( | ||
ClosureExpressionVisitor::getObjectFieldValue($object, $field), | ||
$value | ||
); | ||
}; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
lib/Doctrine/Common/Collections/Expr/Comparison/EndsWith.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\Common\Collections\Expr\Comparison; | ||
|
||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor; | ||
use Doctrine\Common\Collections\Expr\Comparison; | ||
use Doctrine\Common\Collections\Expr\Value; | ||
|
||
/** | ||
* @author Yannick Voyer (http://github.com/yvoyer) | ||
*/ | ||
final class EndsWith extends Comparison | ||
{ | ||
/** | ||
* @param string $field | ||
* @param mixed|Value $value | ||
*/ | ||
public function __construct($field, $value) | ||
{ | ||
parent::__construct($field, Comparison::ENDS_WITH, $value); | ||
} | ||
|
||
/** | ||
* @return callable | ||
*/ | ||
public function getFilterCallback() | ||
{ | ||
$value = $this->getValue()->getValue(); | ||
$field = $this->getField(); | ||
|
||
return function ($object) use ($value, $field) { | ||
return $value === substr( | ||
ClosureExpressionVisitor::getObjectFieldValue($object, $field), | ||
-strlen($this->getValue()->getValue()) | ||
); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\Common\Collections\Expr\Comparison; | ||
|
||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor; | ||
use Doctrine\Common\Collections\Expr\Comparison; | ||
use Doctrine\Common\Collections\Expr\Value; | ||
|
||
/** | ||
* @author Yannick Voyer (http://github.com/yvoyer) | ||
*/ | ||
final class Equal extends Comparison | ||
{ | ||
/** | ||
* @param string $field | ||
* @param mixed|Value $value | ||
*/ | ||
public function __construct($field, $value) | ||
{ | ||
parent::__construct($field, Comparison::EQ, $value); | ||
} | ||
|
||
/** | ||
* @return callable | ||
*/ | ||
public function getFilterCallback() | ||
{ | ||
$value = $this->getValue()->getValue(); | ||
$field = $this->getField(); | ||
|
||
return function ($object) use ($value, $field) { | ||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) === $value; | ||
}; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
lib/Doctrine/Common/Collections/Expr/Comparison/GreaterThan.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\Common\Collections\Expr\Comparison; | ||
|
||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor; | ||
use Doctrine\Common\Collections\Expr\Comparison; | ||
use Doctrine\Common\Collections\Expr\Value; | ||
|
||
/** | ||
* @author Yannick Voyer (http://github.com/yvoyer) | ||
*/ | ||
final class GreaterThan extends Comparison | ||
{ | ||
/** | ||
* @param string $field | ||
* @param mixed|Value $value | ||
*/ | ||
public function __construct($field, $value) | ||
{ | ||
parent::__construct($field, Comparison::GT, $value); | ||
} | ||
|
||
/** | ||
* @return callable | ||
*/ | ||
public function getFilterCallback() | ||
{ | ||
$value = $this->getValue()->getValue(); | ||
$field = $this->getField(); | ||
|
||
return function ($object) use ($value, $field) { | ||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) > $value; | ||
}; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
lib/Doctrine/Common/Collections/Expr/Comparison/GreaterThanEqual.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\Common\Collections\Expr\Comparison; | ||
|
||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor; | ||
use Doctrine\Common\Collections\Expr\Comparison; | ||
use Doctrine\Common\Collections\Expr\Value; | ||
|
||
/** | ||
* @author Yannick Voyer (http://github.com/yvoyer) | ||
*/ | ||
final class GreaterThanEqual extends Comparison | ||
{ | ||
/** | ||
* @param string $field | ||
* @param mixed|Value $value | ||
*/ | ||
public function __construct($field, $value) | ||
{ | ||
parent::__construct($field, Comparison::GTE, $value); | ||
} | ||
|
||
/** | ||
* @return callable | ||
*/ | ||
public function getFilterCallback() | ||
{ | ||
$value = $this->getValue()->getValue(); | ||
$field = $this->getField(); | ||
|
||
return function ($object) use ($value, $field) { | ||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) >= $value; | ||
}; | ||
} | ||
} |
Oops, something went wrong.