Changeset 8256
- Timestamp:
- 04/04/08 10:43:19 (1 year 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
r7767 r8256 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 symfony14 * @subpackage util15 * @author Fabien Potencier <fabien.potencier@symfony-project.com>16 * @version SVN: $Id$17 */18 11 19 12 /** … … 38 31 class sfFinder 39 32 { 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; 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; 50 45 51 46 /** … … 93 88 { 94 89 $finder = new sfFinder(); 95 90 return $finder->setType($name); 91 } 92 93 public function setType($name) 94 { 96 95 if (strtolower(substr($name, 0, 3)) == 'dir') 97 96 { 98 $ finder->type = 'directory';97 $this->type = 'directory'; 99 98 } 100 99 else if (strtolower($name) == 'any') 101 100 { 102 $ finder->type = 'any';101 $this->type = 'any'; 103 102 } 104 103 else 105 104 { 106 $ finder->type = 'file';107 } 108 109 return $ finder;105 $this->type = 'file'; 106 } 107 108 return $this; 110 109 } 111 110 … … 236 235 * Currently supports Subversion, CVS, DARCS, Gnu Arch, Monotone, Bazaar-NG, GIT, Mercurial 237 236 * 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); 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; 245 268 } 246 269 … … 263 286 if (is_array($args[$i]) && !method_exists($args[$i][0], $args[$i][1])) 264 287 { 265 throw new sfException( "method {$args[$i][1]} does not exist for object {$args[$i][0]}");288 throw new sfException(sprintf('method "%s" does not exist for object "%s".', $args[$i][1], $args[$i][0])); 266 289 } 267 290 else if (!is_array($args[$i]) && !function_exists($args[$i])) 268 291 { 269 throw new sfException( "function {$args[$i]} does not exist");292 throw new sfException(sprintf('function "%s" does not exist.', $args[$i])); 270 293 } 271 294 … … 310 333 $here_dir = getcwd(); 311 334 $numargs = func_num_args(); 312 $arg_list = func_get_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 } 313 345 314 346 // first argument is an array? … … 338 370 } 339 371 372 $dir = str_replace(array('/', '\\'), '/', $dir); 373 340 374 if ($this->relative) 341 375 { 342 $files = array_merge($files, str_replace($dir.DIRECTORY_SEPARATOR, '', $this->search_in($dir))); 376 $dir = rtrim($dir, '/'); 377 $files = array_merge($files, str_replace($dir.'/', '', str_replace(array('/', '\\'), '/', $finder->search_in($dir)))); 343 378 } 344 379 else 345 380 { 346 $files = array_merge($files, $this->search_in($dir)); 347 } 381 $files = array_merge($files, $finder->search_in($dir)); 382 } 383 } 384 385 if ($this->sort == 'name') 386 { 387 sort($files); 348 388 } 349 389 … … 364 404 365 405 $files = array(); 366 406 $temp_files = array(); 407 $temp_folders = array(); 367 408 if (is_dir($dir)) 368 409 { … … 379 420 380 421 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) 381 460 { 382 461 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)) … … 390 469 } 391 470 } 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 } 471 472 sort($temp_files); 473 $files = array_merge($files, $temp_files); 474 } 475 400 476 closedir($current_dir); 401 477 } … … 685 761 if (!preg_match('{^([<>]=?)?(.*?)([kmg]i?)?$}i', $this->test, $matches)) 686 762 { 687 throw new sfException( 'don\'t understand "'.$this->test.'" as a test');763 throw new sfException(sprintf('don\'t understand "%s" as a test.', $this->test)); 688 764 } 689 765

