Skip to content

Commit 5738df0

Browse files
authored
Merge pull request #76 from lion-packages/support
lion/route has been integrated with rules integration
2 parents 165c64d + fb75f68 commit 5738df0

28 files changed

+170
-616
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"Database\\Seed\\": "database/Seed/"
1919
},
2020
"files": [
21-
"routes/rules.php",
2221
"routes/middleware.php",
2322
"src/LionBundle/Helpers/Bundle/constants.php",
24-
"src/LionBundle/Helpers/Bundle/helpers.php"
23+
"src/LionBundle/Helpers/Bundle/helpers.php",
24+
"tests/Providers/NameRuleProvider.php"
2525
]
2626
},
2727
"autoload-dev": {

composer.lock

Lines changed: 63 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
</exclude>
4141
</source>
4242

43-
<extensions>
43+
<!-- <extensions>
4444
<bootstrap class="RobinIngelbrecht\PHPUnitPrettyPrint\PhpUnitExtension">
4545
<parameter name="enableByDefault" value="true" />
4646
<parameter name="displayProfiling" value="true" />
4747
<parameter name="useCompactMode" value="true" />
4848
</bootstrap>
49-
</extensions>
49+
</extensions> -->
5050

5151
<!-- <coverage>
5252
<report>

public/index.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@
66

77
require_once(__DIR__ . '/../vendor/autoload.php');
88

9-
use Lion\Bundle\Kernel\HttpKernel;
10-
use Lion\Dependency\Injection\Container;
11-
use Lion\Exceptions\Serialize;
12-
13-
(new Serialize())->exceptionHandler();
14-
15-
include_once(__DIR__ . '/../routes/rules.php');
16-
17-
((new Container())->injectDependencies(new HttpKernel()))->validateRules();
9+
(new Lion\Exceptions\Serialize())->exceptionHandler();
1810

1911
include_once(__DIR__ . '/../routes/middleware.php');
2012
include_once(__DIR__ . '/../routes/web.php');

routes/rules.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

routes/web.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Lion\Mailer\Mailer;
2626
use Lion\Request\Http;
2727
use Lion\Request\Status;
28+
use Tests\Providers\ExampleProvider;
2829

2930
/**
3031
* -----------------------------------------------------------------------------
@@ -104,6 +105,7 @@
104105
**/
105106

106107
Route::init();
108+
107109
Route::addMiddleware(Routes::getMiddleware());
108110
// -----------------------------------------------------------------------------
109111
Route::get('/', function () {
@@ -128,7 +130,7 @@
128130
});
129131

130132
Route::prefix('api', function () {
131-
Route::post('test', fn () => ['token' => jwt()]);
133+
Route::post('test', [ExampleProvider::class, 'getResult']);
132134
Route::get('test', fn () => success('test-response'));
133135
Route::put('test/{id:i}', fn (string $id) => success('test-response: ' . $id));
134136

src/LionBundle/Commands/Lion/New/RulesCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
111111
112112
namespace {$namespace};
113113
114-
use Lion\Bundle\Helpers\Rules;
115-
use Lion\Bundle\Interface\RulesInterface;
114+
use Lion\Route\Helpers\Rules;
115+
use Lion\Route\Interface\RulesInterface;
116116
use Valitron\Validator;
117117
118118
/**

src/LionBundle/Commands/Lion/Route/PostmanCollectionCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
144144
{
145145
$this->fetchRoutes();
146146

147-
$this->postmanCollection->addRoutes($this->routes, Routes::getRules());
147+
$this->postmanCollection->addRoutes($this->routes);
148148

149149
$path = storage_path('postman/', false);
150150

src/LionBundle/Commands/Lion/Route/RouteListCommand.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
138138
$rows[] = [
139139
$this->warningOutput($keyMethods),
140140
$routeUrl,
141-
$this->transformNamespace($method['handler']['controller']['name']),
141+
$method['handler']['controller']['name'],
142142
$this->warningOutput($method['handler']['controller']['function'])
143143
];
144144
}
@@ -150,7 +150,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
150150
$rows[] = [
151151
$this->infoOutput('MIDDLEWARE:'),
152152
$this->infoOutput($filter),
153-
$this->transformNamespace($middleware->getClass()),
153+
$middleware->getClass(),
154154
$this->warningOutput($middleware->getMethodClass())
155155
];
156156
}
@@ -171,7 +171,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
171171
? $this->successOutput('(NAMELESS)')
172172
: $this->successOutput($objectClassRule->field . " ({$requiredParam})")
173173
),
174-
$this->transformNamespace($objectClassRule::class),
174+
$objectClassRule::class,
175175
$this->warningOutput('passes')
176176
];
177177
}
@@ -202,30 +202,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
202202
return Command::SUCCESS;
203203
}
204204

205-
/**
206-
* Add colors in namespace separation
207-
*
208-
* @param string $namespace [Class namespace]
209-
*
210-
* @return string
211-
*/
212-
private function transformNamespace(string $namespace): string
213-
{
214-
$classNew = '';
215-
216-
$split = explode("\\", $namespace);
217-
218-
foreach ($split as $key => $value) {
219-
if ($key < (count($split) - 1)) {
220-
$classNew .= "{$this->purpleOutput($value)}\\";
221-
} else {
222-
$classNew .= $value;
223-
}
224-
}
225-
226-
return $classNew;
227-
}
228-
229205
/**
230206
* Gets the parameters (Web Routes/Rules/Middleware) of the defined web
231207
* routes
@@ -245,8 +221,6 @@ private function fetchRoutes(): void
245221

246222
array_pop($this->routes);
247223

248-
$this->rules = Routes::getRules();
249-
250224
$this->configMiddleware = Routes::getMiddleware();
251225
}
252226
}

src/LionBundle/Exceptions/RulesException.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/LionBundle/Helpers/Commands/PostmanCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private function addRequest(string $name, string $route, string $method, array $
391391
*
392392
* @return void
393393
*/
394-
public function addRoutes(array $routes, array $rules): void
394+
public function addRoutes(array $routes, array $rules = []): void
395395
{
396396
foreach ($routes as $routeUrl => $allRoutes) {
397397
foreach ($allRoutes as $routeMethod => $routeInfo) {

src/LionBundle/Helpers/Http/Routes.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,19 @@
77
/**
88
* Initializes the defined web rules and filters
99
*
10-
* @property array $rules [List of defined web rules]
1110
* @property array $middleware [List of defined web filters]
1211
*
1312
* @package Lion\Bundle\Helpers\Http
1413
*/
1514
class Routes
1615
{
17-
/**
18-
* [List of defined web rules]
19-
*
20-
* @var array $rules
21-
*/
22-
private static array $rules;
23-
2416
/**
2517
* [List of defined web filters]
2618
*
2719
* @var array $middleware
2820
*/
2921
private static array $middleware;
3022

31-
/**
32-
* Returns the list of defined web rules
33-
*
34-
* @return array
35-
*/
36-
public static function getRules(): array
37-
{
38-
return self::$rules;
39-
}
40-
41-
/**
42-
* Change the list of defined web rules
43-
*
44-
* @param array $rules [List of defined web rules]
45-
*
46-
* @return Routes
47-
*/
48-
public static function setRules(array $rules): Routes
49-
{
50-
self::$rules = $rules;
51-
52-
return new static;
53-
}
54-
5523
/**
5624
* Returns the list of defined web filters
5725
*

src/LionBundle/Helpers/Rules.php

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/LionBundle/Interface/RulesInterface.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)