소스 검색

Fix Dingo detection

shalvah 4 년 전
부모
커밋
4a0c8ff0ad
2개의 변경된 파일23개의 추가작업 그리고 20개의 파일을 삭제
  1. 1 20
      src/Commands/GenerateDocumentation.php
  2. 22 0
      src/Tools/DocumentationConfig.php

+ 1 - 20
src/Commands/GenerateDocumentation.php

@@ -293,7 +293,7 @@ class GenerateDocumentation extends Command
             $cachedEndpoints = Camel::loadEndpointsToFlatPrimitivesArray(static::$cacheDir);
         }
 
-        $routes = $routeMatcher->getRoutes($this->docConfig->get('routes'), $this->getRouter());
+        $routes = $routeMatcher->getRoutes($this->docConfig->get('routes'), $this->docConfig->get('router'));
         $endpoints = $this->extractEndpointsInfoFromLaravelApp($routes, $cachedEndpoints, $latestEndpointsData);
         $groupedEndpoints = Camel::groupEndpoints($endpoints);
         $this->writeEndpointsToDisk($groupedEndpoints);
@@ -315,23 +315,4 @@ class GenerateDocumentation extends Command
         $apiDetails = new ApiDetails($this->docConfig, !$this->option('force'));
         $apiDetails->writeMarkdownFiles();
     }
-
-    protected function getRouter(): string
-    {
-        if ($router = $this->docConfig->get('router', null)) {
-            if (!in_array($router, ['dingo', 'laravel'])) {
-                throw new \InvalidArgumentException("Unknown `router` value: $router");
-            }
-            return $router;
-        }
-
-        try {
-            $dingoVersion = \PackageVersions\Versions::getVersion('dingo/api');
-        } catch (\OutOfBoundsException $e) {
-            return 'laravel';
-        }
-
-        c::info('Detected Dingo API router');
-        return 'dingo';
-    }
 }

+ 22 - 0
src/Tools/DocumentationConfig.php

@@ -2,12 +2,15 @@
 
 namespace Knuckles\Scribe\Tools;
 
+use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
+
 class DocumentationConfig
 {
     private $data;
 
     public function __construct(array $config = [])
     {
+        $config['router'] = $this->getRouter($config);
         $this->data = $config;
     }
 
@@ -15,4 +18,23 @@ class DocumentationConfig
     {
         return data_get($this->data, $key, $default);
     }
+
+    private function getRouter(array $config): string
+    {
+        if ($router = data_get($config, 'router', null)) {
+            if (!in_array($router, ['dingo', 'laravel'])) {
+                throw new \InvalidArgumentException("Unknown `router` config value: $router");
+            }
+            return $router;
+        }
+
+        try {
+            $dingoVersion = \PackageVersions\Versions::getVersion('dingo/api');
+        } catch (\OutOfBoundsException $e) {
+            return 'laravel';
+        }
+
+        c::info('Detected Dingo API router');
+        return 'dingo';
+    }
 }