PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/phing/types/Mapper.php

https://bitbucket.org/ealexandru/jobeet
PHP | 207 lines | 123 code | 21 blank | 63 comment | 20 complexity | 5b796044d90d067f5978a0a09aea1ed2 MD5 | raw file
Possible License(s): ISC, AGPL-3.0, LGPL-2.1, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /*
  3. * $Id: Mapper.php 325 2007-12-20 15:44:58Z 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. include_once 'phing/types/DataType.php';
  22. include_once 'phing/types/Path.php';
  23. /**
  24. * Filename Mapper maps source file name(s) to target file name(s).
  25. *
  26. * Built-in mappers can be accessed by specifying they "type" attribute:
  27. * <code>
  28. * <mapper type="glob" from="*.php" to="*.php.bak"/>
  29. * </code>
  30. * Custom mappers can be specified by providing a dot-path to a include_path-relative
  31. * class:
  32. * <code>
  33. * <mapper classname="myapp.mappers.DevToProdMapper" from="*.php" to="*.php"/>
  34. * <!-- maps all PHP files from development server to production server, for example -->
  35. * </code>
  36. *
  37. * @author Hans Lellelid <hans@xmpl.org>
  38. * @package phing.types
  39. */
  40. class Mapper extends DataType {
  41. protected $type;
  42. protected $classname;
  43. protected $from;
  44. protected $to;
  45. protected $classpath;
  46. protected $classpathId;
  47. function __construct(Project $project) {
  48. $this->project = $project;
  49. }
  50. /**
  51. * Set the classpath to be used when searching for component being defined
  52. *
  53. * @param Path $classpath An Path object containing the classpath.
  54. */
  55. public function setClasspath(Path $classpath) {
  56. if ($this->isReference()) {
  57. throw $this->tooManyAttributes();
  58. }
  59. if ($this->classpath === null) {
  60. $this->classpath = $classpath;
  61. } else {
  62. $this->classpath->append($classpath);
  63. }
  64. }
  65. /**
  66. * Create the classpath to be used when searching for component being defined
  67. */
  68. public function createClasspath() {
  69. if ($this->isReference()) {
  70. throw $this->tooManyAttributes();
  71. }
  72. if ($this->classpath === null) {
  73. $this->classpath = new Path($this->project);
  74. }
  75. return $this->classpath->createPath();
  76. }
  77. /**
  78. * Reference to a classpath to use when loading the files.
  79. */
  80. public function setClasspathRef(Reference $r) {
  81. if ($this->isReference()) {
  82. throw $this->tooManyAttributes();
  83. }
  84. $this->classpathId = $r->getRefId();
  85. $this->createClasspath()->setRefid($r);
  86. }
  87. /** Set the type of FileNameMapper to use. */
  88. function setType($type) {
  89. if ($this->isReference()) {
  90. throw $this->tooManyAttributes();
  91. }
  92. $this->type = $type;
  93. }
  94. /** Set the class name of the FileNameMapper to use. */
  95. function setClassname($classname) {
  96. if ($this->isReference()) {
  97. throw $this->tooManyAttributes();
  98. }
  99. $this->classname = $classname;
  100. }
  101. /**
  102. * Set the argument to FileNameMapper.setFrom
  103. */
  104. function setFrom($from) {
  105. if ($this->isReference()) {
  106. throw $this->tooManyAttributes();
  107. }
  108. $this->from = $from;
  109. }
  110. /**
  111. * Set the argument to FileNameMapper.setTo
  112. */
  113. function setTo($to) {
  114. if ($this->isReference()) {
  115. throw $this->tooManyAttributes();
  116. }
  117. $this->to = $to;
  118. }
  119. /**
  120. * Make this Mapper instance a reference to another Mapper.
  121. *
  122. * You must not set any other attribute if you make it a reference.
  123. */
  124. function setRefid($r) {
  125. if ($this->type !== null || $this->from !== null || $this->to !== null) {
  126. throw DataType::tooManyAttributes();
  127. }
  128. parent::setRefid($r);
  129. }
  130. /** Factory, returns inmplementation of file name mapper as new instance */
  131. function getImplementation() {
  132. if ($this->isReference()) {
  133. $tmp = $this->getRef();
  134. return $tmp->getImplementation();
  135. }
  136. if ($this->type === null && $this->classname === null) {
  137. throw new BuildException("either type or classname attribute must be set for <mapper>");
  138. }
  139. if ($this->type !== null) {
  140. switch($this->type) {
  141. case 'identity':
  142. $this->classname = 'phing.mappers.IdentityMapper';
  143. break;
  144. case 'flatten':
  145. $this->classname = 'phing.mappers.FlattenMapper';
  146. break;
  147. case 'glob':
  148. $this->classname = 'phing.mappers.GlobMapper';
  149. break;
  150. case 'regexp':
  151. case 'regex':
  152. $this->classname = 'phing.mappers.RegexpMapper';
  153. break;
  154. case 'merge':
  155. $this->classname = 'phing.mappers.MergeMapper';
  156. break;
  157. default:
  158. throw new BuildException("Mapper type {$this->type} not known");
  159. break;
  160. }
  161. }
  162. // get the implementing class
  163. $cls = Phing::import($this->classname, $this->classpath);
  164. $m = new $cls;
  165. $m->setFrom($this->from);
  166. $m->setTo($this->to);
  167. return $m;
  168. }
  169. /** Performs the check for circular references and returns the referenced Mapper. */
  170. private function getRef() {
  171. if (!$this->checked) {
  172. $stk = array();
  173. $stk[] = $this;
  174. $this->dieOnCircularReference($stk, $this->project);
  175. }
  176. $o = $this->ref->getReferencedObject($this->project);
  177. if (!($o instanceof Mapper)) {
  178. $msg = $this->ref->getRefId()." doesn't denote a mapper";
  179. throw new BuildException($msg);
  180. } else {
  181. return $o;
  182. }
  183. }
  184. }