[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * $Id: PrefixLines.php 3076 2006-12-18 08:52:12Z fabien $ 5 * 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 * 18 * This software consists of voluntary contributions made by many individuals 19 * and is licensed under the LGPL. For more information please see 20 * <http://phing.info>. 21 */ 22 23 include_once 'phing/filters/BaseParamFilterReader.php'; 24 include_once 'phing/filters/ChainableReader.php'; 25 26 /** 27 * Attaches a prefix to every line. 28 * 29 * Example: 30 * <pre><prefixlines prefix="Foo"/></pre> 31 * 32 * Or: 33 * 34 * <pre><filterreader classname="phing.filters.PrefixLines"> 35 * <param name="prefix" value="Foo"/> 36 * </filterreader></pre> 37 * 38 * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> 39 * @author hans lellelid, hans@velum.net 40 * @version $Revision: 1.6 $ $Date: 2004/03/15 14:45:06 $ 41 * @access public 42 * @see FilterReader 43 * @package phing.filters 44 */ 45 class PrefixLines extends BaseParamFilterReader implements ChainableReader { 46 47 /** 48 * Parameter name for the prefix. 49 * @var string 50 */ 51 const PREFIX_KEY = "lines"; 52 53 /** 54 * The prefix to be used. 55 * @var string 56 */ 57 private $_prefix = null; 58 59 /** 60 * Adds a prefix to each line of input stream and returns resulting stream. 61 * 62 * @return mixed buffer, -1 on EOF 63 */ 64 function read($len = null) { 65 if ( !$this->getInitialized() ) { 66 $this->_initialize(); 67 $this->setInitialized(true); 68 } 69 70 $buffer = $this->in->read($len); 71 72 if ($buffer === -1) { 73 return -1; 74 } 75 76 $lines = explode("\n", $buffer); 77 $filtered = array(); 78 79 foreach($lines as $line) { 80 $line = $this->_prefix . $line; 81 $filtered[] = $line; 82 } 83 84 $filtered_buffer = implode("\n", $filtered); 85 return $filtered_buffer; 86 } 87 88 /** 89 * Sets the prefix to add at the start of each input line. 90 * 91 * @param string $prefix The prefix to add at the start of each input line. 92 * May be <code>null</code>, in which case no prefix 93 * is added. 94 */ 95 function setPrefix($prefix) { 96 $this->_prefix = (string) $prefix; 97 } 98 99 /** 100 * Returns the prefix which will be added at the start of each input line. 101 * 102 * @return string The prefix which will be added at the start of each input line 103 */ 104 function getPrefix() { 105 return $this->_prefix; 106 } 107 108 /** 109 * Creates a new PrefixLines filter using the passed in 110 * Reader for instantiation. 111 * 112 * @param object A Reader object providing the underlying stream. 113 * Must not be <code>null</code>. 114 * 115 * @return object A new filter based on this configuration, but filtering 116 * the specified reader 117 */ 118 function chain(Reader $reader) { 119 $newFilter = new PrefixLines($reader); 120 $newFilter->setPrefix($this->getPrefix()); 121 $newFilter->setInitialized(true); 122 $newFilter->setProject($this->getProject()); 123 return $newFilter; 124 } 125 126 /** 127 * Initializes the prefix if it is available from the parameters. 128 */ 129 private function _initialize() { 130 $params = $this->getParameters(); 131 if ( $params !== null ) { 132 for($i = 0, $_i=count($params) ; $i < $_i ; $i++) { 133 if ( self::PREFIX_KEY == $params[$i]->getName() ) { 134 $this->_prefix = (string) $params[$i]->getValue(); 135 break; 136 } 137 } 138 } 139 } 140 } 141 142 ?>
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 |