PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/phing/tasks/system/AvailableTask.php

https://bitbucket.org/ealexandru/jobeet
PHP | 135 lines | 82 code | 20 blank | 33 comment | 22 complexity | 6873e9ba899050931778ce0b27f76275 MD5 | raw file
Possible License(s): ISC, AGPL-3.0, LGPL-2.1, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /*
  3. * $Id: AvailableTask.php 333 2007-12-28 21:30:09Z hans $
  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/Task.php';
  22. include_once 'phing/tasks/system/condition/ConditionBase.php';
  23. /**
  24. * <available> task.
  25. *
  26. * Note: implements condition interface (see condition/Condition.php)
  27. *
  28. * @author Andreas Aderhold <andi@binarycloud.com>
  29. * @copyright � 2001,2002 THYRELL. All rights reserved
  30. * @version $Revision: 1.11 $
  31. * @package phing.tasks.system
  32. */
  33. class AvailableTask extends Task {
  34. /** Property to check for. */
  35. private $property;
  36. /** Value property should be set to. */
  37. private $value = "true";
  38. /** Resource to check for */
  39. private $resource;
  40. private $type = null;
  41. private $filepath = null;
  42. function setProperty($property) {
  43. $this->property = (string) $property;
  44. }
  45. function setValue($value) {
  46. $this->value = (string) $value;
  47. }
  48. function setFile(PhingFile $file) {
  49. $this->file = $file;
  50. }
  51. function setResource($resource) {
  52. $this->resource = (string) $resource;
  53. }
  54. function setType($type) {
  55. $this->type = (string) strtolower($type);
  56. }
  57. function main() {
  58. if ($this->property === null) {
  59. throw new BuildException("property attribute is required", $this->location);
  60. }
  61. if ($this->evaluate()) {
  62. $this->project->setProperty($this->property, $this->value);
  63. }
  64. }
  65. function evaluate() {
  66. if ($this->file === null && $this->resource === null) {
  67. throw new BuildException("At least one of (file|resource) is required", $this->location);
  68. }
  69. if ($this->type !== null && ($this->type !== "file" && $this->type !== "dir")) {
  70. throw new BuildException("Type must be one of either dir or file", $this->location);
  71. }
  72. if (($this->file !== null) && !$this->_checkFile()) {
  73. $this->log("Unable to find " . $this->file->__toString() . " to set property " . $this->property, Project::MSG_VERBOSE);
  74. return false;
  75. }
  76. if (($this->resource !== null) && !$this->_checkResource($this->resource)) {
  77. $this->log("Unable to load resource " . $this->resource . " to set property " . $this->property, Project::MSG_VERBOSE);
  78. return false;
  79. }
  80. return true;
  81. }
  82. // this is prepared for the path type
  83. private function _checkFile() {
  84. if ($this->filepath === null) {
  85. return $this->_checkFile1($this->file);
  86. } else {
  87. $paths = $this->filepath->listDir();
  88. for($i=0,$pcnt=count($paths); $i < $pcnt; $i++) {
  89. $this->log("Searching " . $paths[$i], Project::MSG_VERBOSE);
  90. $tmp = new PhingFile($paths[$i], $this->file->getName());
  91. if($tmp->isFile()) {
  92. return true;
  93. }
  94. }
  95. }
  96. return false;
  97. }
  98. private function _checkFile1(PhingFile $file) {
  99. if ($this->type !== null) {
  100. if ($this->type === "dir") {
  101. return $file->isDirectory();
  102. } else if ($this->type === "file") {
  103. return $file->isFile();
  104. }
  105. }
  106. return $file->exists();
  107. }
  108. private function _checkResource($resource) {
  109. if (null != ($resourcePath = Phing::getResourcePath($resource))) {
  110. return $this->_checkFile1(new PhingFile($resourcePath));
  111. } else {
  112. return false;
  113. }
  114. }
  115. }