Skip to content

Commit

Permalink
fix: parentClass and route name issues
Browse files Browse the repository at this point in the history
  • Loading branch information
izniburak committed Aug 8, 2024
1 parent 7904f15 commit d8f1051
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Supported Laravel Versions:
- v1.x: Laravel 6 and later ([see the source](https://github.com/izniburak/laravel-auto-routes/tree/1.x))

Run the following command directly in your Project path:
```
$ composer require izniburak/laravel-auto-routes
```sh
composer require izniburak/laravel-auto-routes
```
**OR** open your `composer.json` file and add the package like this:
```json
Expand All @@ -39,16 +39,16 @@ $ composer require izniburak/laravel-auto-routes
}
```
after run the install command.
```
$ composer install
```sh
composer install
```

The service provider of the Package will be **automatically discovered** by Laravel.

After that, you should publish the config file via following command:

```
$ php artisan vendor:publish --provider="Buki\AutoRoute\AutoRouteServiceProvider"
```sh
php artisan vendor:publish --provider="Buki\AutoRoute\AutoRouteServiceProvider"
```
Greate! You can start to use **Auto Route** Package.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"php": "^8.1"
},
"require-dev": {
"illuminate/routing": "^10.0",
"illuminate/routing": "^10.0|^11.0",
"phpunit/phpunit": "^10.1"
},
"autoload": {
Expand Down
17 changes: 7 additions & 10 deletions src/AutoRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,20 @@ public function auto(string $prefix, string $controller, array $options = []): v
$except = $options['except'] ?? [];
$patterns = $options['patterns'] ?? [];

$routeName = trim($options['as'] ?? ($options['name'] ?? trim($prefix, '/')), '.') . '.';
if ($routeName === '.') {
$routeName = '';
}

$this->router->group(
array_merge($options, [
'prefix' => $prefix,
'as' => isset($options['as'])
? "{$options['as']}."
: (isset($options['name'])
? "{$options['name']}."
: trim($prefix, '/') . '.'
),
]),
array_merge($options, ['prefix' => $prefix, 'as' => $routeName]),
function () use ($controller, $only, $except, $patterns) {
[$class, $className] = $this->resolveControllerName($controller);
$classRef = new ReflectionClass($class);
foreach ($classRef->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
// Check the method should be added into Routes or not.
if (in_array($method->class, [BaseController::class, "{$this->namespace}\\Controller"])
|| $method->getDeclaringClass()->getParentClass()->getName() === BaseController::class
|| ($method->getDeclaringClass()->getParentClass() && $method->getDeclaringClass()->getParentClass()->getName() === BaseController::class)
|| !$method->isPublic()
|| str_starts_with($method->name, '__')) {
continue;
Expand Down

0 comments on commit d8f1051

Please sign in to comment.