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

   1  <?php
   2  /*
   3   *  $Id: AbstractFileSet.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  include_once 'phing/system/io/PhingFile.php';
  23  include_once 'phing/types/DataType.php';
  24  include_once 'phing/types/PatternSet.php';
  25  include_once 'phing/types/selectors/BaseSelector.php';
  26  include_once 'phing/types/selectors/SelectorContainer.php';
  27  include_once 'phing/types/selectors/BaseSelectorContainer.php';
  28  
  29  // Load all of the selectors (not really necessary but
  30  // helps reveal parse errors right away)
  31  
  32  include_once 'phing/types/selectors/AndSelector.php';
  33  include_once 'phing/types/selectors/ContainsSelector.php';
  34  include_once 'phing/types/selectors/ContainsRegexpSelector.php';
  35  include_once 'phing/types/selectors/DateSelector.php';
  36  include_once 'phing/types/selectors/DependSelector.php';
  37  include_once 'phing/types/selectors/DepthSelector.php';
  38  include_once 'phing/types/selectors/ExtendSelector.php';
  39  include_once 'phing/types/selectors/FilenameSelector.php';
  40  include_once 'phing/types/selectors/MajoritySelector.php';
  41  include_once 'phing/types/selectors/NoneSelector.php';
  42  include_once 'phing/types/selectors/NotSelector.php';
  43  include_once 'phing/types/selectors/OrSelector.php';
  44  include_once 'phing/types/selectors/PresentSelector.php';
  45  include_once 'phing/types/selectors/SizeSelector.php';
  46  include_once 'phing/types/selectors/TypeSelector.php';
  47  
  48  include_once 'phing/util/DirectoryScanner.php';
  49  
  50  /**
  51   * The FileSet class provides methods and properties for accessing
  52   * and managing filesets. It extends ProjectComponent and thus inherits
  53   * all methods and properties (not explicitly declared). See ProjectComponent
  54   * for further detail.
  55   *
  56   * TODO:
  57   *   - merge this with patternsets: FileSet extends PatternSet !!!
  58   *     requires additional mods to the parsing algo
  59   *         [HL] .... not sure if that really makes so much sense.  I think
  60   *            that perhaps they should use common utility class if there really
  61   *            is that much shared functionality
  62   *
  63   * @author    Andreas Aderhold <andi@binarycloud.com>
  64   * @author    Hans Lellelid <hans@xmpl.org>
  65   * @version    $Revision: 1.15 $ $Date: 2005/05/26 13:10:53 $
  66   * @see        ProjectComponent
  67   * @package    phing.types
  68   */
  69  class AbstractFileSet extends DataType implements SelectorContainer {
  70      
  71      // These vars are public for cloning purposes
  72      
  73      /**
  74       * @var boolean
  75       */
  76      public $useDefaultExcludes = true;
  77      
  78      /**
  79       * @var PatternSet
  80       */
  81      public $defaultPatterns;
  82      
  83      public $additionalPatterns = array();
  84      public $dir;
  85      public $isCaseSensitive = true;    
  86      public $selectors = array();
  87      
  88      function __construct($fileset = null) {
  89          if ($fileset !== null && ($fileset instanceof FileSet)) {
  90              $this->dir = $fileset->dir;
  91              $this->defaultPatterns = $fileset->defaultPatterns;
  92              $this->additionalPatterns = $fileset->additionalPatterns;
  93              $this->useDefaultExcludes = $fileset->useDefaultExcludes;
  94              $this->isCaseSensitive = $fileset->isCaseSensitive;
  95              $this->selectors = $fileset->selectors;
  96          }
  97          $this->defaultPatterns = new PatternSet();
  98      }
  99  
 100  
 101      /**
 102      * Makes this instance in effect a reference to another PatternSet
 103      * instance.
 104      * You must not set another attribute or nest elements inside
 105      * this element if you make it a reference.
 106      */
 107      function setRefid(Reference $r) {
 108          if ((isset($this->dir) && !is_null($this->dir)) || $this->defaultPatterns->hasPatterns()) {
 109              throw $this->tooManyAttributes();
 110          }
 111          if (!empty($this->additionalPatterns)) {
 112              throw $this->noChildrenAllowed();
 113          }
 114          if (!empty($this->selectors)) {
 115              throw $this->noChildrenAllowed();
 116          }
 117          parent::setRefid($r);
 118      }
 119  
 120  
 121      function setDir($dir) {
 122          if ($this->isReference()) {
 123              throw $this->tooManyAttributes();
 124          }
 125          if ($dir instanceof PhingFile) {
 126              $dir = $dir->getPath();
 127          }
 128          $this->dir = new PhingFile((string) $dir);
 129      }
 130  
 131  
 132      function getDir(Project $p) {
 133          if ($this->isReference()) {
 134              return $this->getRef($p)->getDir($p);
 135          }
 136          return $this->dir;
 137      }
 138  
 139  
 140      function createPatternSet() {
 141          if ($this->isReference()) {
 142              throw $this->noChildrenAllowed();
 143          }
 144          $num = array_push($this->additionalPatterns, new PatternSet());
 145          return $this->additionalPatterns[$num-1];
 146      }
 147  
 148      /**
 149      * add a name entry on the include list
 150      */
 151      function createInclude() {
 152          if ($this->isReference()) {
 153              throw $this->noChildrenAllowed();
 154          }
 155          return $this->defaultPatterns->createInclude();
 156      }
 157  
 158      /**
 159       * add a name entry on the include files list
 160       */
 161      function createIncludesFile() {
 162          if ($this->isReference()) {
 163              throw $this->noChildrenAllowed();
 164          }
 165          return $this->defaultPatterns->createIncludesFile();
 166      }
 167  
 168      /**
 169       * add a name entry on the exclude list
 170       */
 171      function createExclude() {
 172          if ($this->isReference()) {
 173              throw $this->noChildrenAllowed();
 174          }
 175          return $this->defaultPatterns->createExclude();
 176      }
 177  
 178      /**
 179       * add a name entry on the include files list
 180       */
 181      function createExcludesFile() {
 182          if ($this->isReference()) {
 183              throw $this->noChildrenAllowed();
 184              return;
 185          }
 186          return $this->defaultPatterns->createExcludesFile();
 187      }
 188  
 189      /**
 190       * Sets the set of include patterns. Patterns may be separated by a comma
 191       * or a space.
 192       */
 193      function setIncludes($includes) {
 194          if ($this->isReference()) {
 195              throw $this->tooManyAttributes();
 196          }
 197          $this->defaultPatterns->setIncludes($includes);
 198      }
 199  
 200      /**
 201       * Sets the set of exclude patterns. Patterns may be separated by a comma
 202       * or a space.
 203       */
 204      function setExcludes($excludes) {
 205          if ($this->isReference()) {
 206              throw $this->tooManyAttributes();
 207          }
 208          $this->defaultPatterns->setExcludes($excludes);
 209      }
 210  
 211      /**
 212       * Sets the name of the file containing the includes patterns.
 213       *
 214       * @param $incl The file to fetch the include patterns from.
 215       * @throws BE
 216       */
 217      function setIncludesfile($incl) {
 218          if ($this->isReference()) {
 219              throw $this->tooManyAttributes();
 220          }
 221          $this->defaultPatterns->setIncludesfile($incl);
 222      }
 223  
 224      /**
 225       * Sets the name of the file containing the includes patterns.
 226       *
 227       * @param $excl The file to fetch the exclude patterns from.
 228       * @throws BE
 229       */
 230      function setExcludesfile($excl) {
 231          if ($this->isReference()) {
 232              throw $this->tooManyAttributes();
 233          }
 234          $this->defaultPatterns->setExcludesfile($excl);
 235      }
 236  
 237      /**
 238       * Sets whether default exclusions should be used or not.
 239       *
 240       * @param $useDefaultExcludes "true"|"on"|"yes" when default exclusions
 241       *                           should be used, "false"|"off"|"no" when they
 242       *                           shouldn't be used.
 243       */
 244      function setDefaultexcludes($useDefaultExcludes) {
 245          if ($this->isReference()) {
 246              throw $this->tooManyAttributes();
 247          }
 248          $this->useDefaultExcludes = $useDefaultExcludes;
 249      }
 250  
 251      /**
 252       * Sets case sensitivity of the file system
 253       */
 254      function setCaseSensitive($isCaseSensitive) {
 255          $this->isCaseSensitive = $isCaseSensitive;
 256      }
 257  
 258      /** returns a reference to the dirscanner object belonging to this fileset */
 259      function getDirectoryScanner(Project $p) {
 260          if ($this->isReference()) {
 261              $o = $this->getRef($p);
 262              return $o->getDirectoryScanner($p);
 263          }
 264  
 265          if ($this->dir === null) {
 266              throw new BuildException("No directory specified for fileset.");
 267          }
 268          if (!$this->dir->exists()) {
 269              throw new BuildException("Directory ".$this->dir->getAbsolutePath()." not found.");
 270          }
 271          if (!$this->dir->isDirectory()) {
 272              throw new BuildException($this->dir->getAbsolutePath()." is not a directory.");
 273          }
 274          $ds = new DirectoryScanner();
 275          $this->setupDirectoryScanner($ds, $p);
 276          $ds->scan();
 277          return $ds;
 278      }
 279  
 280      /** feed dirscanner with infos defined by this fileset */
 281      protected function setupDirectoryScanner(DirectoryScanner $ds, Project $p) {
 282          if ($ds === null) {
 283              throw new Exception("DirectoryScanner cannot be null");
 284          }
 285          // FIXME - pass dir directly wehn dirscanner supports File
 286          $ds->setBasedir($this->dir->getPath());
 287          
 288          foreach($this->additionalPatterns as $addPattern) {
 289              $this->defaultPatterns->append($addPattern, $p);
 290          }              
 291  
 292          $ds->setIncludes($this->defaultPatterns->getIncludePatterns($p));
 293          $ds->setExcludes($this->defaultPatterns->getExcludePatterns($p));
 294  
 295          $p->log("FileSet: Setup file scanner in dir " . $this->dir->__toString() . " with " . $this->defaultPatterns->toString(), PROJECT_MSG_DEBUG);
 296          
 297          if ($ds instanceof SelectorScanner) {
 298              $ds->setSelectors($this->getSelectors($p));
 299          }
 300          
 301          if ($this->useDefaultExcludes) {
 302              $ds->addDefaultExcludes();
 303          }
 304          $ds->setCaseSensitive($this->isCaseSensitive);
 305      }
 306  
 307  
 308      /**
 309       * Performs the check for circular references and returns the
 310       * referenced FileSet.
 311       */
 312      function getRef(Project $p) {
 313          if (!$this->checked) {
 314              $stk = array();
 315              array_push($stk, $this);
 316              $this->dieOnCircularReference($stk, $p);            
 317          }
 318  
 319          $o = $this->ref->getReferencedObject($p);
 320          if (!($o instanceof FileSet)) {
 321              $msg = $this->ref->getRefId()." doesn't denote a fileset";
 322              throw new BuildException($msg);
 323          } else {
 324              return $o;
 325          }
 326      }
 327      
 328      // SelectorContainer methods
 329  
 330      /**
 331       * Indicates whether there are any selectors here.
 332       *
 333       * @return boolean Whether any selectors are in this container
 334       */
 335      public function hasSelectors() {
 336          if ($this->isReference() && $this->getProject() !== null) {
 337              return $this->getRef($this->getProject())->hasSelectors();
 338          }
 339          return !empty($this->selectors);
 340      }
 341  
 342      /**
 343       * Indicates whether there are any patterns here.
 344       *
 345       * @return boolean Whether any patterns are in this container.
 346       */
 347      public function hasPatterns() {
 348      
 349          if ($this->isReference() && $this->getProject() !== null) {
 350              return $this->getRef($this->getProject())->hasPatterns();            
 351          }
 352  
 353          if ($this->defaultPatterns->hasPatterns($this->getProject())) {
 354              return true;
 355          }
 356  
 357          for($i=0,$size=count($this->additionalPatterns); $i < $size; $i++) {
 358              $ps = $this->additionalPatterns[$i];
 359              if ($ps->hasPatterns($this->getProject())) {
 360                  return true;
 361              }
 362          }
 363  
 364          return false;
 365      }
 366      
 367      /**
 368       * Gives the count of the number of selectors in this container
 369       *
 370       * @return int The number of selectors in this container
 371       */
 372      public function selectorCount() {
 373          if ($this->isReference() && $this->getProject() !== null) {
 374              try {
 375                  return $this->getRef($this->getProject())->selectorCount();
 376              } catch (Exception $e) {
 377                  throw $e;
 378              }
 379          }
 380          return count($this->selectors);
 381      }
 382  
 383      /**
 384       * Returns the set of selectors as an array.
 385       *
 386       * @return an array of selectors in this container
 387       */
 388      public function getSelectors(Project $p) {
 389          if ($this->isReference()) {
 390              return $this->getRef($p)->getSelectors($p);            
 391          } else {
 392              // *copy* selectors
 393              $result = array();
 394              for($i=0,$size=count($this->selectors); $i < $size; $i++) {
 395                  $result[] = clone $this->selectors[$i];
 396              }
 397              return $result;
 398          }
 399      }
 400  
 401      /**
 402       * Returns an array for accessing the set of selectors.
 403       *
 404       * @return array The array of selectors
 405       */
 406      public function selectorElements() {
 407          if ($this->isReference() && $this->getProject() !== null) {
 408              return $this->getRef($this->getProject())->selectorElements();            
 409          }
 410          return $this->selectors;
 411      }
 412  
 413      /**
 414       * Add a new selector into this container.
 415       *
 416       * @param selector the new selector to add
 417       */
 418      public function appendSelector(FileSelector $selector) {
 419          if ($this->isReference()) {
 420              throw $this->noChildrenAllowed();
 421          }
 422          $this->selectors[] = $selector;
 423      }    
 424  
 425      /* Methods below all add specific selectors */
 426  
 427      /**
 428       * add a "Select" selector entry on the selector list
 429       */
 430      public function createSelector() {
 431          $o = new SelectSelector();
 432          $this->appendSelector($o);
 433          return $o;
 434      }
 435  
 436      /**
 437       * add an "And" selector entry on the selector list
 438       */
 439      public function createAnd() {
 440          $o = new AndSelector();
 441          $this->appendSelector($o);
 442          return $o;
 443      }
 444  
 445      /**
 446       * add an "Or" selector entry on the selector list
 447       */
 448      public function createOr() {
 449          $o = new OrSelector();
 450          $this->appendSelector($o);
 451          return $o;
 452      }
 453  
 454      /**
 455       * add a "Not" selector entry on the selector list
 456       */
 457      public function createNot() {
 458          $o = new NotSelector();
 459          $this->appendSelector($o);
 460          return $o;
 461      }
 462  
 463      /**
 464       * add a "None" selector entry on the selector list
 465       */
 466      public function createNone() {
 467          $o = new NoneSelector();
 468          $this->appendSelector($o);
 469          return $o;
 470      }
 471  
 472      /**
 473       * add a majority selector entry on the selector list
 474       */
 475      public function createMajority() {
 476          $o = new MajoritySelector();
 477          $this->appendSelector($o);
 478          return $o;
 479      }
 480  
 481      /**
 482       * add a selector date entry on the selector list
 483       */
 484      public function createDate() {
 485          $o = new DateSelector();
 486          $this->appendSelector($o);
 487          return $o;
 488      }
 489  
 490      /**
 491       * add a selector size entry on the selector list
 492       */
 493      public function createSize() {
 494          $o = new SizeSelector();
 495          $this->appendSelector($o);
 496          return $o;
 497      }
 498  
 499      /**
 500       * add a selector filename entry on the selector list
 501       */
 502      public function createFilename() {
 503          $o = new FilenameSelector();
 504          $this->appendSelector($o);
 505          return $o;
 506      }
 507  
 508      /**
 509       * add an extended selector entry on the selector list
 510       */
 511      public function createCustom() {
 512          $o = new ExtendSelector();
 513          $this->appendSelector($o);
 514          return $o;
 515      }
 516  
 517      /**
 518       * add a contains selector entry on the selector list
 519       */
 520      public function createContains() {
 521          $o = new ContainsSelector();
 522          $this->appendSelector($o);
 523          return $o;
 524      }
 525  
 526      /**
 527       * add a contains selector entry on the selector list
 528       */
 529      public function createContainsRegexp() {
 530          $o = new ContainsRegexpSelector();
 531          $this->appendSelector($o);
 532          return $o;
 533      }
 534  
 535      /**
 536       * add a present selector entry on the selector list
 537       */
 538      public function createPresent() {
 539          $o = new PresentSelector();
 540          $this->appendSelector($o);
 541          return $o;
 542      }
 543  
 544      /**
 545       * add a depth selector entry on the selector list
 546       */
 547      public function createDepth() {
 548          $o = new DepthSelector();
 549          $this->appendSelector($o);
 550          return $o;
 551      }
 552  
 553      /**
 554       * add a depends selector entry on the selector list
 555       */
 556      public function createDepend() {        
 557          $o = new DependSelector();
 558          $this->appendSelector($o);
 559          return $o;
 560      }
 561      
 562      /**
 563       * add a type selector entry on the selector list
 564       */
 565      public function createType() {
 566          $o = new TypeSelector();
 567          $this->appendSelector($o);
 568          return $o;
 569      }
 570  }


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