Skip to content

Commit

Permalink
Merge pull request #23 from dniccum/bugfix/routing-memory-leak
Browse files Browse the repository at this point in the history
Bugfix/routing memory leak
  • Loading branch information
dniccum authored Feb 3, 2023
2 parents 6578673 + 3b19a56 commit 13174c2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is a tool for Laravel's Nova administrator panel that allows you to create

[![Screenshot](https://raw.githubusercontent.com/dniccum/nova-documentation/master/screenshots/screenshot-1.png)](https://raw.githubusercontent.com/dniccum/nova-documentation/master/screenshots/screenshot-1.png)



## Compatibility Note

Please note, this plugin now **only supports Laravel Nova v4**. If you are using Laravel Nova <= v3, please use version `^3.0`,
Expand Down Expand Up @@ -61,7 +63,7 @@ public function tools()

## Upgrading from version 2

If you are upgrading from version 2 to version 3 (Laravel 4 support), make sure your `composer.json` has the following version/reference to included the updated version:
If you are upgrading from version 2 to version 3 (Laravel Nova 4 support), make sure your `composer.json` has the following version/reference to included the updated version:

```
"dniccum/nova-documentation": "^3.0"
Expand Down Expand Up @@ -145,6 +147,10 @@ Other types of links that are supported:
* Mailto (`mailto:`) links
* External http and https links

### Routes and adding new pages

When a new document is added to the application architecture, and if your application leverages route caching, **be sure to clear/reset your route cache accordingly** (`php artisan route:clear`).

## Configuration

The configuration items listed below can be found in the `novadocumentation.php` configuration file.
Expand Down
25 changes: 24 additions & 1 deletion routes/inertia.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

use Dniccum\NovaDocumentation\Library\Contracts\DocumentationPage;
use Dniccum\NovaDocumentation\Library\MarkdownUtility;
use Dniccum\NovaDocumentation\Library\RouteUtility;
use Illuminate\Support\Facades\Route;
use Laravel\Nova\Http\Requests\NovaRequest;

Expand All @@ -15,4 +18,24 @@
*/

Route::get('/', [ \Dniccum\NovaDocumentation\Http\Controllers\NovaDocumentationController::class, 'home' ])
->name('nova.tools.documentation-home');
->name('nova.tools.documentation-home');

try {
$utility = new MarkdownUtility();
$pageRoutes = $utility->buildPageRoutes();

/**
* @var DocumentationPage[] $filteredRoutes
*/
$filteredRoutes = collect($pageRoutes)
->filter(fn(DocumentationPage $item) => !$item->isHome)
->toArray();

foreach ($filteredRoutes as $filteredRoute) {
\Illuminate\Support\Facades\Route::get("/$filteredRoute->route", function () use ($filteredRoute, $pageRoutes) {
return RouteUtility::buildDocumentRoute($filteredRoute->file, $pageRoutes);
});
}
} catch (\Dniccum\NovaDocumentation\Exceptions\DocumentationParsingException $exception) {
abort($exception->getCode() > 0 ? $exception->getCode() : 500, $exception->getMessage());
}
8 changes: 8 additions & 0 deletions src/Exceptions/DocumentationParsingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Dniccum\NovaDocumentation\Exceptions;

class DocumentationParsingException extends \Exception
{

}
3 changes: 2 additions & 1 deletion src/Library/MarkdownUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use cebe\markdown\Markdown;
use cebe\markdown\GithubMarkdown;
use cebe\markdown\MarkdownExtra;
use Dniccum\NovaDocumentation\Exceptions\DocumentationParsingException;
use Dniccum\NovaDocumentation\Library\Contracts\DocumentationPage;
use Dniccum\NovaDocumentation\Library\Contracts\PageContent;
use Spatie\YamlFrontMatter\YamlFrontMatter;
Expand Down Expand Up @@ -115,7 +116,7 @@ public function buildPageRoutes()
is_int(strpos($files[$i], config('novadocumentation.home')))
);
}
} catch (\Exception $e) {
} catch (DocumentationParsingException $e) {
abort(500, $e);
}

Expand Down
21 changes: 4 additions & 17 deletions src/ToolServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Dniccum\NovaDocumentation\Library\Contracts\DocumentationPage;
use Dniccum\NovaDocumentation\Library\MarkdownUtility;
use Dniccum\NovaDocumentation\Library\RouteUtility;
use Illuminate\Support\Facades\Route;
use Laravel\Nova\Nova;
use Laravel\Nova\Events\ServingNova;
use Illuminate\Support\ServiceProvider;
Expand Down Expand Up @@ -85,22 +85,9 @@ protected function routes()
return;
}

Nova::router(['nova', Authorize::class], $this->prefix)
->group(function() {
/**
* @var DocumentationPage[] $filteredRoutes
*/
$filteredRoutes = collect($this->pageRoutes)
->filter(fn(DocumentationPage $item) => !$item->isHome)
->toArray();
foreach ($filteredRoutes as $filteredRoute) {
$this->app['router']->get("/$filteredRoute->route", function() use ($filteredRoute) {
return RouteUtility::buildDocumentRoute($filteredRoute->file, $this->pageRoutes);
});
}

require(__DIR__.'/../routes/inertia.php');
});
Route::middleware(['nova', Authorize::class])
->prefix('nova-vendor/nova-documentation')
->group(__DIR__.'/../routes/inertia.php');
}

/**
Expand Down

0 comments on commit 13174c2

Please sign in to comment.