[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: ForeachTask.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 require_once 'phing/Task.php'; 23 include_once 'phing/tasks/system/PhingTask.php'; 24 25 /** 26 * <foreach> task 27 * 28 * Task definition for the foreach task. This task takes a list with 29 * delimited values, and executes a target with set param. 30 * 31 * Usage: 32 * <foreach list="values" target="targ" param="name" delimiter="|" /> 33 * 34 * Attributes: 35 * list --> The list of values to process, with the delimiter character, 36 * indicated by the "delimiter" attribute, separating each value. 37 * target --> The target to call for each token, passing the token as the 38 * parameter with the name indicated by the "param" attribute. 39 * param --> The name of the parameter to pass the tokens in as to the 40 * target. 41 * delimiter --> The delimiter string that separates the values in the "list" 42 * parameter. The default is ",". 43 * 44 * @author Jason Hines <jason@greenhell.com> 45 * @author Hans Lellelid <hans@xmpl.org> 46 * @version $Revision: 1.9 $ 47 * @package phing.tasks.system 48 */ 49 class ForeachTask extends Task { 50 51 /** Delimter-separated list of values to process. */ 52 private $list; 53 54 /** Name of parameter to pass to callee */ 55 private $param; 56 57 /** Delimter that separates items in $list */ 58 private $delimiter = ','; 59 60 /** 61 * PhingCallTask that will be invoked w/ calleeTarget. 62 * @var PhingCallTask 63 */ 64 private $callee; 65 66 /** 67 * Target to execute. 68 * @var string 69 */ 70 private $calleeTarget; 71 72 function init() { 73 $this->callee = $this->project->createTask("phingcall"); 74 $this->callee->setOwningTarget($this->getOwningTarget()); 75 $this->callee->setTaskName($this->getTaskName()); 76 $this->callee->setLocation($this->getLocation()); 77 $this->callee->init(); 78 } 79 80 /** 81 * This method does the work. 82 * @return void 83 */ 84 function main() { 85 if ($this->list === null) { 86 throw new BuildException("Missing list to iterate through"); 87 } 88 if (trim($this->list) === '') { 89 return; 90 } 91 if ($this->param === null) { 92 throw new BuildException("You must supply a property name to set on each iteration in param"); 93 } 94 if ($this->calleeTarget === null) { 95 throw new BuildException("You must supply a target to perform"); 96 } 97 98 $callee = $this->callee; 99 $callee->setTarget($this->calleeTarget); 100 $callee->setInheritAll(true); 101 $callee->setInheritRefs(true); 102 103 $arr = explode($this->delimiter, $this->list); 104 105 foreach ($arr as $value) { 106 $this->log("Setting param '$this->param' to value '$value'", PROJECT_MSG_VERBOSE); 107 $prop = $callee->createProperty(); 108 $prop->setOverride(true); 109 $prop->setName($this->param); 110 $prop->setValue($value); 111 $callee->main(); 112 } 113 } 114 115 function setList($list) { 116 $this->list = (string) $list; 117 } 118 119 function setTarget($target) { 120 $this->calleeTarget = (string) $target; 121 } 122 123 function setParam($param) { 124 $this->param = (string) $param; 125 } 126 127 function setDelimiter($delimiter) { 128 $this->delimiter = (string) $delimiter; 129 } 130 131 /** 132 * @return Property 133 */ 134 function createProperty() { 135 return $this->callee->createProperty(); 136 } 137 138 }
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 |