aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-10-26 21:21:44 +0200
committerWilly Micieli <micieli@laposte.net>2019-10-26 21:21:44 +0200
commitb3e06f51d868324f14384a7212c7a47c6e1e73c3 (patch)
tree9c119509e3ebc123d6e2e1c105a3f128c1751f41
parentdae7f192f67162d408db732314037779b2f3c53e (diff)
downloadimperium-b3e06f51d868324f14384a7212c7a47c6e1e73c3.zip
imperium-b3e06f51d868324f14384a7212c7a47c6e1e73c3.tar.gz
add commands
-rw-r--r--imperium/Command/Command.php2
-rw-r--r--imperium/Command/CreateTwigFilter.php49
-rw-r--r--imperium/Command/CreateTwigFunction.php49
-rw-r--r--imperium/Command/CreateTwigGlobal.php48
-rw-r--r--imperium/Command/CreateTwigTest.php49
-rw-r--r--imperium/Command/GenerateMiddleware.php2
-rw-r--r--imperium/View/View.php2
7 files changed, 198 insertions, 3 deletions
diff --git a/imperium/Command/Command.php b/imperium/Command/Command.php
index abcd89b..68be506 100644
--- a/imperium/Command/Command.php
+++ b/imperium/Command/Command.php
@@ -46,7 +46,7 @@ namespace Imperium\Command {
public function run(): int
{
- $commands = [ new GenerateCommand(), new TodoMode(), new KeyGenerate(),new AdminMode(), new ImportDatabase(), new ProductionMode(), new Maintenance(), new GenerateMiddleware(), new GenerateView(), new GenerateRouteBase(), new GenerateModel(), new CleanDatabase(), new Dkim(), new DumpDatabase(), new GenerateController(), new GenerateMigrations(), new MigrateDatabase(), new RollbackDatabase(), new SeedDatabase(), new AddRoute(), new ListRoute(), new RemoveRoute(), new FindRoute(), new UpdateRoute(), new Serve()];
+ $commands = [ new CreateTwigFilter(), new CreateTwigTest(), new CreateTwigGlobal() , new CreateTwigFunction(), new GenerateCommand(), new TodoMode(), new KeyGenerate(),new AdminMode(), new ImportDatabase(), new ProductionMode(), new Maintenance(), new GenerateMiddleware(), new GenerateView(), new GenerateRouteBase(), new GenerateModel(), new CleanDatabase(), new Dkim(), new DumpDatabase(), new GenerateController(), new GenerateMigrations(), new MigrateDatabase(), new RollbackDatabase(), new SeedDatabase(), new AddRoute(), new ListRoute(), new RemoveRoute(), new FindRoute(), new UpdateRoute(), new Serve()];
$this->add($commands)->add(commands());
diff --git a/imperium/Command/CreateTwigFilter.php b/imperium/Command/CreateTwigFilter.php
new file mode 100644
index 0000000..fb0fed1
--- /dev/null
+++ b/imperium/Command/CreateTwigFilter.php
@@ -0,0 +1,49 @@
+<?php
+
+ namespace Imperium\Command;
+
+ use Imperium\Exception\Kedavra;
+ use Imperium\File\File;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Twig\Extension\AbstractExtension;
+
+ class CreateTwigFilter extends Command
+ {
+
+ protected static $defaultName = 'twig:filter';
+
+ protected function configure()
+ {
+ $this->setDescription('Add filter in all views')->addArgument('name',InputArgument::REQUIRED,'The class name');
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int|null
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $class = ucfirst($input->getArgument('name'));
+ $dir = base('app') .DIRECTORY_SEPARATOR . 'Twig'.DIRECTORY_SEPARATOR . 'Filters'. DIRECTORY_SEPARATOR. $class;
+ $file = $dir .'.php';
+ if (file_exists($file))
+ {
+ $output->writeln('<bg=red;fg=white>file already exist</>');
+ return 1;
+ }
+
+ if ((new File($file,EMPTY_AND_WRITE_FILE_MODE))->write("<?php\n\n\tnamespace App\Twig\Filters;\n\tuse Twig\Extension\AbstractExtension;\n\tuse Twig\TwigFilter;\n\n\tclass {$class} extends AbstractExtension\n\t{\n\t\n\t\tpublic function getFilters()\n\t\t{\n\t\t\treturn [\n\t\t\t\tnew TwigFilter('', '',['is_safe'=>'html'])\n\t\t\t];\n\n\t\t}\n\t}")->flush())
+ {
+ $output->writeln("<info>function was generated successfully</info>");
+ return 0;
+ }
+ return 1;
+
+ }
+
+ }
diff --git a/imperium/Command/CreateTwigFunction.php b/imperium/Command/CreateTwigFunction.php
new file mode 100644
index 0000000..5b564ca
--- /dev/null
+++ b/imperium/Command/CreateTwigFunction.php
@@ -0,0 +1,49 @@
+<?php
+
+ namespace Imperium\Command;
+
+ use Imperium\Exception\Kedavra;
+ use Imperium\File\File;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Twig\Extension\AbstractExtension;
+
+ class CreateTwigFunction extends Command
+ {
+
+ protected static $defaultName = 'twig:function';
+
+ protected function configure()
+ {
+ $this->setDescription('Add functions in all views')->addArgument('name',InputArgument::REQUIRED,'The class name');
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int|null
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $class = ucfirst($input->getArgument('name'));
+ $dir = base('app') .DIRECTORY_SEPARATOR . 'Twig'.DIRECTORY_SEPARATOR . 'Functions'. DIRECTORY_SEPARATOR. $class;
+ $file = $dir .'.php';
+ if (file_exists($file))
+ {
+ $output->writeln('<bg=red;fg=white>file already exist</>');
+ return 1;
+ }
+
+ if ((new File($file,EMPTY_AND_WRITE_FILE_MODE))->write("<?php\n\n\tnamespace App\Twig\Functions;\n\tuse Twig\Extension\AbstractExtension;\n\n\tclass {$class} extends AbstractExtension\n\t{\n\t\n\t\tpublic function getFunctions()\n\t\t{\n\t\t\treturn [\n\t\t\t\tnew \Twig\TwigFunction('', '',['is_safe'=>'html'])\n\t\t\t];\n\n\t\t}\n\t}")->flush())
+ {
+ $output->writeln("<info>function was generated successfully</info>");
+ return 0;
+ }
+ return 1;
+
+ }
+
+ }
diff --git a/imperium/Command/CreateTwigGlobal.php b/imperium/Command/CreateTwigGlobal.php
new file mode 100644
index 0000000..e431b5c
--- /dev/null
+++ b/imperium/Command/CreateTwigGlobal.php
@@ -0,0 +1,48 @@
+<?php
+
+ namespace Imperium\Command;
+
+ use Imperium\Exception\Kedavra;
+ use Imperium\File\File;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+
+ class CreateTwigGlobal extends Command
+ {
+
+ protected static $defaultName = 'twig:global';
+
+ protected function configure()
+ {
+ $this->setDescription('Add global variable in all views')->addArgument('name',InputArgument::REQUIRED,'The class name');
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int|null
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $class = ucfirst($input->getArgument('name'));
+ $dir = base('app') .DIRECTORY_SEPARATOR . 'Twig'.DIRECTORY_SEPARATOR . 'Globals'. DIRECTORY_SEPARATOR. $class;
+ $file = $dir .'.php';
+ if (file_exists($file))
+ {
+ $output->writeln('<bg=red;fg=white>file already exist</>');
+ return 1;
+ }
+
+ if ((new File($file,EMPTY_AND_WRITE_FILE_MODE))->write("<?php\n\n\tnamespace App\Twig\Globals;\n\tuse Twig\Extension\AbstractExtension;\n\n\tclass {$class} extends AbstractExtension\n\t{\n\t\n\t\tpublic function getGlobals()\n\t\t{\n\t\t\treturn [\n\t\t\t\t'' => ''\n\t\t\t];\n\n\t\t}\n\t}")->flush())
+ {
+ $output->writeln("<info>function was generated successfully</info>");
+ return 0;
+ }
+ return 1;
+
+ }
+
+ }
diff --git a/imperium/Command/CreateTwigTest.php b/imperium/Command/CreateTwigTest.php
new file mode 100644
index 0000000..9f025a9
--- /dev/null
+++ b/imperium/Command/CreateTwigTest.php
@@ -0,0 +1,49 @@
+<?php
+
+ namespace Imperium\Command;
+
+ use Imperium\Exception\Kedavra;
+ use Imperium\File\File;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Twig\TwigTest;
+
+ class CreateTwigTest extends Command
+ {
+
+ protected static $defaultName = 'twig:test';
+
+ protected function configure()
+ {
+ $this->setDescription('Add twig test extension')->addArgument('name',InputArgument::REQUIRED,'The class name');
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int|null
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $class = ucfirst($input->getArgument('name'));
+ $dir = base('app') .DIRECTORY_SEPARATOR . 'Twig'.DIRECTORY_SEPARATOR . 'Tests'. DIRECTORY_SEPARATOR. $class;
+ $file = $dir .'.php';
+ if (file_exists($file))
+ {
+ $output->writeln('<bg=red;fg=white>file already exist</>');
+ return 1;
+ }
+
+ if ((new File($file,EMPTY_AND_WRITE_FILE_MODE))->write("<?php\n\n\tnamespace App\Twig\Tests;\n\tuse Twig\Extension\AbstractExtension;\n\tuse Twig\TwigTest;\n\n\tclass {$class} extends AbstractExtension\n\t{\n\t\n\t\tpublic function getTests()\n\t\t{\n\t\t\treturn [\n\t\t\t\tnew TwigTest('', '')\n\t\t\t];\n\n\t\t}\n\t}")->flush())
+ {
+ $output->writeln("<info>function was generated successfully</info>");
+ return 0;
+ }
+ return 1;
+
+ }
+
+ }
diff --git a/imperium/Command/GenerateMiddleware.php b/imperium/Command/GenerateMiddleware.php
index 842b85c..f99330a 100644
--- a/imperium/Command/GenerateMiddleware.php
+++ b/imperium/Command/GenerateMiddleware.php
@@ -44,7 +44,7 @@
if(file_exists($file))
{
- $output->write("<bg=red;fg=white>The $x middleware already exist\n");
+ $output->write("<bg=red;fg=white>The $x middleware already exist\n</>");
return 1;
}
diff --git a/imperium/View/View.php b/imperium/View/View.php
index 3d69c3e..8aef1d9 100644
--- a/imperium/View/View.php
+++ b/imperium/View/View.php
@@ -206,7 +206,7 @@
$this->add_test(glob(base('app').DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR .'*.php'));
-
+
}