Changeset 8259
- Timestamp:
- 04/04/08 11:09:52 (2 years ago)
- Files:
-
- branches/1.0/lib/util/sfFinder.class.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/lib/util/sfFinder.class.php
r8256 r8259 4 4 * This file is part of the symfony package. 5 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 6 * 7 7 * For the full copyright and license information, please view the LICENSE 8 8 * file that was distributed with this source code. 9 9 */ 10 10 11 /** 12 * 13 * @package symfony 14 * @subpackage util 15 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 16 * @version SVN: $Id$ 17 */ 11 18 12 19 /** … … 31 38 class sfFinder 32 39 { 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; 45 50 46 51 /** … … 88 93 { 89 94 $finder = new sfFinder(); 90 return $finder->setType($name); 91 } 92 93 public function setType($name) 94 { 95 95 96 if (strtolower(substr($name, 0, 3)) == 'dir') 96 97 { 97 $ this->type = 'directory';98 $finder->type = 'directory'; 98 99 } 99 100 else if (strtolower($name) == 'any') 100 101 { 101 $ this->type = 'any';102 $finder->type = 'any'; 102 103 } 103 104 else 104 105 { 105 $ this->type = 'file';106 } 107 108 return $ this;106 $finder->type = 'file'; 107 } 108 109 return $finder; 109 110 } 110 111 … … 235 236 * Currently supports Subversion, CVS, DARCS, Gnu Arch, Monotone, Bazaar-NG, GIT, Mercurial 236 237 * 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); 268 245 } 269 246 … … 286 263 if (is_array($args[$i]) && !method_exists($args[$i][0], $args[$i][1])) 287 264 { 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]}"); 289 266 } 290 267 else if (!is_array($args[$i]) && !function_exists($args[$i])) 291 268 { 292 throw new sfException( sprintf('function "%s" does not exist.', $args[$i]));269 throw new sfException("function {$args[$i]} does not exist"); 293 270 } 294 271 … … 333 310 $here_dir = getcwd(); 334 311 $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(); 345 313 346 314 // first argument is an array? … … 370 338 } 371 339 372 $dir = str_replace(array('/', '\\'), '/', $dir);373 374 340 if ($this->relative) 375 341 { 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))); 378 343 } 379 344 else 380 345 { 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 } 388 348 } 389 349 … … 404 364 405 365 $files = array(); 406 $temp_files = array(); 407 $temp_folders = array(); 366 408 367 if (is_dir($dir)) 409 368 { … … 420 379 421 380 if (is_dir($current_entry)) 422 {423 if ($this->sort == 'type')424 {425 $temp_folders[$entryname] = $current_entry;426 }427 else428 {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 else441 {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 else449 {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)460 381 { 461 382 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)) … … 469 390 } 470 391 } 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 } 476 400 closedir($current_dir); 477 401 } … … 761 685 if (!preg_match('{^([<>]=?)?(.*?)([kmg]i?)?$}i', $this->test, $matches)) 762 686 { 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'); 764 688 } 765 689

