PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/phing/types/selectors/PresentSelector.php

https://github.com/IDCI-Consulting/WebsiteEval
PHP | 154 lines | 72 code | 14 blank | 68 comment | 15 complexity | fd464e2a0f589a2105311f4100c85333 MD5 | raw file
  1. <?php
  2. /*
  3. * $Id: PresentSelector.php 123 2006-09-14 20:19:08Z 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. /**
  22. * Selector that filters files based on whether they appear in another
  23. * directory tree. It can contain a mapper element, so isn't available
  24. * as an ExtendSelector (since those parameters can't hold other
  25. * elements).
  26. *
  27. * @author Hans Lellelid <hans@xmpl.org> (Phing)
  28. * @author Bruce Atherton <bruce@callenish.com> (Ant)
  29. * @package phing.types.selectors
  30. */
  31. class PresentSelector extends BaseSelector {
  32. private $targetdir = null;
  33. private $mapperElement = null;
  34. private $map = null;
  35. private $destmustexist = true;
  36. private static $filePresence = array("srconly", "both");
  37. public function toString() {
  38. $buf = "{presentselector targetdir: ";
  39. if ($this->targetdir === null) {
  40. $buf .= "NOT YET SET";
  41. } else {
  42. $buf .= $this->targetdir->getName();
  43. }
  44. $buf .= " present: ";
  45. if ($this->destmustexist) {
  46. $buf .= "both";
  47. } else {
  48. $buf .= "srconly";
  49. }
  50. if ($this->map !== null) {
  51. $buf .= $this->map->toString();
  52. } elseif ($this->mapperElement !== null) {
  53. $buf .= $this->mapperElement->toString();
  54. }
  55. $buf .= "}";
  56. return $buf;
  57. }
  58. /**
  59. * The name of the file or directory which is checked for matching
  60. * files.
  61. *
  62. * @param targetdir the directory to scan looking for matching files.
  63. */
  64. public function setTargetdir(PhingFile $targetdir) {
  65. $this->targetdir = $targetdir;
  66. }
  67. /**
  68. * Defines the FileNameMapper to use (nested mapper element).
  69. * @throws BuildException
  70. */
  71. public function createMapper() {
  72. if ($this->mapperElement !== null) {
  73. throw new BuildException("Cannot define more than one mapper");
  74. }
  75. $this->mapperElement = new Mapper($this->getProject());
  76. return $this->mapperElement;
  77. }
  78. /**
  79. * This sets whether to select a file if its dest file is present.
  80. * It could be a <code>negate</code> boolean, but by doing things
  81. * this way, we get some documentation on how the system works.
  82. * A user looking at the documentation should clearly understand
  83. * that the ONLY files whose presence is being tested are those
  84. * that already exist in the source directory, hence the lack of
  85. * a <code>destonly</code> option.
  86. *
  87. * @param string $fp An attribute set to either <code>srconly</code or
  88. * ><code>both</code>.
  89. */
  90. public function setPresent($fp) {
  91. $idx = array_search($fp, self::$filePresence, true);
  92. if ( $idx === 0 ) {
  93. $this->destmustexist = false;
  94. }
  95. }
  96. /**
  97. * Checks to make sure all settings are kosher. In this case, it
  98. * means that the targetdir attribute has been set and we have a mapper.
  99. */
  100. public function verifySettings() {
  101. if ($this->targetdir === null) {
  102. $this->setError("The targetdir attribute is required.");
  103. }
  104. if ($this->mapperElement === null) {
  105. $this->map = new IdentityMapper();
  106. } else {
  107. $this->map = $this->mapperElement->getImplementation();
  108. }
  109. if ($this->map === null) {
  110. $this->setError("Could not set <mapper> element.");
  111. }
  112. }
  113. /**
  114. * The heart of the matter. This is where the selector gets to decide
  115. * on the inclusion of a file in a particular fileset.
  116. *
  117. * @param basedir the base directory the scan is being done from
  118. * @param filename is the name of the file to check
  119. * @param file is a PhingFile object the selector can use
  120. * @return whether the file should be selected or not
  121. */
  122. public function isSelected(PhingFile $basedir, $filename, PhingFile $file) {
  123. $this->validate();
  124. // Determine file whose existence is to be checked
  125. $destfiles = $this->map->main($filename);
  126. // If filename does not match the To attribute of the mapper
  127. // then filter it out of the files we are considering
  128. if ($destfiles === null) {
  129. return false;
  130. }
  131. // Sanity check
  132. if (count($destfiles) !== 1 || $destfiles[0] === null) {
  133. throw new BuildException("Invalid destination file results for "
  134. . $this->targetdir . " with filename " . $filename);
  135. }
  136. $destname = $destfiles[0];
  137. $destfile = new PhingFile($this->targetdir, $destname);
  138. return $destfile->exists() === $this->destmustexist;
  139. }
  140. }