PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/install/phing/classes/phing/tasks/system/condition/EqualsCondition.php

https://github.com/chregu/fluxcms
PHP | 78 lines | 30 code | 10 blank | 38 comment | 3 complexity | 2c5451ad2b3a899e657c91af32d947b1 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/tasks/system/condition/Condition.php';
  22. /**
  23. * A simple string comparator. Compares two strings for eqiality in a
  24. * binary safe manner. Implements the condition interface specification.
  25. *
  26. * @author Andreas Aderhold <andi@binarycloud.com>
  27. * @copyright © 2001,2002 THYRELL. All rights reserved
  28. * @version $Revision: 1.7 $ $Date: 2003/12/24 13:02:09 $
  29. * @access public
  30. * @package phing.tasks.system.condition
  31. */
  32. class EqualsCondition implements Condition {
  33. private $arg1;
  34. private $arg2;
  35. private $trim = false;
  36. private $caseSensitive = true;
  37. public function setArg1($a1) {
  38. $this->arg1 = $a1;
  39. }
  40. public function setArg2($a2) {
  41. $this->arg2 = $a2;
  42. }
  43. /**
  44. * Should we want to trim the arguments before comparing them?
  45. * @param boolean $b
  46. */
  47. public function setTrim($b) {
  48. $this->trim = (boolean) $b;
  49. }
  50. /**
  51. * Should the comparison be case sensitive?
  52. * @param boolean $b
  53. */
  54. public function setCaseSensitive($b) {
  55. $this->caseSensitive = (boolean) $b;
  56. }
  57. public function evaluate() {
  58. if ($this->arg1 === null || $this->arg2 === null) {
  59. throw new BuildException("Both arg1 and arg2 are required in equals.");
  60. }
  61. if ($this->trim) {
  62. $this->arg1 = trim($this->arg1);
  63. $this->arg2 = trim($this->arg2);
  64. }
  65. //print("[comparison] Comparing '".$this->arg1."' and '".$this->arg2."'\n");
  66. return $this->caseSensitive ? $this->arg1 === $this->arg2 : strtolower($this->arg1) === strtolower($this->arg2);
  67. }
  68. }