[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: PropertyPromptTask.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/system/io/ConsoleReader.php'; 24 25 /** 26 * Deprecated task that uses console to prompt user for property values. 27 * 28 * This class is very slightly simpler than the InputTask, but lacks the ability 29 * to use a non-console input handler. You should, therefore, use InputTask. This 30 * class can serve as a reference, but will be removed in the future. 31 * 32 * @author Hans Lellelid <hans@xmpl.org> (Phing) 33 * @author Anthony J. Young-Garner <ajyoung@alum.mit.edu> (Ant) 34 * @version $Revision: 1.4 $ 35 * @package phing.tasks.system 36 * @deprecated - in favor of the more capable InputTask 37 */ 38 class PropertyPromptTask extends Task { 39 40 private $propertyName; // required 41 private $defaultValue; 42 private $proposedValue; // required 43 private $promptText; // required 44 private $promptCharacter; 45 private $useExistingValue; 46 47 /** 48 * Sets the prompt text that will be presented to the user. 49 * @param string $prompt 50 * @return void 51 */ 52 public function addText($prompt) { 53 $this->setPromptText($prompt); 54 } 55 56 /** 57 * Run the PropertyPrompt task. 58 * @throws BuildException 59 */ 60 public function main() { 61 $this->proposedValue = $this->project->getProperty($this->propertyName); 62 $currentValue = $this->defaultValue; 63 if ($currentValue == "" && $this->proposedValue !== null) { $currentValue = $this->proposedValue; } 64 if (! (($this->useExistingValue === true) && ($this->proposedValue !== null))) { 65 66 $this->log("Prompting user for " . $this->propertyName . ". " . $this->getDefaultMessage(), PROJECT_MSG_VERBOSE); 67 68 print "\n" . $this->promptText . " [" . $currentValue . "] " . $this->promptCharacter . " "; 69 70 /** future version should probably have hooks for validation of user input.*/ 71 $reader = new ConsoleReader(); 72 73 try { 74 $this->proposedValue = $reader->readLine(); 75 } catch (IOException $e) { 76 $this->log("Prompt failed. Using default. (Failure reason: " . $e->getMessage().")"); 77 $this->proposedValue = $this->defaultValue; 78 } 79 80 if (empty($this->proposedValue)) { 81 $this->log("No value specified, using default.", PROJECT_MSG_VERBOSE); 82 $this->proposedValue = $this->defaultValue; 83 } 84 85 if (!empty($this->proposedValue)) { 86 $this->project->setProperty($this->propertyName, $this->proposedValue); 87 } 88 89 } 90 } 91 92 /** 93 * Returns a string to be inserted in the log message 94 * indicating whether a default response was specified 95 * in the build file. 96 */ 97 private function getDefaultMessage() { 98 if ($this->defaultValue == "") { 99 return "No default response specified."; 100 } else return "Default response is " . $this->defaultValue . "."; 101 } 102 103 /** 104 * Returns defaultValue specified 105 * in this task for the Property 106 * being set. 107 * @return string 108 */ 109 public function getDefaultValue() { 110 return $this->defaultValue; 111 } 112 113 /** 114 * Returns the terminating character used to 115 * punctuate the prompt text. 116 * @return string 117 */ 118 public function getPromptCharacter() { 119 return $this->promptCharacter; 120 } 121 122 /** 123 * Returns text of the prompt. 124 * @return java.lang.String 125 */ 126 public function getPromptText() { 127 return $this->promptText; 128 } 129 130 /** 131 * Returns name of the Ant Project Property 132 * being set by this task. 133 * @return string 134 */ 135 public function getPropertyName() { 136 return $this->propertyName; 137 } 138 /** 139 * Initializes this task. 140 */ 141 public function init() { 142 parent::init(); 143 $this->defaultValue = ""; 144 $this->promptCharacter = "?"; 145 $this->useExistingValue = false; 146 } 147 148 /** 149 * Insert the method's description here. 150 * Creation date: (12/10/2001 8:16:16 AM) 151 * @return boolean 152 */ 153 public function isUseExistingValue() { 154 return $this->useExistingValue; 155 } 156 157 /** 158 * Sets defaultValue for the Property 159 * being set by this task. 160 * @param string $newDefaultvalue 161 */ 162 public function setDefaultvalue($newDefaultvalue) { 163 $this->defaultValue = $newDefaultvalue; 164 } 165 166 /** 167 * Sets the terminating character used to 168 * punctuate the prompt text (default is "?"). 169 * @param newPromptcharacter java.lang.String 170 */ 171 public function setPromptCharacter($newPromptcharacter) { 172 $this->promptCharacter = $newPromptcharacter; 173 } 174 175 /** 176 * Sets text of the prompt. 177 * @param newPrompttext java.lang.String 178 */ 179 public function setPromptText($newPrompttext) { 180 $this->promptText = $newPrompttext; 181 } 182 183 /** 184 * Specifies the Phing Project Property 185 * being set by this task. 186 * @param newPropertyname java.lang.String 187 */ 188 public function setPropertyName($newPropertyname) { 189 $this->propertyName = $newPropertyname; 190 } 191 192 /** 193 * 194 * 195 * @param boolean newUseExistingValue 196 */ 197 public function setUseExistingValue($newUseExistingValue) { 198 $this->useExistingValue = $newUseExistingValue; 199 } 200 201 }
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 |