|
11 | 11 | * Class AutoRoute
|
12 | 12 | *
|
13 | 13 | * @package Buki\AutoRoute
|
14 |
| - * @author İzni Burak Demirtaş <info@burakdemirtasorg> |
| 14 | + * @author İzni Burak Demirtaş <info@burakdemirtasorg> |
15 | 15 | */
|
16 | 16 | class AutoRoute
|
17 | 17 | {
|
@@ -64,7 +64,22 @@ public function __construct(Container $app)
|
64 | 64 | {
|
65 | 65 | $this->app = $app;
|
66 | 66 | $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 | + } |
68 | 83 | }
|
69 | 84 |
|
70 | 85 | /**
|
@@ -110,7 +125,9 @@ public function auto(string $prefix, string $controller, array $options = []): v
|
110 | 125 | function () use ($endpoints, $methodName, $method, $httpMethods, $routePatterns) {
|
111 | 126 | $endpoints = implode('/', $endpoints);
|
112 | 127 | $this->router->addRoute(
|
113 |
| - array_map(function($method) { return strtoupper($method); }, $httpMethods), |
| 128 | + array_map(function ($method) { |
| 129 | + return strtoupper($method); |
| 130 | + }, $httpMethods), |
114 | 131 | ($methodName !== $this->mainMethod ? $methodName : '') . "/{$endpoints}",
|
115 | 132 | [$method->class, $method->name]
|
116 | 133 | )->where($routePatterns)->name(".{$methodName}");
|
@@ -180,21 +197,4 @@ private function resolveControllerName(string $controller): array
|
180 | 197 | $controller,
|
181 | 198 | ];
|
182 | 199 | }
|
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 |
| - } |
199 | 200 | }
|
200 |
| - |
0 commit comments