Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/FileFinder.php
| Show All 15 Lines | |||||
| * @task internal Internal | * @task internal Internal | ||||
| * @group filesystem | * @group filesystem | ||||
| */ | */ | ||||
| final class FileFinder { | final class FileFinder { | ||||
| private $root; | private $root; | ||||
| private $exclude = array(); | private $exclude = array(); | ||||
| private $paths = array(); | private $paths = array(); | ||||
| private $name = array(); | |||||
| private $suffix = array(); | private $suffix = array(); | ||||
| private $type; | private $type; | ||||
| private $generateChecksums = false; | private $generateChecksums = false; | ||||
| private $followSymlinks; | private $followSymlinks; | ||||
| private $forceMode; | private $forceMode; | ||||
| /** | /** | ||||
| * Create a new FileFinder. | * Create a new FileFinder. | ||||
| Show All 12 Lines | final class FileFinder { | ||||
| public function excludePath($path) { | public function excludePath($path) { | ||||
| $this->exclude[] = $path; | $this->exclude[] = $path; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function withName($name) { | |||||
| $this->name[] = $name; | |||||
| return $this; | |||||
| } | |||||
| /** | |||||
| * @task config | |||||
| */ | |||||
| public function withSuffix($suffix) { | public function withSuffix($suffix) { | ||||
| $this->suffix[] = '*.'.$suffix; | $this->suffix[] = '*.'.$suffix; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| Show All 34 Lines | public function setForceMode($mode) { | ||||
| $this->forceMode = $mode; | $this->forceMode = $mode; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| public function validateFile($file) { | public function validateFile($file) { | ||||
| $matches = (count($this->suffix) == 0); | $matches = !count($this->name) && !count($this->suffix); | ||||
| foreach ($this->name as $curr_name) { | |||||
| if (basename($file) === $curr_name) { | |||||
| $matches = true; | |||||
| break; | |||||
| } | |||||
| } | |||||
epriestley: pls 2 clarifying parens T.T
or `count() || count()`? | |||||
| foreach ($this->suffix as $curr_suffix) { | foreach ($this->suffix as $curr_suffix) { | ||||
| if (fnmatch($curr_suffix, $file)) { | if (fnmatch($curr_suffix, $file)) { | ||||
| $matches = true; | $matches = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (!$matches) { | if (!$matches) { | ||||
| return false; | return false; | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if ($php_mode) { | ||||
| $command[] = '-o'; | $command[] = '-o'; | ||||
| } | } | ||||
| if ($this->type) { | if ($this->type) { | ||||
| $command[] = '-type %s'; | $command[] = '-type %s'; | ||||
| $args[] = $this->type; | $args[] = $this->type; | ||||
| } | } | ||||
| if ($this->suffix) { | if ($this->name || $this->suffix) { | ||||
| $command[] = $this->generateList('name', $this->suffix); | $command[] = $this->generateList('name', array_merge( | ||||
Not Done Inline ActionsThis should probably be array_merge()? The initial elements of suffix will be overwritten: $ php -r "print_r(array('example.js') + array('.js'));" Array ( [0] => example.js ) epriestley: This should probably be `array_merge()`? The initial elements of `suffix` will be overwritten… | |||||
| $this->name, | |||||
| $this->suffix)); | |||||
| } | } | ||||
| if ($this->paths) { | if ($this->paths) { | ||||
| $command[] = $this->generateList('path', $this->paths); | $command[] = $this->generateList('path', $this->paths); | ||||
| } | } | ||||
| $command[] = '-print0'; | $command[] = '-print0'; | ||||
| ▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines | |||||
pls 2 clarifying parens T.T
or count() || count()?