From f6bd0aeb8c2c9eff01ac80f85c37d7bb837a78d6 Mon Sep 17 00:00:00 2001
From: Pooya
Date: Fri, 8 Oct 2021 11:54:42 +0330
Subject: [PATCH] bug-fix for lumen frame work: - add laravel default
public_path helper because it's not present in lumen usage
IDocGeneratorCommand line 74 - improve readme.md to define public path if
needed - add new routes for lumen because it's totaly diffrent - extends
service provider for lumen
---
.gitignore | 3 ++-
README.md | 3 ++-
composer.json | 3 +++
helpers/helpers.php | 13 +++++++++
resources/routes/lumen.php | 9 +++++++
src/idoc/IDocLumenServiceProvider.php | 38 +++++++++++++++++++++++++++
src/idoc/IDocServiceProvider.php | 6 ++---
7 files changed, 70 insertions(+), 5 deletions(-)
create mode 100644 helpers/helpers.php
create mode 100644 resources/routes/lumen.php
create mode 100644 src/idoc/IDocLumenServiceProvider.php
diff --git a/.gitignore b/.gitignore
index 86fdebf..fcb8e6e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
composer.lock
.php_cs.cache
/vendor/
+/.idea
/public
.couscous/
-.phpintel/
\ No newline at end of file
+.phpintel/
diff --git a/README.md b/README.md
index 8de09cd..1b7e79c 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,8 @@ This will create an `idoc.php` file in your `config` folder.
### Lumen
- Register the service provider in your `bootstrap/app.php`:
```php
-$app->register(\OVAC\IDoc\IDocServiceProvider::class);
+$app->bind('path.public', function ($app) { return $app->basePath('../your-public-path'); });
+$app->register(\OVAC\IDoc\IDocLumenServiceProvider::class);
```
- Copy the config file from `vendor/ovac/idoc/config/idoc.php` to your project as `config/idoc.php`. Then add to your `bootstrap/app.php`:
```php
diff --git a/composer.json b/composer.json
index 0395fae..1555e3a 100644
--- a/composer.json
+++ b/composer.json
@@ -31,6 +31,9 @@
"league/fractal": "^0.17.0"
},
"autoload": {
+ "files": [
+ "helpers/helpers.php"
+ ],
"psr-4": {
"OVAC\\IDoc\\": "src/idoc"
}
diff --git a/helpers/helpers.php b/helpers/helpers.php
new file mode 100644
index 0000000..4515ccf
--- /dev/null
+++ b/helpers/helpers.php
@@ -0,0 +1,13 @@
+make('path.public').($path ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : $path);
+ }
+}
\ No newline at end of file
diff --git a/resources/routes/lumen.php b/resources/routes/lumen.php
new file mode 100644
index 0000000..44bed72
--- /dev/null
+++ b/resources/routes/lumen.php
@@ -0,0 +1,9 @@
+get('info', [function () { return view('idoc::partials.info'); }, 'as' => 'info']);
+
+//This is the route for the root documentation view page.
+$router->get('', [function () { return view('idoc::documentation'); }, 'as' => 'root']);
diff --git a/src/idoc/IDocLumenServiceProvider.php b/src/idoc/IDocLumenServiceProvider.php
new file mode 100644
index 0000000..40ea698
--- /dev/null
+++ b/src/idoc/IDocLumenServiceProvider.php
@@ -0,0 +1,38 @@
+registerRoutes();
+ $this->registerPublishing();
+
+ $this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'idoc');
+ $this->loadViewsFrom(__DIR__ . '/../../resources/views/', 'idoc');
+
+ if ($this->app->runningInConsole()) {
+ $this->commands([
+ IDocGeneratorCommand::class,
+ ]);
+ }
+ }
+
+ protected function registerRoutes()
+ {
+ app()->router->group($this->routeConfiguration(), function ($router) {
+ require __DIR__ . '/../../resources/routes/lumen.php';
+ });
+ }
+
+ protected function routeConfiguration()
+ {
+ return [
+ 'domain' => config('idoc.domain'),
+ 'prefix' => config('idoc.path'),
+ 'middleware' => config('idoc.middleware', []),
+ 'as' => 'idoc',
+ ];
+ }
+}
diff --git a/src/idoc/IDocServiceProvider.php b/src/idoc/IDocServiceProvider.php
index e9c2e0c..10bc142 100644
--- a/src/idoc/IDocServiceProvider.php
+++ b/src/idoc/IDocServiceProvider.php
@@ -34,7 +34,7 @@ public function boot()
*
* @return array
*/
- private function registerRoutes()
+ protected function registerRoutes()
{
Route::group($this->routeConfiguration(), function () {
$this->loadRoutesFrom(__DIR__ . '/../../resources/routes/idoc.php', 'idoc');
@@ -46,7 +46,7 @@ private function registerRoutes()
*
* @return void
*/
- private function registerPublishing()
+ protected function registerPublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
@@ -68,7 +68,7 @@ private function registerPublishing()
*
* @return array
*/
- private function routeConfiguration()
+ protected function routeConfiguration()
{
return [
'domain' => config('idoc.domain', null),