コード例 #1
0
ファイル: Compiler.php プロジェクト: mast3rpee/blw
 /**
  * Adds files in a directory for compilation.
  *
  * @throws \BLW\Model\FileException If <code>$Dir</code> is not a readable directory.
  * @throws \BLW\Model\InvalidArgumentException If <code>$Extention is
  * @param \BLW\Type\IFile $Dir
  *            Directory to add files from.
  * @param string $Extention
  *            [optional] Extention of files to add.
  * @param ...
  * @return boolean <code>TRUE</code> on success. <code>FALSE</code> otherwise.
  */
 public function addDir(IFile $Dir, $Extention = 'php')
 {
     // Is $Dir invalid?
     if (!$Dir->isDir() || !$Dir->isReadable()) {
         // Exception
         throw new FileException($Dir);
     }
     // Exclude regex
     $Excluded = '![\\x2f\\x5c](?:[^\\x2f\\x5c]*tests?|[^\\x2f\\x5c]*examples?|demos?|docs?)[\\x2f\\x5c]!i';
     // Include regex
     try {
         $Included = array_reduce(array_slice(func_get_args(), 1), array($this, '_extractExctentionRegex'), '');
         $Included = "!(?:{$Included})\$!i";
     } catch (InvalidArgumentException $e) {
         throw new InvalidArgumentException($e->getCode(), null, 0, $e);
     }
     // Add files
     $added = 0;
     $Dir = new RecursiveDirectoryIterator($Dir, FilesystemIterator::SKIP_DOTS | FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO);
     foreach (new RecursiveIteratorIterator($Dir, RecursiveIteratorIterator::SELF_FIRST) as $File) {
         // $File is a directory?
         if (is_dir($File)) {
             continue;
             // Is $File excluded?
         } elseif (preg_match($Excluded, $File)) {
             continue;
             // Is $File included
         } elseif (preg_match($Included, $File)) {
             // Is file readable?
             if (is_readable($File) && is_file($File)) {
                 // Add file
                 $this->_Files[] = $File;
                 // Increase counter
                 $added++;
             }
         }
     }
     // Done
     return $added > 1;
 }