CVS: phpweather/config pw_dependency_and.php,NONE,1.1 pw_dependency_e...
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2003-07-01 10:05:08
|
Update of /cvsroot/phpweather/phpweather/config In directory sc8-pr-cvs1:/tmp/cvs-serv13992 Modified Files: pw_dependency_or.php pw_dependency.php Added Files: pw_dependency_and.php pw_dependency_equal.php pw_dependency_not.php Log Message: The dependency classes can now handle full Boolean expressions with the pw_dependency_or, pw_dependency_and, and pw_dependency_not classes. The old pw_dependency class is now called pw_dependency_equal because it depends on a given option being equal to a given value. The pw_dependency class is only there to act as some form of interface although it isn't strictly necessary. --- NEW FILE --- <?php require_once('pw_dependency.php'); /** * An 'and' dependency. * * This dependency is a collection of several dependencies and will * only be satisfied when all of them is satisfied. The logic is * short-circuit so that the evaluation stops as soon as the answer is * known, that is, as soon as one of the dependencies fail. * * @author Martin Geisler <gim...@gi...> * @version $Id: pw_dependency_and.php,v 1.1 2003/07/01 10:05:04 gimpster Exp $ * @package PHP Weather Configurator */ class pw_dependency_and extends pw_dependency { /** * Constructs a new 'and' dependency. * * @param mixed A variable number of other dependencies. This * dependency is satisfied if and only if all the dependencies * satisfied. */ function pw_dependency_and() { $this->pw_dependency(func_get_args()); } /** * Checks the dependency. * * All the dependencies that were used to create this dependency is * tested one after another. * * @return boolean Returns true if and only if all all the * dependencies are satisfied. */ function check() { foreach ($this->dep as $d) { if (!$d->check()) return false; } return true; } } ?> --- NEW FILE --- <?php require_once('pw_dependency.php'); /** * Depends on an option being ready and having a particular value. * * @author Martin Geisler <gim...@gi...> * @version $Id: pw_dependency_equal.php,v 1.1 2003/07/01 10:05:04 gimpster Exp $ * @package PHP Weather Configurator * @abstract */ class pw_dependency_equal extends pw_dependency { /** * The name of an option. * * @var string The name of the option that should be checked. */ var $option; /** * Constructs a new dependency. * * @param string $option The name of the option that must satisfy * the dependency. * @param string $dep The required value of the option. * */ function pw_dependency_equal($option, $dep) { $this->option = $option; $this->pw_dependency($dep); } /** * Check the dependency. * * The dependency is tested using value equality (==) and not the * more restrictive type and value equality (===). Additionally the * option must be ready to be displayed. * * @return boolean Returns true if the dependency is satisfied, * false otherwise. */ function check() { global $HTTP_SESSION_VARS; return ($HTTP_SESSION_VARS[$this->option]->is_ready() && $HTTP_SESSION_VARS[$this->option]->get_value() == $this->dep); } } ?> --- NEW FILE --- <?php require_once('pw_dependency.php'); /** * An 'not' dependency. * * This dependency negates another dependency and is satisfied if and * only if the other dependency fails. * * @author Martin Geisler <gim...@gi...> * @version $Id: pw_dependency_not.php,v 1.1 2003/07/01 10:05:04 gimpster Exp $ * @package PHP Weather Configurator */ class pw_dependency_not extends pw_dependency { /** * Constructs a new 'not' dependency. * * @param object $dependency The dependency that should be negated. */ function pw_dependency_not($dependency) { $this->pw_dependency($dependency); } /** * Checks the dependency. * * @return boolean Returns true if and only if the dependency wasn't * satisfied. */ function check() { return !$this->dep->check(); } } ?> Index: pw_dependency_or.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_dependency_or.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- pw_dependency_or.php 28 Dec 2002 00:52:54 -0000 1.3 +++ pw_dependency_or.php 1 Jul 2003 10:05:04 -0000 1.4 @@ -1,10 +1,15 @@ <?php +require_once('pw_dependency.php'); + /** * An 'or' dependency. * * This dependency is a collection of several dependencies, but it - * will be satisfied as long a just one of them is satisfied. + * will be satisfied as long at least one of them is satisfied. The + * logic is short-circuit so that the evaluation stops as soon as the + * answer is known, that is, as soon as one of the dependencies is + * satisfied. * * @author Martin Geisler <gim...@gi...> * @version $Id$ @@ -13,25 +18,28 @@ class pw_dependency_or extends pw_dependency { /** - * Constructs a new 'or' dependency. - * - * @param string $option The name of the option that must satisfy - * one of the dependencies. - * - * @param array $dependencies This should be an array of strings. If - * the value of $option equals just one of these strings, then the - * dependency is satisfied. + * Constructs a new 'and' dependency. * + * @param mixed A variable number of other dependencies. This + * dependency is satisfied if at least one of the dependencies + * satisfied. */ - function pw_dependency_or($option, $dependencies) { - $this->pw_dependency($option, $dependencies); + function pw_dependency_or() { + $this->pw_dependency(func_get_args()); } + /** + * Checks the dependency. + * + * All the dependencies that were used to create this dependency is + * tested one after another until one of them is satisfied. + * + * @return boolean Returns true if at least one of the + * dependencies are satisfied. + */ function check() { - global $HTTP_SESSION_VARS; - $value = $HTTP_SESSION_VARS[$this->option]->get_value(); foreach ($this->dep as $d) { - if ($value == $d) return true; + if ($d->check()) return true; } return false; } Index: pw_dependency.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_dependency.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- pw_dependency.php 28 Dec 2002 00:52:54 -0000 1.3 +++ pw_dependency.php 1 Jul 2003 10:05:04 -0000 1.4 @@ -11,41 +11,30 @@ class pw_dependency { /** - * The name of an option. + * Other dependencies that this dependency depends on. * - * @var string The name of the option that should be checked. - */ - var $option; - - /** - * The value that the option must have to satisfy this dependency. - * - * @var string The required value. + * @var mixed Depending on the subclass, this can be an array of + * other dependencies, a string to match or something else. */ var $dep; /** * Constructs a new dependency. * - * @param string $option The name of the option that must satisfy - * the dependency. - * @param string $dep The required value of the option. - * + * @param string $dep Other dependencies. */ - function pw_dependency($option, $dep) { - $this->option = $option; + function pw_dependency($dep) { $this->dep = $dep; } /** - * Checks a dependency. + * Check the dependency. * - * @return boolean True if the dependency is satisfied, false - * otherwise. + * @return boolean Returns false because this is an abstract method. + * @abstract */ function check() { - global $HTTP_SESSION_VARS; - return ($HTTP_SESSION_VARS[$this->option]->get_value() == $this->dep); + trigger_error('Abstract method', E_USER_ERROR); } } ?> |