Development

Changeset 8259

You must first sign up to be able to contribute.

Changeset 8259

Show
Ignore:
Timestamp:
04/04/08 11:09:52 (2 years ago)
Author:
noel
Message:

reverted last change

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/lib/util/sfFinder.class.php

    r8256 r8259  
    44 * This file is part of the symfony package. 
    55 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 
    6  * 
     6 *  
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
    99 */ 
    1010 
     11/** 
     12 * 
     13 * @package    symfony 
     14 * @subpackage util 
     15 * @author     Fabien Potencier <fabien.potencier@symfony-project.com> 
     16 * @version    SVN: $Id$ 
     17 */ 
    1118 
    1219/** 
     
    3138class sfFinder 
    3239{ 
    33   protected $type                   = 'file'; 
    34   protected $names                  = array(); 
    35   protected $prunes                 = array(); 
    36   protected $discards               = array(); 
    37   protected $execs                  = array(); 
    38   protected $mindepth               = 0; 
    39   protected $sizes                  = array(); 
    40   protected $maxdepth               = 1000000; 
    41   protected $relative               = false; 
    42   protected $follow_link            = false; 
    43   protected $sort                   = false; 
    44   protected $ignore_version_control = true; 
     40  protected $type        = 'file'; 
     41  protected $names       = array(); 
     42  protected $prunes      = array(); 
     43  protected $discards    = array(); 
     44  protected $execs       = array(); 
     45  protected $mindepth    = 0; 
     46  protected $sizes       = array(); 
     47  protected $maxdepth    = 1000000; 
     48  protected $relative    = false; 
     49  protected $follow_link = false; 
    4550 
    4651  /** 
     
    8893  { 
    8994    $finder = new sfFinder(); 
    90     return $finder->setType($name); 
    91   } 
    92  
    93   public function setType($name) 
    94   { 
     95 
    9596    if (strtolower(substr($name, 0, 3)) == 'dir') 
    9697    { 
    97       $this->type = 'directory'; 
     98      $finder->type = 'directory'; 
    9899    } 
    99100    else if (strtolower($name) == 'any') 
    100101    { 
    101       $this->type = 'any'; 
     102      $finder->type = 'any'; 
    102103    } 
    103104    else 
    104105    { 
    105       $this->type = 'file'; 
    106     } 
    107  
    108     return $this
     106      $finder->type = 'file'; 
     107    } 
     108 
     109    return $finder
    109110  } 
    110111 
     
    235236   * Currently supports Subversion, CVS, DARCS, Gnu Arch, Monotone, Bazaar-NG, GIT, Mercurial 
    236237   * 
    237    * @return object current sfFinder object 
    238    */ 
    239   public function ignore_version_control($ignore = true) 
    240   { 
    241     $this->ignore_version_control = $ignore; 
    242  
    243     return $this; 
    244   } 
    245  
    246   /** 
    247    * Returns files and directories ordered by name 
    248    * 
    249    * @return object current sfFinder object 
    250    */ 
    251   public function sort_by_name() 
    252   { 
    253     $this->sort = 'name'; 
    254  
    255     return $this; 
    256   } 
    257  
    258   /** 
    259    * Returns files and directories ordered by type (directories before files), then by name 
    260    * 
    261    * @return object current sfFinder object 
    262    */ 
    263   public function sort_by_type() 
    264   { 
    265     $this->sort = 'type'; 
    266  
    267     return $this; 
     238   * @return object current pakeFinder object 
     239   */ 
     240  public function ignore_version_control() 
     241  { 
     242    $ignores = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg'); 
     243 
     244    return $this->discard($ignores)->prune($ignores); 
    268245  } 
    269246 
     
    286263      if (is_array($args[$i]) && !method_exists($args[$i][0], $args[$i][1])) 
    287264      { 
    288         throw new sfException(sprintf('method "%s" does not exist for object "%s".', $args[$i][1], $args[$i][0])); 
     265        throw new sfException("method {$args[$i][1]} does not exist for object {$args[$i][0]}"); 
    289266      } 
    290267      else if (!is_array($args[$i]) && !function_exists($args[$i])) 
    291268      { 
    292         throw new sfException(sprintf('function "%s" does not exist.', $args[$i])); 
     269        throw new sfException("function {$args[$i]} does not exist"); 
    293270      } 
    294271 
     
    333310    $here_dir = getcwd(); 
    334311    $numargs  = func_num_args(); 
    335     $arg_list = func_get_args(); 
    336  
    337     $finder = clone $this; 
    338  
    339     if ($this->ignore_version_control) 
    340     { 
    341       $ignores = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg'); 
    342  
    343       $finder->discard($ignores)->prune($ignores); 
    344     } 
     312    $arg_list = func_get_args();  
    345313 
    346314    // first argument is an array? 
     
    370338      } 
    371339 
    372       $dir = str_replace(array('/', '\\'), '/', $dir); 
    373  
    374340      if ($this->relative) 
    375341      { 
    376         $dir   = rtrim($dir, '/'); 
    377         $files = array_merge($files, str_replace($dir.'/', '', str_replace(array('/', '\\'), '/', $finder->search_in($dir)))); 
     342        $files = array_merge($files, str_replace($dir.DIRECTORY_SEPARATOR, '', $this->search_in($dir))); 
    378343      } 
    379344      else 
    380345      { 
    381         $files = array_merge($files, $finder->search_in($dir)); 
    382       } 
    383     } 
    384  
    385     if ($this->sort == 'name') 
    386     { 
    387       sort($files); 
     346        $files = array_merge($files, $this->search_in($dir)); 
     347      } 
    388348    } 
    389349 
     
    404364 
    405365    $files = array(); 
    406     $temp_files = array(); 
    407     $temp_folders = array(); 
     366 
    408367    if (is_dir($dir)) 
    409368    { 
     
    420379 
    421380        if (is_dir($current_entry)) 
    422         { 
    423           if ($this->sort == 'type') 
    424           { 
    425             $temp_folders[$entryname] = $current_entry; 
    426           } 
    427           else 
    428           { 
    429             if (($this->type == 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->exec_ok($dir, $entryname)) 
    430             { 
    431               $files[] = realpath($current_entry); 
    432             } 
    433  
    434             if (!$this->is_pruned($dir, $entryname)) 
    435             { 
    436               $files = array_merge($files, $this->search_in($current_entry, $depth + 1)); 
    437             } 
    438           } 
    439         } 
    440         else 
    441         { 
    442           if (($this->type != 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->size_ok($dir, $entryname) && $this->exec_ok($dir, $entryname)) 
    443           { 
    444             if ($this->sort == 'type') 
    445             { 
    446               $temp_files[] = realpath($current_entry); 
    447             } 
    448             else 
    449             { 
    450               $files[] = realpath($current_entry); 
    451             } 
    452           } 
    453         } 
    454       } 
    455  
    456       if ($this->sort == 'type') 
    457       { 
    458         ksort($temp_folders); 
    459         foreach($temp_folders as $entryname => $current_entry) 
    460381        { 
    461382          if (($this->type == 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->exec_ok($dir, $entryname)) 
     
    469390          } 
    470391        } 
    471  
    472         sort($temp_files); 
    473         $files = array_merge($files, $temp_files); 
    474       } 
    475  
     392        else 
     393        { 
     394          if (($this->type != 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->size_ok($dir, $entryname) && $this->exec_ok($dir, $entryname)) 
     395          { 
     396            $files[] = realpath($current_entry); 
     397          } 
     398        } 
     399      } 
    476400      closedir($current_dir); 
    477401    } 
     
    761685    if (!preg_match('{^([<>]=?)?(.*?)([kmg]i?)?$}i', $this->test, $matches)) 
    762686    { 
    763       throw new sfException(sprintf('don\'t understand "%s" as a test.', $this->test)); 
     687      throw new sfException('don\'t understand "'.$this->test.'" as a test'); 
    764688    } 
    765689 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.