Skip to content

Commit bf87f84

Browse files
committed
feat(make): controller, middleware and component stubs
1 parent 2b744fd commit bf87f84

4 files changed

Lines changed: 105 additions & 0 deletions

File tree

alisa

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,72 @@ switch ($argv[1] ?? null) {
3333

3434
break;
3535

36+
case 'make:component':
37+
if (!isset($argv[2])) {
38+
die('[Ошибка] Укажите название компонента: php alisa make:component <name>.');
39+
}
40+
41+
$name = $argv[2];
42+
$path = project_path('app/Components/' . $name . '.php');
43+
44+
if (file_exists($path)) {
45+
die('[Ошибка] Компонент уже существует: ' . $path . '" ');
46+
}
47+
48+
$stub = file_get_contents(project_path('framework/stubs/component.stub'));
49+
50+
$stub = str_replace('%name%', $name, $stub);
51+
52+
file_put_contents($path, $stub);
53+
54+
echo '[OK] Компонент создан: ' . $path;
55+
56+
break;
57+
58+
case 'make:controller':
59+
if (!isset($argv[2])) {
60+
die('[Ошибка] Укажите название контролера: php alisa make:controller <name>.');
61+
}
62+
63+
$name = $argv[2];
64+
$path = project_path('app/Controllers/' . $name . '.php');
65+
66+
if (file_exists($path)) {
67+
die('[Ошибка] Контроллер уже существует: ' . $path . '" ');
68+
}
69+
70+
$stub = file_get_contents(project_path('framework/stubs/controller.stub'));
71+
72+
$stub = str_replace('%name%', $name, $stub);
73+
74+
file_put_contents($path, $stub);
75+
76+
echo '[OK] Контроллер создан: ' . $path;
77+
78+
break;
79+
80+
case 'make:middleware':
81+
if (!isset($argv[2])) {
82+
die('[Ошибка] Укажите название мидлвари: php alisa make:middleware <name>.');
83+
}
84+
85+
$name = $argv[2];
86+
$path = project_path('app/Middlewares/' . $name . '.php');
87+
88+
if (file_exists($path)) {
89+
die('[Ошибка] Мидлваря уже существует: ' . $path . '" ');
90+
}
91+
92+
$stub = file_get_contents(project_path('framework/stubs/middleware.stub'));
93+
94+
$stub = str_replace('%name%', $name, $stub);
95+
96+
file_put_contents($path, $stub);
97+
98+
echo '[OK] Мидлваря создана: ' . $path;
99+
100+
break;
101+
36102
case 'help':
37103
case '--help':
38104
case '-h':

framework/stubs/component.stub

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Components;
4+
5+
use Alisa\Component;
6+
7+
class %name% extends Component
8+
{
9+
public function register()
10+
{
11+
//
12+
}
13+
}

framework/stubs/controller.stub

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
use Alisa\Context;
6+
7+
class %name%
8+
{
9+
public function __invoke(Context $context)
10+
{
11+
//
12+
}
13+
}

framework/stubs/middleware.stub

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Middlewares;
4+
5+
use Alisa\Context;
6+
7+
class %name%
8+
{
9+
public function __invoke(Context $context, $next)
10+
{
11+
$next($context);
12+
}
13+
}

0 commit comments

Comments
 (0)