From ea1eb531930fa32503df13188cbe98fafb2d5361 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sat, 3 Jul 2021 14:08:29 +0800 Subject: [PATCH 01/11] Refactor methods to an abstract class so we can extend to it and re-use some methods --- .../GroupedEndpointsAbstract.php | 85 +++++++++++++++++++ .../GroupedEndpointsFromApp.php | 71 ++-------------- .../GroupedEndpointsFromTests.php | 43 ++++++++++ 3 files changed, 134 insertions(+), 65 deletions(-) create mode 100644 src/GroupedEndpoints/GroupedEndpointsAbstract.php create mode 100644 src/GroupedEndpoints/GroupedEndpointsFromTests.php diff --git a/src/GroupedEndpoints/GroupedEndpointsAbstract.php b/src/GroupedEndpoints/GroupedEndpointsAbstract.php new file mode 100644 index 00000000..b85930f4 --- /dev/null +++ b/src/GroupedEndpoints/GroupedEndpointsAbstract.php @@ -0,0 +1,85 @@ +command = $command; + $this->docConfig = $command->getDocConfig(); + $this->preserveUserChanges = $preserveUserChanges; + + static::$camelDir = GenerateDocumentation::$camelDir; + static::$cacheDir = GenerateDocumentation::$cacheDir; + } + + public function get(): array + { + $groupedEndpoints = $this->extractEndpointsInfoAndWriteToDisk(); + $this->extractAndWriteApiDetailsToDisk(); + + return $groupedEndpoints; + } + + protected function extractAndWriteApiDetailsToDisk(): void + { + $apiDetails = new ApiDetails($this->docConfig, !$this->command->option('force')); + $apiDetails->writeMarkdownFiles(); + } + + protected function writeEndpointsToDisk(array $grouped): void + { + Utils::deleteFilesMatching(static::$camelDir, function (array $file) { + return !Str::startsWith($file['basename'], 'custom.'); + }); + Utils::deleteDirectoryAndContents(static::$cacheDir); + + if (!is_dir(static::$camelDir)) { + mkdir(static::$camelDir, 0777, true); + } + + if (!is_dir(static::$cacheDir)) { + mkdir(static::$cacheDir, 0777, true); + } + + $fileNameIndex = 0; + foreach ($grouped as $group) { + $yaml = Yaml::dump( + $group, + 20, + 2, + Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK + ); + if ( + count(Camel::$groupFileNames) == count($grouped) + && isset(Camel::$groupFileNames[$group['name']]) + ) { + $fileName = Camel::$groupFileNames[$group['name']]; + } else { + $fileName = "$fileNameIndex.yaml"; + $fileNameIndex++; + } + + file_put_contents(static::$camelDir . "/$fileName", $yaml); + file_put_contents(static::$cacheDir . "/$fileName", "## Autogenerated by Scribe. DO NOT MODIFY.\n\n" . $yaml); + } + } + + abstract protected function extractEndpointsInfoAndWriteToDisk(): array; +} diff --git a/src/GroupedEndpoints/GroupedEndpointsFromApp.php b/src/GroupedEndpoints/GroupedEndpointsFromApp.php index 9281b988..11611915 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromApp.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromApp.php @@ -21,36 +21,17 @@ use ReflectionClass; use Symfony\Component\Yaml\Yaml; -class GroupedEndpointsFromApp implements GroupedEndpointsContract +class GroupedEndpointsFromApp extends GroupedEndpointsAbstract implements GroupedEndpointsContract { - private $command; private $routeMatcher; - private $docConfig; - private $preserveUserChanges; private bool $encounteredErrors = false; - - public static string $camelDir; - public static string $cacheDir; - private array $endpointGroupIndexes = []; public function __construct(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher, $preserveUserChanges) { - $this->command = $command; - $this->routeMatcher = $routeMatcher; - $this->docConfig = $command->getDocConfig(); - $this->preserveUserChanges = $preserveUserChanges; - - static::$camelDir = GenerateDocumentation::$camelDir; - static::$cacheDir = GenerateDocumentation::$cacheDir; - } - - public function get(): array - { - $groupedEndpoints = $this->extractEndpointsInfoAndWriteToDisk($this->routeMatcher, $this->preserveUserChanges); - $this->extractAndWriteApiDetailsToDisk(); + parent::__construct($command, $preserveUserChanges); - return $groupedEndpoints; + $this->routeMatcher = $routeMatcher; } public function hasEncounteredErrors(): bool @@ -58,19 +39,19 @@ public function hasEncounteredErrors(): bool return $this->encounteredErrors; } - protected function extractEndpointsInfoAndWriteToDisk(RouteMatcherInterface $routeMatcher, bool $preserveUserChanges): array + protected function extractEndpointsInfoAndWriteToDisk(): array { $latestEndpointsData = []; $cachedEndpoints = []; $groups = []; - if ($preserveUserChanges && is_dir(static::$camelDir) && is_dir(static::$cacheDir)) { + if ($this->preserveUserChanges && is_dir(static::$camelDir) && is_dir(static::$cacheDir)) { $latestEndpointsData = Camel::loadEndpointsToFlatPrimitivesArray(static::$camelDir); $cachedEndpoints = Camel::loadEndpointsToFlatPrimitivesArray(static::$cacheDir, true); $groups = Camel::loadEndpointsIntoGroups(static::$camelDir); } - $routes = $routeMatcher->getRoutes($this->docConfig->get('routes'), $this->docConfig->get('router')); + $routes = $this->routeMatcher->getRoutes($this->docConfig->get('routes'), $this->docConfig->get('router')); $endpoints = $this->extractEndpointsInfoFromLaravelApp($routes, $cachedEndpoints, $latestEndpointsData, $groups); $groupedEndpoints = Camel::groupEndpoints($endpoints, $this->endpointGroupIndexes); $this->writeEndpointsToDisk($groupedEndpoints); @@ -187,40 +168,6 @@ private function mergeAnyEndpointDataUpdates(ExtractedEndpointData $endpointData return [$endpointData, $index]; } - protected function writeEndpointsToDisk(array $grouped): void - { - Utils::deleteFilesMatching(static::$camelDir, function (array $file) { - return !Str::startsWith($file['basename'], 'custom.'); - }); - Utils::deleteDirectoryAndContents(static::$cacheDir); - - if (!is_dir(static::$camelDir)) { - mkdir(static::$camelDir, 0777, true); - } - - if (!is_dir(static::$cacheDir)) { - mkdir(static::$cacheDir, 0777, true); - } - - $fileNameIndex = 0; - foreach ($grouped as $group) { - $yaml = Yaml::dump( - $group, 20, 2, - Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK - ); - if (count(Camel::$groupFileNames) == count($grouped) - && isset(Camel::$groupFileNames[$group['name']])) { - $fileName = Camel::$groupFileNames[$group['name']]; - } else { - $fileName = "$fileNameIndex.yaml"; - $fileNameIndex++; - } - - file_put_contents(static::$camelDir . "/$fileName", $yaml); - file_put_contents(static::$cacheDir . "/$fileName", "## Autogenerated by Scribe. DO NOT MODIFY.\n\n" . $yaml); - } - } - private function isValidRoute(array $routeControllerAndMethod = null): bool { if (is_array($routeControllerAndMethod)) { @@ -276,10 +223,4 @@ protected function writeExampleCustomEndpoint(): void copy(__DIR__ . '/../../resources/example_custom_endpoint.yaml', static::$camelDir . '/custom.0.yaml'); } } - - protected function extractAndWriteApiDetailsToDisk(): void - { - $apiDetails = new ApiDetails($this->docConfig, !$this->command->option('force')); - $apiDetails->writeMarkdownFiles(); - } } diff --git a/src/GroupedEndpoints/GroupedEndpointsFromTests.php b/src/GroupedEndpoints/GroupedEndpointsFromTests.php new file mode 100644 index 00000000..5f2c4dfd --- /dev/null +++ b/src/GroupedEndpoints/GroupedEndpointsFromTests.php @@ -0,0 +1,43 @@ +encounteredErrors; + } + + protected function extractEndpointsInfoAndWriteToDisk(): array + { + $latestEndpointsData = []; + $cachedEndpoints = []; + $groups = []; + + if ($this->preserveUserChanges && is_dir(static::$camelDir) && is_dir(static::$cacheDir)) { + $latestEndpointsData = Camel::loadEndpointsToFlatPrimitivesArray(static::$camelDir); + $cachedEndpoints = Camel::loadEndpointsToFlatPrimitivesArray(static::$cacheDir, true); + $groups = Camel::loadEndpointsIntoGroups(static::$camelDir); + } + + $endpoints = $this->extractEndpointsInfoFromTests(); + $groupedEndpoints = Camel::groupEndpoints($endpoints, $this->endpointGroupIndexes); + $this->writeEndpointsToDisk($groupedEndpoints); + $groupedEndpoints = Camel::prepareGroupedEndpointsForOutput($groupedEndpoints); + return $groupedEndpoints; + } + + private function extractEndpointsInfoFromTests(): array + { + // TODO: Implement logic + return []; + } +} From d62c809651a0336a04c74ffb0c2f6c2b6e6281f3 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sat, 3 Jul 2021 14:24:49 +0800 Subject: [PATCH 02/11] Fix, remove unused --- src/GroupedEndpoints/GroupedEndpointsFromTests.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/GroupedEndpoints/GroupedEndpointsFromTests.php b/src/GroupedEndpoints/GroupedEndpointsFromTests.php index 5f2c4dfd..0f9cff8c 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromTests.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromTests.php @@ -18,16 +18,6 @@ public function hasEncounteredErrors(): bool protected function extractEndpointsInfoAndWriteToDisk(): array { - $latestEndpointsData = []; - $cachedEndpoints = []; - $groups = []; - - if ($this->preserveUserChanges && is_dir(static::$camelDir) && is_dir(static::$cacheDir)) { - $latestEndpointsData = Camel::loadEndpointsToFlatPrimitivesArray(static::$camelDir); - $cachedEndpoints = Camel::loadEndpointsToFlatPrimitivesArray(static::$cacheDir, true); - $groups = Camel::loadEndpointsIntoGroups(static::$camelDir); - } - $endpoints = $this->extractEndpointsInfoFromTests(); $groupedEndpoints = Camel::groupEndpoints($endpoints, $this->endpointGroupIndexes); $this->writeEndpointsToDisk($groupedEndpoints); From c8c251c47f9f3fc37e03b9b8241b9fde58006230 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sat, 3 Jul 2021 14:28:26 +0800 Subject: [PATCH 03/11] Fix --- src/GroupedEndpoints/GroupedEndpointsAbstract.php | 4 +--- src/GroupedEndpoints/GroupedEndpointsFromApp.php | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/GroupedEndpoints/GroupedEndpointsAbstract.php b/src/GroupedEndpoints/GroupedEndpointsAbstract.php index b85930f4..4649efed 100644 --- a/src/GroupedEndpoints/GroupedEndpointsAbstract.php +++ b/src/GroupedEndpoints/GroupedEndpointsAbstract.php @@ -14,16 +14,14 @@ abstract class GroupedEndpointsAbstract { protected GenerateDocumentation $command; protected DocumentationConfig $docConfig; - protected bool $preserveUserChanges; public static string $camelDir; public static string $cacheDir; - public function __construct(GenerateDocumentation $command, bool $preserveUserChanges) + public function __construct(GenerateDocumentation $command) { $this->command = $command; $this->docConfig = $command->getDocConfig(); - $this->preserveUserChanges = $preserveUserChanges; static::$camelDir = GenerateDocumentation::$camelDir; static::$cacheDir = GenerateDocumentation::$cacheDir; diff --git a/src/GroupedEndpoints/GroupedEndpointsFromApp.php b/src/GroupedEndpoints/GroupedEndpointsFromApp.php index 11611915..ac31b679 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromApp.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromApp.php @@ -24,14 +24,16 @@ class GroupedEndpointsFromApp extends GroupedEndpointsAbstract implements GroupedEndpointsContract { private $routeMatcher; + private bool $preserveUserChanges; private bool $encounteredErrors = false; private array $endpointGroupIndexes = []; - public function __construct(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher, $preserveUserChanges) + public function __construct(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher, bool $preserveUserChanges) { - parent::__construct($command, $preserveUserChanges); + parent::__construct($command); $this->routeMatcher = $routeMatcher; + $this->preserveUserChanges = $preserveUserChanges; } public function hasEncounteredErrors(): bool From 1fa2d3cd8d830dbc41ebf8351a00803814f3fe87 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sun, 4 Jul 2021 14:15:22 +0800 Subject: [PATCH 04/11] Elaborate comment --- src/GroupedEndpoints/GroupedEndpointsFromTests.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/GroupedEndpoints/GroupedEndpointsFromTests.php b/src/GroupedEndpoints/GroupedEndpointsFromTests.php index 0f9cff8c..f3d2fdd2 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromTests.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromTests.php @@ -27,7 +27,10 @@ protected function extractEndpointsInfoAndWriteToDisk(): array private function extractEndpointsInfoFromTests(): array { - // TODO: Implement logic + // TODO: Implement: + // First, run the phpunit tests to extract the $groupedEndpoints + // and write them to the yaml files just like when we write them when we extracted them from Laravel app. + // Then return the $groupedEndpoints. return []; } } From cdd036ef176aa3de26a0547f952125c9f2ababd6 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sun, 4 Jul 2021 14:17:08 +0800 Subject: [PATCH 05/11] Fix comment --- src/GroupedEndpoints/GroupedEndpointsFromTests.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/GroupedEndpoints/GroupedEndpointsFromTests.php b/src/GroupedEndpoints/GroupedEndpointsFromTests.php index f3d2fdd2..510183cd 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromTests.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromTests.php @@ -27,10 +27,7 @@ protected function extractEndpointsInfoAndWriteToDisk(): array private function extractEndpointsInfoFromTests(): array { - // TODO: Implement: - // First, run the phpunit tests to extract the $groupedEndpoints - // and write them to the yaml files just like when we write them when we extracted them from Laravel app. - // Then return the $groupedEndpoints. + // TODO: Run the phpunit tests to extract and return the endpoints. return []; } } From 6336d4ceff777109d735e82a278666de45829d5e Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sun, 4 Jul 2021 14:31:12 +0800 Subject: [PATCH 06/11] Return GroupedEndpointsFromTests in factory if from_tests.enabled --- config/scribe.php | 7 +++++++ src/GroupedEndpoints/GroupedEndpointsFactory.php | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/config/scribe.php b/config/scribe.php index 425e1dae..c1503ca9 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -187,6 +187,13 @@ 'base_url' => null, ], + 'from_tests' => [ + /** + * Generate api documentation by running phpunit tests following "Test-Driven Documentation" principle. + */ + 'enabled' => false, + ], + /* * How is your API authenticated? This information will be used in the displayed docs, generated examples and response calls. */ diff --git a/src/GroupedEndpoints/GroupedEndpointsFactory.php b/src/GroupedEndpoints/GroupedEndpointsFactory.php index 68052e92..681b1f46 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFactory.php +++ b/src/GroupedEndpoints/GroupedEndpointsFactory.php @@ -10,6 +10,10 @@ class GroupedEndpointsFactory { public static function make(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher): GroupedEndpointsContract { + if ($command->getDocConfig()->get('from_tests.enabled')) { + return new GroupedEndpointsFromTests($command); + } + if ($command->isForcing()) { return new GroupedEndpointsFromApp($command, $routeMatcher, false); } From 06eaa63a67ed759287cb87dbb36376680300da33 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sun, 4 Jul 2021 14:38:52 +0800 Subject: [PATCH 07/11] Fix, return GroupedEndpointsFromCamelDir if no-extraction --- src/GroupedEndpoints/GroupedEndpointsFactory.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GroupedEndpoints/GroupedEndpointsFactory.php b/src/GroupedEndpoints/GroupedEndpointsFactory.php index 681b1f46..99a1d82c 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFactory.php +++ b/src/GroupedEndpoints/GroupedEndpointsFactory.php @@ -10,6 +10,10 @@ class GroupedEndpointsFactory { public static function make(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher): GroupedEndpointsContract { + if ($command->option('no-extraction')) { + return new GroupedEndpointsFromCamelDir; + } + if ($command->getDocConfig()->get('from_tests.enabled')) { return new GroupedEndpointsFromTests($command); } @@ -21,7 +25,5 @@ public static function make(GenerateDocumentation $command, RouteMatcherInterfac if ($command->shouldExtract()) { return new GroupedEndpointsFromApp($command, $routeMatcher, true); } - - return new GroupedEndpointsFromCamelDir; } } From 544d7baea147c89c4d96e624bfbe403d60c6e67a Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sun, 4 Jul 2021 14:43:52 +0800 Subject: [PATCH 08/11] Simplify returning of GroupedEndpointsFromApp --- src/GroupedEndpoints/GroupedEndpointsFactory.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/GroupedEndpoints/GroupedEndpointsFactory.php b/src/GroupedEndpoints/GroupedEndpointsFactory.php index 99a1d82c..33f0c995 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFactory.php +++ b/src/GroupedEndpoints/GroupedEndpointsFactory.php @@ -18,12 +18,6 @@ public static function make(GenerateDocumentation $command, RouteMatcherInterfac return new GroupedEndpointsFromTests($command); } - if ($command->isForcing()) { - return new GroupedEndpointsFromApp($command, $routeMatcher, false); - } - - if ($command->shouldExtract()) { - return new GroupedEndpointsFromApp($command, $routeMatcher, true); - } + return new GroupedEndpointsFromApp($command, $routeMatcher, !$command->isForcing()); } } From 2a8a3d969697596a2c77b2f5bbb5c229037f5837 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sun, 4 Jul 2021 20:45:18 +0800 Subject: [PATCH 09/11] Update, add matchFromTestsOnly in RouteMatcher --- .../GroupedEndpointsFromTests.php | 7 +++--- src/Matching/RouteMatcher.php | 25 ++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/GroupedEndpoints/GroupedEndpointsFromTests.php b/src/GroupedEndpoints/GroupedEndpointsFromTests.php index 510183cd..04e9699a 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromTests.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromTests.php @@ -18,16 +18,17 @@ public function hasEncounteredErrors(): bool protected function extractEndpointsInfoAndWriteToDisk(): array { - $endpoints = $this->extractEndpointsInfoFromTests(); + $routes = $this->routeMatcher->matchFromTestsOnly()->getRoutes($this->docConfig->get('routes'), $this->docConfig->get('router')); + $endpoints = $this->extractEndpointsInfoFromTests($routes); $groupedEndpoints = Camel::groupEndpoints($endpoints, $this->endpointGroupIndexes); $this->writeEndpointsToDisk($groupedEndpoints); $groupedEndpoints = Camel::prepareGroupedEndpointsForOutput($groupedEndpoints); return $groupedEndpoints; } - private function extractEndpointsInfoFromTests(): array + private function extractEndpointsInfoFromTests(array $routes): array { - // TODO: Run the phpunit tests to extract and return the endpoints. + // TODO: code return []; } } diff --git a/src/Matching/RouteMatcher.php b/src/Matching/RouteMatcher.php index 24aadb3e..16ac78e1 100644 --- a/src/Matching/RouteMatcher.php +++ b/src/Matching/RouteMatcher.php @@ -9,6 +9,15 @@ class RouteMatcher implements RouteMatcherInterface { + private bool $matchFromTestsOnly = false; + + public function matchFromTestsOnly(bool $bool = true): self + { + $this->matchFromTestsOnly = $bool; + + return $this; + } + public function getRoutes(array $routeRules = [], string $router = 'laravel'): array { $usingDingoRouter = strtolower($router) == 'dingo'; @@ -34,7 +43,10 @@ private function getRoutesToBeDocumented(array $routeRules, bool $usingDingoRout continue; } - if ($this->shouldIncludeRoute($route, $routeRule, $includes, $usingDingoRouter)) { + if ( + $this->shouldIncludeRoute($route, $routeRule, $includes, $usingDingoRouter) + && $this->isMatchedFromTests($route) + ) { $matchedRoutes[] = new MatchedRoute($route, $routeRule['apply'] ?? []); } } @@ -93,4 +105,15 @@ private function shouldExcludeRoute(Route $route, array $routeRule): bool return Str::is($excludes, $route->getName()) || Str::is($excludes, $route->uri()); } + + public function isMatchedFromTests(Route $route): bool + { + if ($this->matchFromTestsOnly == false) { + return true; + } + + // TODO: Run phpunit tests first to list all the routes that are included + // and check if route is included from tests + return true; + } } From 6db7da860863d09b4fbf71f63e711450bf9108ad Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sun, 4 Jul 2021 20:51:40 +0800 Subject: [PATCH 10/11] Fix --- src/GroupedEndpoints/GroupedEndpointsAbstract.php | 5 ++++- src/GroupedEndpoints/GroupedEndpointsFactory.php | 2 +- src/GroupedEndpoints/GroupedEndpointsFromApp.php | 4 +--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/GroupedEndpoints/GroupedEndpointsAbstract.php b/src/GroupedEndpoints/GroupedEndpointsAbstract.php index 4649efed..97893d01 100644 --- a/src/GroupedEndpoints/GroupedEndpointsAbstract.php +++ b/src/GroupedEndpoints/GroupedEndpointsAbstract.php @@ -6,6 +6,7 @@ use Knuckles\Camel\Camel; use Knuckles\Scribe\Commands\GenerateDocumentation; use Knuckles\Scribe\Extracting\ApiDetails; +use Knuckles\Scribe\Matching\RouteMatcherInterface; use Knuckles\Scribe\Tools\DocumentationConfig; use Knuckles\Scribe\Tools\Utils; use Symfony\Component\Yaml\Yaml; @@ -13,14 +14,16 @@ abstract class GroupedEndpointsAbstract { protected GenerateDocumentation $command; + protected RouteMatcherInterface $routeMatcher; protected DocumentationConfig $docConfig; public static string $camelDir; public static string $cacheDir; - public function __construct(GenerateDocumentation $command) + public function __construct(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher) { $this->command = $command; + $this->routeMatcher = $routeMatcher; $this->docConfig = $command->getDocConfig(); static::$camelDir = GenerateDocumentation::$camelDir; diff --git a/src/GroupedEndpoints/GroupedEndpointsFactory.php b/src/GroupedEndpoints/GroupedEndpointsFactory.php index 33f0c995..f7af8761 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFactory.php +++ b/src/GroupedEndpoints/GroupedEndpointsFactory.php @@ -15,7 +15,7 @@ public static function make(GenerateDocumentation $command, RouteMatcherInterfac } if ($command->getDocConfig()->get('from_tests.enabled')) { - return new GroupedEndpointsFromTests($command); + return new GroupedEndpointsFromTests($command, $routeMatcher); } return new GroupedEndpointsFromApp($command, $routeMatcher, !$command->isForcing()); diff --git a/src/GroupedEndpoints/GroupedEndpointsFromApp.php b/src/GroupedEndpoints/GroupedEndpointsFromApp.php index ac31b679..bcfacb76 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromApp.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromApp.php @@ -23,16 +23,14 @@ class GroupedEndpointsFromApp extends GroupedEndpointsAbstract implements GroupedEndpointsContract { - private $routeMatcher; private bool $preserveUserChanges; private bool $encounteredErrors = false; private array $endpointGroupIndexes = []; public function __construct(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher, bool $preserveUserChanges) { - parent::__construct($command); + parent::__construct($command, $routeMatcher); - $this->routeMatcher = $routeMatcher; $this->preserveUserChanges = $preserveUserChanges; } From ddb3a7a5f550fcd2a327f644777d978adbff26ff Mon Sep 17 00:00:00 2001 From: ajcastro Date: Sun, 4 Jul 2021 20:56:45 +0800 Subject: [PATCH 11/11] Fix --- src/Matching/RouteMatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Matching/RouteMatcher.php b/src/Matching/RouteMatcher.php index 16ac78e1..d31d4449 100644 --- a/src/Matching/RouteMatcher.php +++ b/src/Matching/RouteMatcher.php @@ -106,7 +106,7 @@ private function shouldExcludeRoute(Route $route, array $routeRule): bool || Str::is($excludes, $route->uri()); } - public function isMatchedFromTests(Route $route): bool + private function isMatchedFromTests(Route $route): bool { if ($this->matchFromTestsOnly == false) { return true;