|
13 | 13 | namespace marcocesarato\amwscan;
|
14 | 14 |
|
15 | 15 | use ArrayIterator;
|
| 16 | +use ArrayObject; |
16 | 17 | use CallbackFilterIterator;
|
17 | 18 | use Exception;
|
18 | 19 | use LimitIterator;
|
19 | 20 | use Phar;
|
20 | 21 | use RecursiveDirectoryIterator;
|
21 | 22 | use RecursiveIteratorIterator;
|
| 23 | +use SplFileInfo; |
22 | 24 |
|
23 | 25 | /**
|
24 | 26 | * Class Application.
|
@@ -597,11 +599,6 @@ private function arguments($args = null)
|
597 | 599 | self::setPathScan(realpath($path));
|
598 | 600 | }
|
599 | 601 | }
|
600 |
| - |
601 |
| - // Check path |
602 |
| - if (!is_dir(self::$pathScan)) { |
603 |
| - self::setPathScan(pathinfo(self::$pathScan, PATHINFO_DIRNAME)); |
604 |
| - } |
605 | 602 | }
|
606 | 603 |
|
607 | 604 | /**
|
@@ -687,61 +684,67 @@ private function modes()
|
687 | 684 | public function mapping()
|
688 | 685 | {
|
689 | 686 | // Mapping files
|
690 |
| - $directory = new RecursiveDirectoryIterator(self::$pathScan); |
691 |
| - $files = new RecursiveIteratorIterator($directory); |
692 |
| - $filtered = new CallbackFilterIterator($files, function ($cur) { |
693 |
| - $ignore = false; |
694 |
| - $wildcard = '.*?'; // '[^\\\\\\/]*' |
695 |
| - // Ignore |
696 |
| - foreach (self::$ignorePaths as $ignorePath) { |
697 |
| - $ignorePath = preg_quote($ignorePath, ';'); |
698 |
| - $ignorePath = str_replace('\*', $wildcard, $ignorePath); |
699 |
| - if (preg_match(';' . $ignorePath . ';i', $cur->getPath())) { |
700 |
| - $ignore = true; |
| 687 | + if (is_dir(self::$pathScan)) { |
| 688 | + $directory = new RecursiveDirectoryIterator(self::$pathScan); |
| 689 | + $files = new RecursiveIteratorIterator($directory); |
| 690 | + $filtered = new CallbackFilterIterator($files, function ($cur) { |
| 691 | + $ignore = false; |
| 692 | + $wildcard = '.*?'; // '[^\\\\\\/]*' |
| 693 | + // Ignore |
| 694 | + foreach (self::$ignorePaths as $ignorePath) { |
| 695 | + $ignorePath = preg_quote($ignorePath, ';'); |
| 696 | + $ignorePath = str_replace('\*', $wildcard, $ignorePath); |
| 697 | + if (preg_match(';' . $ignorePath . ';i', $cur->getPath())) { |
| 698 | + $ignore = true; |
| 699 | + } |
701 | 700 | }
|
702 |
| - } |
703 |
| - // Filter |
704 |
| - foreach (self::$filterPaths as $filterPath) { |
705 |
| - $filterPath = preg_quote($filterPath, ';'); |
706 |
| - $filterPath = str_replace('\*', $wildcard, $filterPath); |
707 |
| - if (!preg_match(';' . $filterPath . ';i', $cur->getPath())) { |
708 |
| - $ignore = true; |
| 701 | + // Filter |
| 702 | + foreach (self::$filterPaths as $filterPath) { |
| 703 | + $filterPath = preg_quote($filterPath, ';'); |
| 704 | + $filterPath = str_replace('\*', $wildcard, $filterPath); |
| 705 | + if (!preg_match(';' . $filterPath . ';i', $cur->getPath())) { |
| 706 | + $ignore = true; |
| 707 | + } |
709 | 708 | }
|
710 |
| - } |
711 | 709 |
|
712 |
| - if (!$ignore && |
713 |
| - $cur->isDir()) { |
714 |
| - Modules::init($cur->getPath()); |
| 710 | + if (!$ignore && |
| 711 | + $cur->isDir()) { |
| 712 | + Modules::init($cur->getPath()); |
715 | 713 |
|
716 |
| - return false; |
717 |
| - } |
718 |
| - |
719 |
| - return |
720 |
| - !$ignore && |
721 |
| - $cur->isFile() && |
722 |
| - in_array($cur->getExtension(), self::getExtensions(), true); |
723 |
| - }); |
| 714 | + return false; |
| 715 | + } |
724 | 716 |
|
725 |
| - $mapping = array(); |
| 717 | + return |
| 718 | + !$ignore && |
| 719 | + $cur->isFile() && |
| 720 | + in_array($cur->getExtension(), self::getExtensions(), true); |
| 721 | + }); |
| 722 | + $mapping = array(); |
726 | 723 |
|
727 |
| - $mapped = 0; |
728 |
| - $count = iterator_count($filtered); |
| 724 | + $mapped = 0; |
| 725 | + $count = iterator_count($filtered); |
729 | 726 |
|
730 |
| - Console::writeBreak(1); |
731 |
| - Console::writeLine('Verifying files checksum...', 2); |
| 727 | + Console::writeBreak(1); |
| 728 | + Console::writeLine('Verifying files checksum...', 2); |
732 | 729 |
|
733 |
| - foreach ($filtered as $cur) { |
734 |
| - Console::progress($mapped++, $count); |
735 |
| - if ($cur->isFile() && !Modules::isVerified($cur->getPathname())) { |
736 |
| - $mapping[] = $cur; |
| 730 | + foreach ($filtered as $cur) { |
| 731 | + Console::progress($mapped++, $count); |
| 732 | + if ($cur->isFile() && !Modules::isVerified($cur->getPathname())) { |
| 733 | + $mapping[] = $cur; |
| 734 | + } |
| 735 | + Console::progress($mapped, $count); |
737 | 736 | }
|
738 |
| - Console::progress($mapped, $count); |
| 737 | + $iterator = new \ArrayObject($mapping); |
| 738 | + |
| 739 | + Console::writeBreak(1); |
| 740 | + |
| 741 | + return $iterator->getIterator(); |
739 | 742 | }
|
740 |
| - $iterator = new \ArrayObject($mapping); |
741 | 743 |
|
742 |
| - Console::writeBreak(1); |
| 744 | + $file = new SplFileInfo(self::$pathScan); |
| 745 | + $obj = new ArrayObject(array($file)); |
743 | 746 |
|
744 |
| - return $iterator->getIterator(); |
| 747 | + return $obj->getIterator(); |
745 | 748 | }
|
746 | 749 |
|
747 | 750 | /**
|
@@ -1349,7 +1352,7 @@ protected function interrupt()
|
1349 | 1352 | {
|
1350 | 1353 | $this->interrupt = true;
|
1351 | 1354 | if (self::isCli()) {
|
1352 |
| - die(); |
| 1355 | + exit(); |
1353 | 1356 | }
|
1354 | 1357 | }
|
1355 | 1358 |
|
|
0 commit comments