[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/phing/tasks/system/ -> InputTask.php (source)

   1  <?php
   2  /*
   3   *  $Id: InputTask.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/input/InputRequest.php';
  24  include_once 'phing/input/YesNoInputRequest.php';
  25  include_once 'phing/input/MultipleChoiceInputRequest.php';
  26   
  27  /**
  28   * Reads input from the InputHandler.
  29   * 
  30   * @see       Project::getInputHandler()
  31   * @author    Hans Lellelid <hans@xmpl.org> (Phing)
  32   * @author    Ulrich Schmidt <usch@usch.net> (Ant)
  33   * @author    Stefan Bodewig <stefan.bodewig@epost.de> (Ant)
  34   * @version   $Revision: 1.6 $
  35   * @package   phing.tasks.system
  36   */
  37  class InputTask extends Task {
  38      
  39      private $validargs;
  40      private $message = ""; // required
  41      private $propertyName; // required
  42      private $defaultValue;
  43      private $promptChar;
  44      
  45      /**
  46       * Defines valid input parameters as comma separated strings. If set, input
  47       * task will reject any input not defined as accepted and requires the user
  48       * to reenter it. Validargs are case sensitive. If you want 'a' and 'A' to
  49       * be accepted you need to define both values as accepted arguments.
  50       *
  51       * @param validargs A comma separated String defining valid input args.
  52       */
  53      public function setValidargs ($validargs) {
  54          $this->validargs = $validargs;
  55      }
  56  
  57      /**
  58       * Defines the name of a property to be set from input.
  59       *
  60       * @param string $name Name for the property to be set from input
  61       */
  62      public function setPropertyName($name) {
  63          $this->propertyName = $name;
  64      }
  65  
  66      /**
  67       * Sets the Message which gets displayed to the user during the build run.
  68       * @param message The message to be displayed.
  69       */
  70      public function setMessage ($message) {
  71          $this->message = $message;
  72      }
  73  
  74      /**
  75       * Set a multiline message.
  76       */
  77      public function addText($msg) {
  78          $this->message .= $this->project->replaceProperties($msg);
  79      }
  80      
  81      /**
  82       * Add a default value.
  83       * @param string $v
  84       */
  85      public function setDefaultValue($v) {
  86          $this->defaultValue = $v;
  87      }
  88      
  89      /**
  90       * Set the character/string to use for the prompt.
  91       * @param string $c
  92       */
  93      public function setPromptChar($c) {
  94          $this->promptChar = $c;
  95      }
  96      
  97      /**
  98       * Actual method executed by phing.
  99       * @throws BuildException
 100       */
 101      public function main() {
 102      
 103          if ($this->propertyName === null) {
 104              throw new BuildException("You must specify a value for propertyName attribute.");
 105          }
 106          
 107          if ($this->validargs !== null) {
 108              $accept = preg_split('/[\s,]+/', $this->validargs);
 109              
 110              // is it a boolean (yes/no) inputrequest?
 111              $yesno = false;
 112              if (count($accept) == 2) {
 113                  $yesno = true;
 114                  foreach($accept as $ans) {
 115                      if(!StringHelper::isBoolean($ans)) {
 116                          $yesno = false;
 117                          break;
 118                      }
 119                  }
 120              }
 121              if ($yesno) $request = new YesNoInputRequest($this->message, $accept);
 122              else $request = new MultipleChoiceInputRequest($this->message, $accept);
 123          } else {
 124              $request = new InputRequest($this->message);
 125          }
 126          
 127          // default default is curr prop value        
 128          $request->setDefaultValue($this->project->getProperty($this->propertyName));
 129          
 130          $request->setPromptChar($this->promptChar);
 131          
 132          // unless overridden...
 133          if ($this->defaultValue !== null) {
 134              $request->setDefaultValue($this->defaultValue);
 135          }
 136          
 137          $this->project->getInputHandler()->handleInput($request);
 138  
 139          $value = $request->getInput();
 140          
 141          if ($value !== null) {
 142              $this->project->setUserProperty($this->propertyName, $value);
 143          }
 144      }
 145  
 146  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7