[ 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/ -> DataType.php (source)

   1  <?php
   2  /*
   3   *  $Id: DataType.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/ProjectComponent.php';
  23  include_once 'phing/BuildException.php';
  24  
  25  /**
  26   * Base class for those classes that can appear inside the build file
  27   * as stand alone data types.
  28   *
  29   * This class handles the common description attribute and provides
  30   * a default implementation for reference handling and checking for
  31   * circular references that is appropriate for types that can not be
  32   * nested inside elements of the same type (i.e. patternset but not path)
  33   *
  34   * @package   phing.types
  35   */
  36  class DataType extends ProjectComponent {
  37  
  38      /** The descriptin the user has set. */
  39      public $description = null;
  40  
  41      /** Value to the refid attribute. Type of Reference*/
  42      public $ref = null;
  43  
  44      /**
  45       * Are we sure we don't hold circular references?
  46       *
  47       * Subclasses are responsible for setting this value to false
  48       * if we'd need to investigate this condition (usually because a
  49       * child element has been added that is a subclass of DataType).
  50       * @var boolean
  51       */
  52      protected $checked = true;
  53    
  54      /**
  55       * Sets a description of the current data type. It will be useful
  56       * in commenting what we are doing.
  57       */
  58      function setDescription($desc) {
  59          $this->description = (string) $desc;
  60      }
  61  
  62      /** Return the description for the current data type. */
  63      function getDescription() {
  64          return $this->description;
  65      }
  66  
  67      /** Has the refid attribute of this element been set? */
  68      function isReference() {
  69          return ($this->ref !== null);
  70      }
  71  
  72      /**
  73       * Set the value of the refid attribute.
  74       *
  75       * Subclasses may need to check whether any other attributes
  76       * have been set as well or child elements have been created and
  77       * thus override this method. if they do they must call parent::setRefid()
  78       * 
  79       * @param Reference $r
  80       * @return void
  81       */
  82      function setRefid(Reference $r) {
  83          $this->ref = $r;
  84          $this->checked = false;
  85      }
  86  
  87      /**
  88       * Check to see whether any DataType we hold references to is
  89       * included in the Stack (which holds all DataType instances that
  90       * directly or indirectly reference this instance, including this
  91       * instance itself).
  92       *
  93       * If one is included, throw a BuildException created by circularReference
  94       *
  95       * This implementation is appropriate only for a DataType that
  96       * cannot hold other DataTypes as children.
  97       *
  98       * The general contract of this method is that it shouldn't do
  99       * anything if checked is true and set it to true on exit.
 100       */
 101      function dieOnCircularReference(&$stk, Project $p) {
 102          if ($this->checked || !$this->isReference()) {
 103              return;
 104          }
 105  
 106          $o = $this->ref->getReferencedObject($p);
 107  
 108          if ($o instanceof DataType) {
 109              
 110              // TESTME - make sure that in_array() works just as well here
 111              //
 112              // check if reference is in stack
 113              //$contains = false;
 114              //for ($i=0, $size=count($stk); $i < $size; $i++) {
 115              //    if ($stk[$i] === $o) {
 116              //        $contains = true;
 117              //        break;
 118              //    }
 119              //}
 120  
 121              if (in_array($o, $stk, true)) {
 122                  // throw build exception
 123                  throw $this->circularReference();
 124              } else {
 125                  array_push($stk, $o);
 126                  $o->dieOnCircularReference($stk, $p);
 127                  array_pop($stk);
 128              }
 129          }
 130          $this->checked = true;
 131      }
 132  
 133      /** Performs the check for circular references and returns the referenced object. */
 134      function getCheckedRef($requiredClass, $dataTypeName) {
 135      
 136          if (!$this->checked) {
 137              // should be in stack
 138              $stk = array();
 139              $stk[] = $this;
 140              $this->dieOnCircularReference($stk, $this->getProject());            
 141          }
 142  
 143          $o = $this->ref->getReferencedObject($this->getProject());
 144          if (!($o instanceof $requiredClass) ) {
 145              throw new BuildException($this->ref->getRefId()." doesn't denote a " . $dataTypeName);
 146          } else {
 147              return $o;
 148          }
 149      }
 150  
 151      /**
 152       * Creates an exception that indicates that refid has to be the
 153       * only attribute if it is set.
 154       */
 155      function tooManyAttributes() {
 156          return new BuildException( "You must not specify more than one attribute when using refid" );
 157      }
 158  
 159      /**
 160       * Creates an exception that indicates that this XML element must
 161       * not have child elements if the refid attribute is set.
 162       */
 163      function noChildrenAllowed() {
 164          return new BuildException("You must not specify nested elements when using refid");
 165      }
 166  
 167      /**
 168       * Creates an exception that indicates the user has generated a
 169       * loop of data types referencing each other.
 170       */
 171      function circularReference() {
 172          return new BuildException("This data type contains a circular reference.");
 173      }
 174      
 175      /**
 176       * Template method being called when the data type has been 
 177       * parsed completely.
 178       * @return void
 179       */
 180      function parsingComplete() {}
 181  }
 182  


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