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