PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/chregu/fluxcms
PHP | 76 lines | 25 code | 9 blank | 42 comment | 2 complexity | 7714b4d35c5d68388057dae1a33c201b 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. * Is one string part of another string?
  24. *
  25. * @author Hans Lellelid <hans@xmpl.org> (Phing)
  26. * @author Stefan Bodewig <stefan.bodewig@epost.de> (Ant)
  27. * @version $Revision: 1.3 $
  28. * @package phing.tasks.system.condition
  29. */
  30. class ContainsCondition implements Condition {
  31. private $string;
  32. private $subString;
  33. private $caseSensitive = true;
  34. /**
  35. * The string to search in.
  36. * @param string $a1
  37. */
  38. public function setString($a1) {
  39. $this->string = $a1;
  40. }
  41. /**
  42. * The string to search for.
  43. * @param string $a2
  44. */
  45. public function setSubstring($a2) {
  46. $this->subString = $a2;
  47. }
  48. /**
  49. * Whether to search ignoring case or not.
  50. */
  51. public function setCaseSensitive($b) {
  52. $this->caseSensitive = (boolean) $b;
  53. }
  54. /**
  55. * Check whether string contains substring.
  56. * @throws BuildException
  57. */
  58. public function evaluate() {
  59. if ($this->string === null || $this->subString === null) {
  60. throw new BuildException("both string and substring are required "
  61. . "in contains");
  62. }
  63. return $this->caseSensitive
  64. ? strpos($this->string, $this->subString) !== false
  65. : substr(strtolower($this->string), strtolower($this->subString)) !== false;
  66. }
  67. }