feat: Store documentation file on a configurable directory#152
feat: Store documentation file on a configurable directory#152hans-thomas wants to merge 16 commits intoRonasIT:masterfrom
Conversation
|
@hans-thomas I've updated task description, please add required changes accordingly the new task description (please feel free to open few PRs if you can divide task for small subtasks without breaking the package work) |
|
@hans-thomas please do not use autoclosing issues as we need to test task before closing |
The `production_path` key renamed to `base_file_name` for both local and storage drivers;
|
Hi @DenTray, would you please review this PR? |
src/Drivers/LocalDriver.php
Outdated
| $this->config = config('auto-doc.drivers.local'); | ||
|
|
||
| if (empty($this->prodFilePath)) { | ||
| $directory = str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR) |
There was a problem hiding this comment.
| $directory = str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR) | |
| $directory = (str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR)) |
There was a problem hiding this comment.
I made this change but I can't understand the difference.
src/Drivers/StorageDriver.php
Outdated
| $this->disk = Storage::disk($this->config['disk']); | ||
|
|
||
| if (empty($this->prodFilePath)) { | ||
| $directory = str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR) |
There was a problem hiding this comment.
as you already did the same in the local driver, let's move this logic to the BaseDriver class
| $directory = str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR) | |
| $directory = (str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR)) |
Force set documentation directory as empty for AutoDocControllerTest;
ee90fc7 to
cef046b
Compare
src/Drivers/StorageDriver.php
Outdated
| $this->disk = Storage::disk($this->config['disk']); | ||
|
|
||
| if (empty($this->prodFilePath)) { | ||
| $directory = (str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR)) |
There was a problem hiding this comment.
not sure this logic required for the Storage driver as it works correctly for all next cases:
- Storage::put('file.txt', 'content')
- Storage::put('/path/file.txt', 'content')
- Storage::put('path/file.txt', 'content')
- Storage::put('/file.txt', 'content')
- Storage::put('//file.txt', 'content')
There was a problem hiding this comment.
That logic was preventing this case:
Storage::put('documentations//documentation.json', 'content')However, it's handling this case correctly, too.
| $driver = new LocalDriver(); | ||
| $driver->saveTmpData(self::$tmpData); | ||
|
|
||
| $this->assertFileExists(self::$tmpDocumentationFilePath); |
There was a problem hiding this comment.
| $this->assertFileExists(self::$tmpDocumentationFilePath); | |
| $this->assertFileExists(storage_path('documentations/documentation.json')); |
There was a problem hiding this comment.
These static properties are used several times in this class and I believe they are beneficial to keep tests simpler and improve the readability.
|
|
Hi @DenTray, please review this PR. If everything is okay, I will cover the new lines. |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces configurable directory support for documentation file storage, allowing users to specify where generated documentation files are saved. The changes refactor both Local and Storage drivers to support directory configuration while maintaining backward compatibility.
- Adds a new
directoryconfiguration option with default valuedocumentations - Renames
production_pathtobase_file_namewith automatic.jsonextension handling - Implements directory creation logic for the Local driver when directories don't exist
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| config/auto-doc.php | Updates configuration structure with new directory and base_file_name options, increments config version |
| src/Drivers/LocalDriver.php | Implements directory handling logic and automatic directory creation |
| src/Drivers/StorageDriver.php | Refactors to use new configuration structure with directory support |
| tests/LocalDriverTest.php | Updates tests to use new configuration and adds directory creation test coverage |
| tests/StorageDriverTest.php | Updates tests for new configuration structure and adds directory separator handling test |
| tests/RemoteDriverTest.php | Updates temporary file path to use storage_path helper |
| tests/AutoDocControllerTest.php | Updates tests to use new configuration options |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| $this->disk = Storage::disk($this->config['disk']); | ||
|
|
||
| if (empty($this->prodFilePath)) { | ||
| $directory = $this->config['directory'] . DIRECTORY_SEPARATOR; |
There was a problem hiding this comment.
The directory separator is unconditionally added, which will create paths like 'documentations//' when the directory already ends with a separator. This should check if the directory already ends with a separator first, similar to the LocalDriver implementation.
| $directory = $this->config['directory'] . DIRECTORY_SEPARATOR; | |
| $directory = $this->config['directory']; | |
| if (!str_ends_with($directory, DIRECTORY_SEPARATOR)) { | |
| $directory .= DIRECTORY_SEPARATOR; | |
| } |
| public function saveData(): void | ||
| { | ||
| file_put_contents($this->prodFilePath, json_encode($this->getTmpData())); | ||
| $documentationDirectory = storage_path($this->config['directory']); |
There was a problem hiding this comment.
The directory path construction is inconsistent with the mainFilePath construction. When config['directory'] already ends with DIRECTORY_SEPARATOR, this will create the wrong directory path. Should use the same normalized $directory variable from lines 19-21.
| $documentationDirectory = 'test_directory'; | ||
| if (is_dir($documentationDirectory)) { |
There was a problem hiding this comment.
The test uses a hardcoded directory name that doesn't match the actual configuration being tested. This should use the same directory configuration as other tests for consistency and to properly test the actual functionality.
| $documentationDirectory = 'test_directory'; | |
| if (is_dir($documentationDirectory)) { | |
| $documentationDirectory = config('auto-doc.drivers.local.directory'); | |
| if (is_dir(storage_path($documentationDirectory))) { |
| { | ||
| $documentationDirectory = 'test_directory'; | ||
| if (is_dir($documentationDirectory)) { | ||
| rmdir(storage_path($documentationDirectory)); |
There was a problem hiding this comment.
Using rmdir() without checking if the directory is empty will fail if the directory contains files. Should use a recursive directory removal or ensure the directory is empty before attempting to remove it.



Hi, it adds the ability to store the generated documentation file in a configurable directory.
TODO list:
directorywith the default valuedocumentationsproduction_pathconfig for Local and Storage drivers should be renamed tobase_file_namewith the default valuedocumentation(without.jsonextension).jsonextension