package.xml 0000664 0001750 0001750 00000025040 12653672417 011315 0 ustar jan jan
Horde_Constraintpear.horde.orgHorde Constraint libraryA programmatic way of building constraints that evaluate to true or false.Chuck Hagenbuchchuckchuck@horde.orgyes2016-02-012.0.31.0.0stablestableBSD-2-Clause
* [jan] Mark PHP 7 as supported.
5.3.08.0.0alpha18.0.0alpha11.7.0Horde_Testpear.horde.org2.1.03.0.0alpha13.0.0alpha11.0.0alpha11.0.0alphaalpha2011-03-08BSD-2-Clause
* First alpha release for Horde 4.
1.0.0beta11.0.0betabeta2011-03-16BSD-2-Clause
* First beta release for Horde 4.
1.0.0RC11.0.0betabeta2011-03-22BSD-2-Clause
* First release candidate for Horde 4.
1.0.0RC21.0.0betabeta2011-03-29BSD-2-Clause
* Second release candidate for Horde 4.
1.0.01.0.0stablestable2011-04-06BSD-2-Clause
* First stable release for Horde 4.
1.0.11.0.0stablestable2011-11-22BSD-2-Clause
* [jan] Fix tests to work with PHPUnit 3.6.
2.0.0alpha11.0.0alphastable2012-07-05BSD-2-Clause
* First alpha release for Horde 5.
2.0.0beta11.0.0betastable2012-07-19BSD-2-Clause
* First beta release for Horde 5.
2.0.01.0.0stablestable2012-10-30BSD-2-Clause
* First stable release for Horde 5.
2.0.11.0.0stablestable2012-11-19BSD-2-Clause
* [mms] Use new Horde_Test layout.
2.0.21.0.0stablestable2015-01-08BSD-2-Clause
* [jan] Add Composer definition.
2.0.31.0.0stablestable2016-02-01BSD-2-Clause
* [jan] Mark PHP 7 as supported.
Horde_Constraint-2.0.3/doc/Horde/Constraint/COPYING 0000664 0001750 0001750 00000002430 12653672417 020066 0 ustar jan jan 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.php 0000664 0001750 0001750 00000000341 12653672417 021757 0 ustar jan jan
*/
class Horde_Constraint_AlwaysFalse implements Horde_Constraint
{
public function evaluate($value)
{
return false;
}
}
Horde_Constraint-2.0.3/lib/Horde/Constraint/AlwaysTrue.php 0000664 0001750 0001750 00000000336 12653672417 021650 0 ustar jan jan
*/
class Horde_Constraint_AlwaysTrue implements Horde_Constraint
{
public function evaluate($value)
{
return true;
}
}
Horde_Constraint-2.0.3/lib/Horde/Constraint/And.php 0000664 0001750 0001750 00000000750 12653672417 020252 0 ustar jan jan
*/
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.php 0000664 0001750 0001750 00000001775 12653672417 021171 0 ustar jan jan
*/
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.php 0000664 0001750 0001750 00000000615 12653672417 021113 0 ustar jan jan
*/
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.php 0000664 0001750 0001750 00000000650 12653672417 022074 0 ustar jan jan
*/
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.php 0000664 0001750 0001750 00000000677 12653672417 020320 0 ustar jan jan
*/
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.php 0000664 0001750 0001750 00000000434 12653672417 020461 0 ustar jan jan
*/
class Horde_Constraint_Null implements Horde_Constraint
{
public function evaluate($value)
{
return is_null($value);
}
}
Horde_Constraint-2.0.3/lib/Horde/Constraint/Or.php 0000664 0001750 0001750 00000000737 12653672417 020135 0 ustar jan jan
* @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.php 0000664 0001750 0001750 00000000650 12653672417 021421 0 ustar jan jan
*/
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.php 0000664 0001750 0001750 00000000242 12653672417 017544 0 ustar jan jan
*/
interface Horde_Constraint
{
public function evaluate($value);
}
Horde_Constraint-2.0.3/test/Horde/Constraint/AllTests.php 0000664 0001750 0001750 00000000132 12653672417 021506 0 ustar jan jan run();
Horde_Constraint-2.0.3/test/Horde/Constraint/AlwaysFalseTest.php 0000664 0001750 0001750 00000000773 12653672417 023041 0 ustar jan jan assertFalse($const->evaluate($value));
}
}
Horde_Constraint-2.0.3/test/Horde/Constraint/AlwaysTrueTest.php 0000664 0001750 0001750 00000000767 12653672417 022731 0 ustar jan jan assertTrue($const->evaluate($value));
}
}
Horde_Constraint-2.0.3/test/Horde/Constraint/AndTest.php 0000664 0001750 0001750 00000004037 12653672417 021325 0 ustar jan jan assertFalse($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.php 0000664 0001750 0001750 00000000143 12653672417 021772 0 ustar jan jan assertFalse($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.php 0000664 0001750 0001750 00000000704 12653672417 021360 0 ustar jan jan assertTrue($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.php 0000664 0001750 0001750 00000000642 12653672417 021533 0 ustar jan jan assertTrue($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.php 0000664 0001750 0001750 00000003756 12653672417 021212 0 ustar jan jan assertTrue($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.xml 0000664 0001750 0001750 00000000056 12653672417 021460 0 ustar jan jan
Horde_Constraint-2.0.3/test/Horde/Constraint/PregMatchTest.php 0000664 0001750 0001750 00000000730 12653672417 022471 0 ustar jan jan assertTrue($preg->evaluate('somestring'));
}
public function testPregReturnsFalseWhenRegex_DoesNot_Match()
{
$preg = new Horde_Constraint_PregMatch('/somestring/');
$this->assertFalse($preg->evaluate('some other string'));
}
}