diff --git a/src/Extracting/ApiDetails.php b/src/Extracting/ApiDetails.php index 254baeb1..87e70f1c 100644 --- a/src/Extracting/ApiDetails.php +++ b/src/Extracting/ApiDetails.php @@ -25,18 +25,18 @@ class ApiDetails private array $lastKnownFileContentHashes = []; /** - * @param PathConfig $docsName + * @param PathConfig $pathConfig * @param DocumentationConfig|null $config * @param bool $preserveUserChanges */ public function __construct( - PathConfig $docsName, + PathConfig $pathConfig, DocumentationConfig $config = null, - bool $preserveUserChanges = true + bool $preserveUserChanges = true ) { - $this->markdownOutputPath = $docsName; //.scribe by default + $this->markdownOutputPath = $pathConfig; //.scribe by default // If no config is injected, pull from global. Makes testing easier. - $this->config = $config ?: new DocumentationConfig(config($docsName)); + $this->config = $config ?: new DocumentationConfig(config($pathConfig)); $this->baseUrl = $this->config->get('base_url') ?? config('app.url'); $this->preserveUserChanges = $preserveUserChanges; diff --git a/src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php b/src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php index 6064a5f9..ab154827 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php @@ -7,22 +7,22 @@ class GroupedEndpointsFromCamelDir implements GroupedEndpointsContract { - protected PathConfig $docsName; + protected PathConfig $pathConfig; - public function __construct(PathConfig $docsName) + public function __construct(PathConfig $pathConfig) { - $this->docsName = $docsName; + $this->pathConfig = $pathConfig; } public function get(): array { - if (!is_dir(Camel::camelDir($this->docsName))) { + if (!is_dir(Camel::camelDir($this->pathConfig))) { throw new \InvalidArgumentException( - "Can't use --no-extraction because there are no endpoints in the " . Camel::camelDir($this->docsName) . " directory." + "Can't use --no-extraction because there are no endpoints in the " . Camel::camelDir($this->pathConfig) . " directory." ); } - return Camel::loadEndpointsIntoGroups(Camel::camelDir($this->docsName)); + return Camel::loadEndpointsIntoGroups(Camel::camelDir($this->pathConfig)); } public function hasEncounteredErrors(): bool diff --git a/src/Writing/Writer.php b/src/Writing/Writer.php index f3abe421..39f4cfb6 100644 --- a/src/Writing/Writer.php +++ b/src/Writing/Writer.php @@ -16,7 +16,7 @@ class Writer * The "name" of this docs instance. By default, it is "scribe". * Used for multi-docs. */ - public PathConfig $docsName; + public PathConfig $pathConfig; private DocumentationConfig $config; @@ -41,21 +41,21 @@ class Writer private string $laravelAssetsPath; - public function __construct(DocumentationConfig $config = null, PathConfig $docsName) + public function __construct(DocumentationConfig $config = null, PathConfig $pathConfig) { - $this->docsName = $docsName; + $this->pathConfig = $pathConfig; // If no config is injected, pull from global, for easier testing. - $this->config = $config ?: new DocumentationConfig(config($docsName->getScribeConfigFile())); + $this->config = $config ?: new DocumentationConfig(config($pathConfig->getScribeConfigFile())); $this->isStatic = $this->config->get('type') === 'static'; - $this->markdownOutputPath = $docsName; //.scribe by default + $this->markdownOutputPath = $pathConfig; //.scribe by default $this->laravelTypeOutputPath = $this->getLaravelTypeOutputPath(); $this->staticTypeOutputPath = rtrim($this->config->get('static.output_path', 'public/docs'), '/'); $this->laravelAssetsPath = $this->config->get('laravel.assets_directory') ? '/' . $this->config->get('laravel.assets_directory') - : "/vendor/" . $this->docsName->getScribeConfigFile(); + : "/vendor/" . $this->pathConfig->getScribeConfigFile(); } /** @@ -87,8 +87,8 @@ protected function writePostmanCollection(array $groups): void $collectionPath = "{$this->staticTypeOutputPath}/collection.json"; file_put_contents($collectionPath, $collection); } else { - Storage::disk('local')->put($this->docsName->getScribeConfigFile() . "/collection.json", $collection); - $collectionPath = Storage::disk('local')->path($this->docsName->getScribeConfigFile() . "/collection.json"); + Storage::disk('local')->put($this->pathConfig->getScribeConfigFile() . "/collection.json", $collection); + $collectionPath = Storage::disk('local')->path($this->pathConfig->getScribeConfigFile() . "/collection.json"); } c::success("Wrote Postman collection to: {$this->makePathFriendly($collectionPath)}"); @@ -106,8 +106,8 @@ protected function writeOpenAPISpec(array $parsedRoutes): void $specPath = "{$this->staticTypeOutputPath}/openapi.yaml"; file_put_contents($specPath, $spec); } else { - Storage::disk('local')->put($this->docsName->getScribeConfigFile() . "/openapi.yaml", $spec); - $specPath = Storage::disk('local')->path($this->docsName->getScribeConfigFile() . "/openapi.yaml"); + Storage::disk('local')->put($this->pathConfig->getScribeConfigFile() . "/openapi.yaml", $spec); + $specPath = Storage::disk('local')->path($this->pathConfig->getScribeConfigFile() . "/openapi.yaml"); } c::success("Wrote OpenAPI specification to: {$this->makePathFriendly($specPath)}"); @@ -181,8 +181,8 @@ protected function performFinalTasksForLaravelType(): void // Rewrite asset links to go through Laravel $contents = preg_replace('#href="\.\./docs/css/(.+?)"#', 'href="{{ asset("' . $this->laravelAssetsPath . '/css/$1") }}"', $contents); $contents = preg_replace('#src="\.\./docs/(js|images)/(.+?)"#', 'src="{{ asset("' . $this->laravelAssetsPath . '/$1/$2") }}"', $contents); - $contents = str_replace('href="../docs/collection.json"', 'href="{{ route("' . $this->docsName->getScribeConfigFile() . '.postman") }}"', $contents); - $contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("' . $this->docsName->getScribeConfigFile() . '.openapi") }}"', $contents); + $contents = str_replace('href="../docs/collection.json"', 'href="{{ route("' . $this->pathConfig->getScribeConfigFile() . '.postman") }}"', $contents); + $contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("' . $this->pathConfig->getScribeConfigFile() . '.openapi") }}"', $contents); file_put_contents("$this->laravelTypeOutputPath/index.blade.php", $contents); } @@ -229,7 +229,7 @@ protected function getLaravelTypeOutputPath(): ?string { if ($this->isStatic) return null; - return config('view.paths.0', function_exists('base_path') ? base_path("resources/views") : "resources/views") . "/" . $this->docsName->getScribeConfigFile(); + return config('view.paths.0', function_exists('base_path') ? base_path("resources/views") : "resources/views") . "/" . $this->pathConfig->getScribeConfigFile(); } /**