ConditionTask.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * $Id: ConditionTask.php 905 2010-10-05 16:28:03Z mrook $
  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/ConditionBase.php';
  22. /**
  23. * <condition> task as a generalization of <available>
  24. *
  25. * <p>This task supports boolean logic as well as pluggable conditions
  26. * to decide, whether a property should be set.</p>
  27. *
  28. * <p>This task does not extend Task to take advantage of
  29. * ConditionBase.</p>
  30. *
  31. * @author Andreas Aderhold <andi@binarycloud.com>
  32. * @copyright © 2001,2002 THYRELL. All rights reserved
  33. * @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
  34. * @access public
  35. * @package phing.tasks.system
  36. */
  37. class ConditionTask extends ConditionBase {
  38. private $property;
  39. private $value = "true";
  40. /**
  41. * The name of the property to set. Required.
  42. */
  43. function setProperty($p) {
  44. $this->property = $p;
  45. }
  46. /**
  47. * The value for the property to set. Defaults to "true".
  48. */
  49. function setValue($v) {
  50. $this->value = $v;
  51. }
  52. /**
  53. * See whether our nested condition holds and set the property.
  54. */
  55. function main() {
  56. if ($this->countConditions() > 1) {
  57. throw new BuildException("You must not nest more than one condition into <condition>");
  58. }
  59. if ($this->countConditions() < 1) {
  60. throw new BuildException("You must nest a condition into <condition>");
  61. }
  62. $cs = $this->getIterator();
  63. if ($cs->current()->evaluate()) {
  64. $this->project->setProperty($this->property, $this->value);
  65. }
  66. }
  67. }