Skip to content

Commit 17b568d

Browse files
First Publish
0 parents  commit 17b568d

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#-----------------------------------
2+
# Composer
3+
#-----------------------------------
4+
5+
vendor
6+
composer.lock
7+
8+
#-----------------------------------
9+
# PHPDoc
10+
#-----------------------------------
11+
12+
.phpdoc

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Laravel Route
2+
3+
Easy to define routes in Laravel
4+
5+
## Installation
6+
7+
You can install package via composer:
8+
9+
```
10+
composer require yukata-roommate/laravel-route
11+
```

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "yukata-roommate/laravel-route",
3+
"description": "Easy to define routes in Laravel",
4+
"version": "1.0.0",
5+
"keywords": [
6+
"yukata-roommate",
7+
"php",
8+
"laravel",
9+
"package",
10+
"route",
11+
"laravel-route"
12+
],
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Yukata Roommate"
17+
}
18+
],
19+
"autoload": {
20+
"psr-4": {
21+
"YukataRm\\Laravel\\Route\\": "src"
22+
}
23+
},
24+
"extra": {
25+
"laravel": {
26+
"providers": [
27+
"YukataRm\\Laravel\\Route\\ServiceProvider"
28+
]
29+
}
30+
},
31+
"require": {
32+
"php": ">=8.3.0",
33+
"laravel/framework": "^11.0 || ^12.0",
34+
"yukata-roommate/info": "^1.0.0"
35+
}
36+
}

src/Macros/RouterMacro.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace YukataRm\Laravel\Route\Macros;
4+
5+
use Illuminate\Routing\Router;
6+
7+
use YukataRm\Info\Proxies\PHPInfo;
8+
9+
/**
10+
* Router Macro
11+
*
12+
* @package YukataRm\Laravel\Route\Macros
13+
*
14+
* @method \Illuminate\Routing\RouteRegistrar group(array $attributes, \Closure $routes)
15+
* @method \Illuminate\Routing\RouteRegistrar controller(string $controller)
16+
* @method \Illuminate\Routing\Route get(string $uri, array|string|callable|null $action = null)
17+
* @method \Illuminate\Routing\Route post(string $uri, array|string|callable|null $action = null)
18+
* @see \Illuminate\Routing\Router
19+
*/
20+
class RouterMacro
21+
{
22+
/**
23+
* macro class
24+
*
25+
* @return string
26+
*/
27+
public function class(): string
28+
{
29+
return Router::class;
30+
}
31+
32+
/**
33+
* registered methods
34+
*
35+
* @return array<string, \Closure>
36+
*/
37+
public function methods(): array
38+
{
39+
return [
40+
"phpinfo" => $this->phpinfo(),
41+
];
42+
}
43+
44+
/**
45+
* phpinfo
46+
*
47+
* @return \Closure
48+
*/
49+
protected function phpinfo(): \Closure
50+
{
51+
return function (): void {
52+
$this->group(["prefix" => "phpinfo", "as" => "phpinfo."], function () {
53+
$this->get("/", function () {
54+
return PHPInfo::show();
55+
})->name("all");
56+
57+
$this->get("/general", function () {
58+
return PHPInfo::make()->general()->show();
59+
})->name("general");
60+
61+
$this->get("/credits", function () {
62+
return PHPInfo::make()->credits()->show();
63+
})->name("credits");
64+
65+
$this->get("/configuration", function () {
66+
return PHPInfo::make()->configuration()->show();
67+
})->name("configuration");
68+
69+
$this->get("/modules", function () {
70+
return PHPInfo::make()->modules()->show();
71+
})->name("modules");
72+
73+
$this->get("/variables", function () {
74+
return PHPInfo::make()->variables()->show();
75+
})->name("variables");
76+
77+
$this->get("/license", function () {
78+
return PHPInfo::make()->license()->show();
79+
})->name("license");
80+
});
81+
};
82+
}
83+
}

src/ServiceProvider.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace YukataRm\Laravel\Route;
4+
5+
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
6+
7+
use YukataRm\Laravel\Route\Macros\RouterMacro;
8+
9+
/**
10+
* Route Service Provider
11+
*
12+
* @package YukataRm\Laravel\Route
13+
*/
14+
class ServiceProvider extends BaseServiceProvider
15+
{
16+
/*----------------------------------------*
17+
* Boot
18+
*----------------------------------------*/
19+
20+
/**
21+
* boot
22+
*
23+
* @return void
24+
*/
25+
public function boot(): void
26+
{
27+
$this->bootMacros();
28+
}
29+
30+
/**
31+
* boot macros
32+
*
33+
* @return void
34+
*/
35+
protected function bootMacros(): void
36+
{
37+
$macro = new RouterMacro();
38+
39+
$macroClass = $macro->class();
40+
$macroMethods = $macro->methods();
41+
42+
if (!class_exists($macroClass)) return;
43+
44+
if (!method_exists($macroClass, "macro")) return;
45+
46+
foreach ($macroMethods as $name => $closure) {
47+
$macroClass::macro($name, $closure);
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)