[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/vendor/phing/types/ -> TokenSource.php (source)

   1  <?php
   2  /*
   3   *  $Id: TokenSource.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/types/DataType.php';
  23  include_once 'phing/util/StringHelper.php';
  24  
  25  /**
  26   * A parameter is composed of a name, type and value.
  27   *
  28   * Example of usage:
  29   *
  30   * <replacetokens>
  31   *   <tokensource classname="phing.filters.util.IniFileTokenReader">
  32   *     <!-- all params for the TokenReader here -->
  33   *     <param name="file" value="tokens.ini" />
  34   *   </tokensource>
  35   * </replacetokens>
  36   *
  37   * or:
  38   * 
  39   * <filterreader classname="phing.filters.ReplaceTokens">
  40   *   <param type="tokensource>
  41   *     <param name="classname" value="phing.filters.util.IniFileTokenReader" />
  42   *     <param name="file" value="tokens.ini" />
  43   *   </param>
  44   * </filterreader>
  45   *
  46   * @author    <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a>
  47   * @package   phing.types
  48   */
  49  class TokenSource extends DataType {
  50  
  51      /**
  52       * String to hold the path to the TokenReader
  53       * @var     string
  54       */
  55      protected $classname = null;
  56  
  57      /**
  58       * Array holding parameters for the wrapped TokenReader.
  59       * @var array
  60       */
  61      protected $parameters = array();
  62  
  63      /**
  64       * Reference to the TokenReader used by this TokenSource
  65       * @var TokenReader
  66       */
  67      protected $reader;
  68  
  69      /**
  70       * Array with key/value pairs of tokens
  71       */
  72      protected $tokens = array();
  73  
  74      /**
  75       * This method is called to load the sources from the reader
  76       * into the buffer of the source.
  77       */
  78      function load() {
  79          // Create new Reader
  80          if ($this->classname === null) {
  81              throw new BuildException("No Classname given to TokenSource.");
  82          }
  83          
  84          $classname = Phing::import($this->classname);        
  85          $this->reader = new $classname($this->project);
  86  
  87          // Configure Reader
  88          $this->configureTokenReader($this->reader);
  89  
  90          // Load Tokens
  91          try {
  92              while ($token = $this->reader->readToken()) {
  93                  $this->tokens[] = $token;
  94              }
  95          } catch (BuildException $e) {
  96              $this->log("Error reading TokenSource: " . $e->getMessage(), PROJECT_MSG_WARN);
  97          } catch (IOException $e) {
  98              $this->log("Error reading TokenSource: " . $e->getMessage(), PROJECT_MSG_WARN);
  99          }
 100      }
 101  
 102      /**
 103       * This function uses the wrapper to read the tokens and then
 104       * returns them.
 105       *
 106       * @access  public
 107       */
 108      function getTokens() {
 109          if ($this->tokens === null)
 110              $this->Load();
 111  
 112          return $this->tokens;
 113      }
 114  
 115      /**
 116       * Configures a TokenReader with the parameters passed to the
 117       * TokenSource.
 118       * @param TokenReader $reader
 119       */
 120      private function configureTokenReader(TokenReader $reader) {
 121          $count = count($this->parameters);
 122          for ($i = 0; $i < $count; $i++) {
 123              $method_name = "Set" . $this->parameters[$i]->getName();
 124              $value = $this->parameters[$i]->getValue();
 125              $reader->$method_name($value);
 126          }
 127      }
 128      
 129      /**
 130       * Set the classname (dot-path) to use for handling token replacement.
 131       * @param string $c
 132       */
 133      function setClassname($c) {
 134          $this->classname = $c;
 135      }
 136      
 137      /**
 138       * Returns the qualified classname (dot-path) to use for handling token replacement.
 139       * @return string
 140       */
 141      function getClassname() {
 142          return $this->classname;
 143      }
 144  
 145      /**
 146       * Create nested <param> tag.
 147       * Uses standard name/value Parameter class.
 148       * @return Parameter
 149       */
 150      function createParam() {
 151          $num = array_push($this->parameters, new Parameter());
 152          return $this->parameters[$num-1];
 153      }
 154  }
 155  
 156  
 157  ?>


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