printTaskError(sprintf('Invalid glob "%s"!', $resource), $this); $success = false; continue; } foreach ($glob as $resource) { if (!$this->checkResource($resource, $type)) { $success = false; } } } return $success; } /** * Checks a single resource, file or directory. * * It will print an error as well on the console. * * @param string $resource File or folder. * @param string $type "file", "dir", "fileAndDir" * * @return bool */ protected function checkResource($resource, $type) { switch ($type) { case 'file': if (!$this->isFile($resource)) { $this->printTaskError(sprintf('File "%s" does not exist!', $resource), $this); return false; } return true; case 'dir': if (!$this->isDir($resource)) { $this->printTaskError(sprintf('Directory "%s" does not exist!', $resource), $this); return false; } return true; case 'fileAndDir': if (!$this->isDir($resource) && !$this->isFile($resource)) { $this->printTaskError(sprintf('File or directory "%s" does not exist!', $resource), $this); return false; } return true; } } /** * Convenience method to check the often uses "source => target" file / folder arrays. * * @param string|array $resources */ protected function checkSourceAndTargetResource($resources) { if (is_string($resources)) { $resources = [$resources]; } $sources = []; $targets = []; foreach ($resources as $source => $target) { $sources[] = $source; $target[] = $target; } $this->checkResources($sources); $this->checkResources($targets); } /** * Wrapper method around phps is_dir() * * @param string $directory * * @return bool */ protected function isDir($directory) { return is_dir($directory); } /** * Wrapper method around phps file_exists() * * @param string $file * * @return bool */ protected function isFile($file) { return file_exists($file); } }