Skip to content

Commit 9666905

Browse files
committed
Bug fixed.
1 parent 45bff94 commit 9666905

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/AutoRoute.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Class AutoRoute
1212
*
1313
* @package Buki\AutoRoute
14-
* @author İzni Burak Demirtaş <info@burakdemirtasorg>
14+
* @author İzni Burak Demirtaş <info@burakdemirtasorg>
1515
*/
1616
class AutoRoute
1717
{
@@ -64,7 +64,22 @@ public function __construct(Container $app)
6464
{
6565
$this->app = $app;
6666
$this->router = $app->get('router');
67-
$this->init($this->app['config']->get('auto-route'));
67+
}
68+
69+
/**
70+
* Initialize for the AutoRoute
71+
*
72+
* @param array $config
73+
*/
74+
public function setConfigurations(array $config): void
75+
{
76+
$this->mainMethod = $config['main_method'] ?? 'index';
77+
$this->namespace = $config['namespace'] ?? 'App\\Http\\Controllers';
78+
$this->defaultPatterns = array_merge($this->defaultPatterns, $config['patterns'] ?? []);
79+
$this->defaultHttpMethods = $config['http_methods'] ?? $this->availableMethods;
80+
if (empty($this->defaultHttpMethods) || $this->defaultHttpMethods === '*') {
81+
$this->defaultHttpMethods = $this->availableMethods;
82+
}
6883
}
6984

7085
/**
@@ -110,7 +125,9 @@ public function auto(string $prefix, string $controller, array $options = []): v
110125
function () use ($endpoints, $methodName, $method, $httpMethods, $routePatterns) {
111126
$endpoints = implode('/', $endpoints);
112127
$this->router->addRoute(
113-
array_map(function($method) { return strtoupper($method); }, $httpMethods),
128+
array_map(function ($method) {
129+
return strtoupper($method);
130+
}, $httpMethods),
114131
($methodName !== $this->mainMethod ? $methodName : '') . "/{$endpoints}",
115132
[$method->class, $method->name]
116133
)->where($routePatterns)->name(".{$methodName}");
@@ -180,21 +197,4 @@ private function resolveControllerName(string $controller): array
180197
$controller,
181198
];
182199
}
183-
184-
/**
185-
* Initialize for the AutoRoute
186-
*
187-
* @param array $config
188-
*/
189-
private function init(array $config): void
190-
{
191-
$this->mainMethod = $config['main_method'] ?? 'index';
192-
$this->namespace = $config['namespace'] ?? 'App\\Http\\Controllers';
193-
$this->defaultPatterns = array_merge($this->defaultPatterns, $config['patterns'] ?? []);
194-
$this->defaultHttpMethods = $config['http_methods'] ?? $this->availableMethods;
195-
if (empty($this->defaultHttpMethods) || $this->defaultHttpMethods === '*') {
196-
$this->defaultHttpMethods = $this->availableMethods;
197-
}
198-
}
199200
}
200-

src/AutoRouteServiceProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Class AutoRouteServiceProvider
1010
*
1111
* @package Buki\AutoRoute
12-
* @author İzni Burak Demirtaş <info@burakdemirtasorg>
12+
* @author İzni Burak Demirtaş <info@burakdemirtasorg>
1313
*/
1414
class AutoRouteServiceProvider extends ServiceProvider
1515
{
@@ -21,7 +21,7 @@ class AutoRouteServiceProvider extends ServiceProvider
2121
public function boot()
2222
{
2323
$this->publishes([
24-
$this->configPath() => config_path('auto-route.php')
24+
$this->configPath() => config_path('auto-route.php'),
2525
], 'auto-route');
2626
}
2727

@@ -32,9 +32,11 @@ public function boot()
3232
*/
3333
public function register()
3434
{
35-
$this->mergeConfigFrom($this->configPath(), 'auto-router');
35+
$this->mergeConfigFrom($this->configPath(), 'auto-route');
3636
$this->app->singleton(AutoRoute::class, function ($app) {
37-
return new AutoRoute($app);
37+
$autoRouter = new AutoRoute($app);
38+
$autoRouter->setConfigurations($app['config']->get('auto-route'));
39+
return $autoRouter;
3840
});
3941

4042
/** @var Router $router */

0 commit comments

Comments
 (0)