[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: GlobMapper.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/mappers/FileNameMapper.php'; 23 24 /** 25 * description here 26 * 27 * @author Andreas Aderhold, andi@binarycloud.com 28 * @version $Revision: 1.10 $ 29 * @package phing.mappers 30 */ 31 class GlobMapper implements FileNameMapper { 32 33 /** 34 * Part of "from" pattern before the *. 35 */ 36 private $fromPrefix = null; 37 38 /** 39 * Part of "from" pattern after the *. 40 */ 41 private $fromPostfix = null; 42 43 /** 44 * Length of the prefix ("from" pattern). 45 */ 46 private $prefixLength; 47 48 /** 49 * Length of the postfix ("from" pattern). 50 */ 51 private $postfixLength; 52 53 /** 54 * Part of "to" pattern before the *. 55 */ 56 private $toPrefix = null; 57 58 /** 59 * Part of "to" pattern after the *. 60 */ 61 private $toPostfix = null; 62 63 64 function main($_sourceFileName) { 65 if (($this->fromPrefix === null) 66 || !StringHelper::startsWith($this->fromPrefix, $_sourceFileName) 67 || !StringHelper::endsWith($this->fromPostfix, $_sourceFileName)) { 68 return null; 69 } 70 $varpart = $this->_extractVariablePart($_sourceFileName); 71 $substitution = $this->toPrefix.$varpart.$this->toPostfix; 72 return array($substitution); 73 } 74 75 76 77 function setFrom($from) { 78 $index = strrpos($from, '*'); 79 80 if ($index === false) { 81 $this->fromPrefix = $from; 82 $this->fromPostfix = ""; 83 } else { 84 $this->fromPrefix = substr($from, 0, $index); 85 $this->fromPostfix = substr($from, $index+1); 86 } 87 $this->prefixLength = strlen($this->fromPrefix); 88 $this->postfixLength = strlen($this->fromPostfix); 89 } 90 91 /** 92 * Sets the "to" pattern. Required. 93 */ 94 function setTo($to) { 95 $index = strrpos($to, '*'); 96 if ($index === false) { 97 $this->toPrefix = $to; 98 $this->toPostfix = ""; 99 } else { 100 $this->toPrefix = substr($to, 0, $index); 101 $this->toPostfix = substr($to, $index+1); 102 } 103 } 104 105 private function _extractVariablePart($_name) { 106 // ergh, i really hate php's string functions .... all but natural 107 $start = ($this->prefixLength === 0) ? 0 : $this->prefixLength; 108 $end = ($this->postfixLength === 0) ? strlen($_name) : strlen($_name) - $this->postfixLength; 109 $len = $end-$start; 110 return substr($_name, $start, $len); 111 } 112 113 }
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 |