-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateMiddleware.php
47 lines (41 loc) · 1.66 KB
/
CreateMiddleware.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace MiraCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
class CreateMiddleware extends Command
{
public function configure()
{
$this->setName("new:middleware")
->setDescription('Make a new middleware')
->addArgument('middleware', InputArgument::REQUIRED, "Middleware Name");
}
public function execute(InputInterface $input, OutputInterface $output)
{
$middlewareName = $input->getArgument('middleware');
$this->new($middlewareName, $output);
}
private function new($middlewareName, OutputInterface $output)
{
if (file_exists("application/Middleware/$middlewareName.php")) {
$output->writeln("Middleware already exists. Try renaming this middleware.");
return false;
}
$output->writeln("Creating Middleware ... ");
if (fopen("application/Middleware/$middlewareName.php", "a")) {
$startmiddleware = "<?php\n\n";
$startmiddleware .= "namespace Middleware;\n\n";
$startmiddleware .= "class $middlewareName\n";
$startmiddleware .= "{\n";
$startmiddleware .= "\x20\x20\x20\x20\x20 // Create a new Middleware!\n";
$startmiddleware .= "}\n";
file_put_contents("application/Middleware/$middlewareName.php", $startmiddleware);
$output->writeln("$middlewareName created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
}
}