package.xml0000664000175000017500000002504012653672417011315 0ustar janjan Horde_Constraint pear.horde.org Horde Constraint library A programmatic way of building constraints that evaluate to true or false. Chuck Hagenbuch chuck chuck@horde.org yes 2016-02-01 2.0.3 1.0.0 stable stable BSD-2-Clause * [jan] Mark PHP 7 as supported. 5.3.0 8.0.0alpha1 8.0.0alpha1 1.7.0 Horde_Test pear.horde.org 2.1.0 3.0.0alpha1 3.0.0alpha1 1.0.0alpha1 1.0.0 alpha alpha 2011-03-08 BSD-2-Clause * First alpha release for Horde 4. 1.0.0beta1 1.0.0 beta beta 2011-03-16 BSD-2-Clause * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 BSD-2-Clause * First release candidate for Horde 4. 1.0.0RC2 1.0.0 beta beta 2011-03-29 BSD-2-Clause * Second release candidate for Horde 4. 1.0.0 1.0.0 stable stable 2011-04-06 BSD-2-Clause * First stable release for Horde 4. 1.0.1 1.0.0 stable stable 2011-11-22 BSD-2-Clause * [jan] Fix tests to work with PHPUnit 3.6. 2.0.0alpha1 1.0.0 alpha stable 2012-07-05 BSD-2-Clause * First alpha release for Horde 5. 2.0.0beta1 1.0.0 beta stable 2012-07-19 BSD-2-Clause * First beta release for Horde 5. 2.0.0 1.0.0 stable stable 2012-10-30 BSD-2-Clause * First stable release for Horde 5. 2.0.1 1.0.0 stable stable 2012-11-19 BSD-2-Clause * [mms] Use new Horde_Test layout. 2.0.2 1.0.0 stable stable 2015-01-08 BSD-2-Clause * [jan] Add Composer definition. 2.0.3 1.0.0 stable stable 2016-02-01 BSD-2-Clause * [jan] Mark PHP 7 as supported. Horde_Constraint-2.0.3/doc/Horde/Constraint/COPYING0000664000175000017500000000243012653672417020066 0ustar janjan Copyright 1999-2016 Horde LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 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 HORDE PROJECT 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. Horde_Constraint-2.0.3/lib/Horde/Constraint/AlwaysFalse.php0000664000175000017500000000034112653672417021757 0ustar janjan */ class Horde_Constraint_AlwaysFalse implements Horde_Constraint { public function evaluate($value) { return false; } } Horde_Constraint-2.0.3/lib/Horde/Constraint/AlwaysTrue.php0000664000175000017500000000033612653672417021650 0ustar janjan */ class Horde_Constraint_AlwaysTrue implements Horde_Constraint { public function evaluate($value) { return true; } } Horde_Constraint-2.0.3/lib/Horde/Constraint/And.php0000664000175000017500000000075012653672417020252 0ustar janjan */ class Horde_Constraint_And extends Horde_Constraint_Coupler { public function evaluate($value) { foreach ($this->_constraints as $c) { if (!$c->evaluate($value)) { return false; } } return true; } } Horde_Constraint-2.0.3/lib/Horde/Constraint/Coupler.php0000664000175000017500000000177512653672417021171 0ustar janjan */ abstract class Horde_Constraint_Coupler implements Horde_Constraint { protected $_constraints = array(); public function __construct() { $constraints = func_get_args(); foreach ($constraints as $c) { if (! $c instanceof Horde_Constraint) { throw new IllegalArgumentException("$c does not implement Horde_Constraint"); } $this->addConstraint($c); } } public function addConstraint(Horde_Constraint $constraint) { $kind = get_class($this); if ($constraint instanceof $kind) { foreach ($constraint->getConstraints() as $c) { $this->addConstraint($c); } } else { $this->_constraints[] = $constraint; } return $this; } public function getConstraints() { return $this->_constraints; } } Horde_Constraint-2.0.3/lib/Horde/Constraint/IsEqual.php0000664000175000017500000000061512653672417021113 0ustar janjan */ class Horde_Constraint_IsEqual implements Horde_Constraint { private $_value; public function __construct($value) { $this->_value = $value; } public function evaluate($value) { return $this->_value == $value; } } Horde_Constraint-2.0.3/lib/Horde/Constraint/IsInstanceOf.php0000664000175000017500000000065012653672417022074 0ustar janjan */ class Horde_Constraint_IsInstanceOf implements Horde_Constraint { private $_type; public function __construct($type) { $this->_type = $type; } public function evaluate($value) { return $value instanceof $this->_type; } } Horde_Constraint-2.0.3/lib/Horde/Constraint/Not.php0000664000175000017500000000067712653672417020320 0ustar janjan */ class Horde_Constraint_Not implements Horde_Constraint { private $_constraint; public function __construct(Horde_Constraint $constraint) { $this->_constraint = $constraint; } public function evaluate($value) { return !$this->_constraint->evaluate($value); } } Horde_Constraint-2.0.3/lib/Horde/Constraint/Null.php0000664000175000017500000000043412653672417020461 0ustar janjan */ class Horde_Constraint_Null implements Horde_Constraint { public function evaluate($value) { return is_null($value); } } Horde_Constraint-2.0.3/lib/Horde/Constraint/Or.php0000664000175000017500000000073712653672417020135 0ustar janjan * @author Chuck Hagenbuch */ class Horde_Constraint_Or extends Horde_Constraint_Coupler { public function evaluate($value) { foreach ($this->_constraints as $c) { if ($c->evaluate($value)) { return true; } } return false; } } Horde_Constraint-2.0.3/lib/Horde/Constraint/PregMatch.php0000664000175000017500000000065012653672417021421 0ustar janjan */ class Horde_Constraint_PregMatch implements Horde_Constraint { private $_regex; public function __construct($regex) { $this->_regex = $regex; } public function evaluate($value) { return preg_match($this->_regex, $value) > 0; } } Horde_Constraint-2.0.3/lib/Horde/Constraint.php0000664000175000017500000000024212653672417017544 0ustar janjan */ interface Horde_Constraint { public function evaluate($value); } Horde_Constraint-2.0.3/test/Horde/Constraint/AllTests.php0000664000175000017500000000013212653672417021506 0ustar janjanrun(); Horde_Constraint-2.0.3/test/Horde/Constraint/AlwaysFalseTest.php0000664000175000017500000000077312653672417023041 0ustar janjanassertFalse($const->evaluate($value)); } } Horde_Constraint-2.0.3/test/Horde/Constraint/AlwaysTrueTest.php0000664000175000017500000000076712653672417022731 0ustar janjanassertTrue($const->evaluate($value)); } } Horde_Constraint-2.0.3/test/Horde/Constraint/AndTest.php0000664000175000017500000000403712653672417021325 0ustar janjanassertFalse($and->evaluate('test_string')); } public function testAndEvaluatesFalseWhenBothConstraintsAreFalse() { $c1 = new Horde_Constraint_AlwaysFalse(); $c2 = new Horde_Constraint_AlwaysFalse(); $and = new Horde_Constraint_And($c1, $c2); $this->assertFalse($and->evaluate('test_string')); } public function testAndEvaluatesTrueWhenBothConstraintsAreTrue() { $c1 = new Horde_Constraint_AlwaysTrue(); $c2 = new Horde_Constraint_AlwaysTrue(); $and = new Horde_Constraint_And($c1, $c2); $this->assertTrue($and->evaluate('test_string')); } public function testAndEvaluatesFalseWhenFalseConstraintIsAddedViaSetter() { $c1 = new Horde_Constraint_AlwaysTrue(); $c2 = new Horde_Constraint_AlwaysTrue(); $and = new Horde_Constraint_And($c1, $c2); $and->addConstraint(new Horde_Constraint_AlwaysFalse()); $this->assertFalse($and->evaluate('test_string')); } public function testAndaddConstraintReturnsAndConstraint() { $c1 = new Horde_Constraint_AlwaysTrue(); $c2 = new Horde_Constraint_AlwaysTrue(); $and = new Horde_Constraint_And($c1, $c2); $returnConst = $and->addConstraint(new Horde_Constraint_AlwaysFalse()); $this->assertInstanceOf('Horde_Constraint_And', $returnConst); } public function testReturnedAndEvaluatesFalseWhenFalseConstraintIsAddedViaSetter() { $c1 = new Horde_Constraint_AlwaysTrue(); $c2 = new Horde_Constraint_AlwaysTrue(); $and = new Horde_Constraint_And($c1, $c2); $and = $and->addConstraint(new Horde_Constraint_AlwaysFalse()); $this->assertFalse($and->evaluate('test_string')); } } Horde_Constraint-2.0.3/test/Horde/Constraint/bootstrap.php0000664000175000017500000000014312653672417021772 0ustar janjanassertFalse($const->evaluate($foo)); } public function testConstraintReturnsTrueWhenInstanceIsCorrectClass() { $foo = new StdClass(); $const = new Horde_Constraint_IsInstanceOf('StdClass'); $this->assertTrue($const->evaluate($foo)); } } Horde_Constraint-2.0.3/test/Horde/Constraint/NotTest.php0000664000175000017500000000070412653672417021360 0ustar janjanassertTrue($not->evaluate('foo')); } public function testNotMakesTrueConstraintFalse() { $not = new Horde_Constraint_Not(new Horde_Constraint_AlwaysTrue()); $this->assertFalse($not->evaluate('foo')); } } Horde_Constraint-2.0.3/test/Horde/Constraint/NullTest.php0000664000175000017500000000064212653672417021533 0ustar janjanassertTrue($const->evaluate(null)); } public function testNullReturnsFalseWhenValue_IsNot_Null() { $const = new Horde_Constraint_Null(); $this->assertFalse($const->evaluate('not null value')); } } Horde_Constraint-2.0.3/test/Horde/Constraint/OrTest.php0000664000175000017500000000375612653672417021212 0ustar janjanassertTrue($or->evaluate('test_string')); } public function testOrEvaluatesFalseWhenBothConstraintsAreFalse() { $c1 = new Horde_Constraint_AlwaysFalse(); $c2 = new Horde_Constraint_AlwaysFalse(); $or = new Horde_Constraint_Or($c1, $c2); $this->assertFalse($or->evaluate('test_string')); } public function testOrEvaluatesTrueWhenBothConstraintsAreTrue() { $c1 = new Horde_Constraint_AlwaysTrue(); $c2 = new Horde_Constraint_AlwaysTrue(); $or = new Horde_Constraint_Or($c1, $c2); $this->assertTrue($or->evaluate('test_string')); } public function testOrEvaluatesTrueWhenTrueConstraintIsAddedViaSetter() { $c1 = new Horde_Constraint_AlwaysFalse(); $c2 = new Horde_Constraint_AlwaysFalse(); $or = new Horde_Constraint_Or($c1, $c2); $or->addConstraint(new Horde_Constraint_AlwaysTrue()); $this->assertTrue($or->evaluate('test_string')); } public function testOraddConstraintReturnsOrConstraint() { $c1 = new Horde_Constraint_AlwaysTrue(); $c2 = new Horde_Constraint_AlwaysTrue(); $or = new Horde_Constraint_Or($c1, $c2); $returnConst = $or->addConstraint(new Horde_Constraint_AlwaysFalse()); $this->assertInstanceOf('Horde_Constraint_Or', $returnConst); } public function testReturnedOrEvaluatesTrueWhenTrueConstraintIsAddedViaSetter() { $c1 = new Horde_Constraint_AlwaysFalse(); $c2 = new Horde_Constraint_AlwaysFalse(); $or = new Horde_Constraint_Or($c1, $c2); $or = $or->addConstraint(new Horde_Constraint_AlwaysTrue()); $this->assertTrue($or->evaluate('test_string')); } } Horde_Constraint-2.0.3/test/Horde/Constraint/phpunit.xml0000664000175000017500000000005612653672417021460 0ustar janjan Horde_Constraint-2.0.3/test/Horde/Constraint/PregMatchTest.php0000664000175000017500000000073012653672417022471 0ustar janjanassertTrue($preg->evaluate('somestring')); } public function testPregReturnsFalseWhenRegex_DoesNot_Match() { $preg = new Horde_Constraint_PregMatch('/somestring/'); $this->assertFalse($preg->evaluate('some other string')); } }