Recca0120\Terminal\Console\Commands\Find::fire PHP Метод

fire() публичный Метод

fire.
public fire ( )
    public function fire()
    {
        // set_time_limit(30);
        $path = $this->argument('path');
        $name = $this->option('name');
        $type = $this->option('type');
        $maxDepth = $this->option('maxdepth');
        $delete = $this->option('delete');
        $root = $this->getLaravel()->basePath();
        $path = realpath($root . '/' . $path);
        $this->finder->in($path);
        if ($name !== null) {
            $this->finder->name($name);
        }
        switch ($type) {
            case 'd':
                $this->finder->directories();
                break;
            case 'f':
                $this->finder->files();
                break;
        }
        if ($maxDepth !== null) {
            if ($maxDepth == '0') {
                $this->line($path);
                return;
            }
            $this->finder->depth('<' . $maxDepth);
        }
        foreach ($this->finder as $file) {
            $realPath = $file->getRealpath();
            if ($delete === 'true' && $filesystem->exists($realPath) === true) {
                try {
                    if ($filesystem->isDirectory($realPath) === true) {
                        $deleted = $filesystem->deleteDirectory($realPath, true);
                    } else {
                        $deleted = $filesystem->delete($realPath);
                    }
                } catch (Exception $e) {
                }
                if ($deleted === true) {
                    $this->info('removed ' . $realPath);
                } else {
                    $this->error('removed ' . $realPath . ' fail');
                }
            } else {
                $this->line($file->getRealpath());
            }
        }
    }