aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-10-23 20:15:39 +0200
committerWilly Micieli <micieli@laposte.net>2019-10-23 20:15:39 +0200
commit64732aa97a6985601e06e3e5c0e5e7ccda28861e (patch)
treee00e507333a80c2852b3f368421c96333c9c868c
parent667ee46472a44d6b7d425dd548e2daee961dd1fc (diff)
downloadimperium-64732aa97a6985601e06e3e5c0e5e7ccda28861e.zip
imperium-64732aa97a6985601e06e3e5c0e5e7ccda28861e.tar.gz
start todo
-rw-r--r--imperium/Action/Todo.php32
-rw-r--r--imperium/App.php9
-rw-r--r--imperium/Command/AddRoute.php99
-rw-r--r--imperium/Command/Command.php2
-rw-r--r--imperium/Command/FindRoute.php157
-rw-r--r--imperium/Command/GenerateRouteBase.php10
-rw-r--r--imperium/Command/ListRoute.php52
-rw-r--r--imperium/Command/RemoveRoute.php125
-rw-r--r--imperium/Command/TodoMode.php30
-rw-r--r--imperium/Command/UpdateRoute.php110
-rw-r--r--imperium/Model/Model.php16
-rw-r--r--imperium/Model/Task.php29
-rw-r--r--imperium/Query/Query.php16
-rw-r--r--imperium/Routing/Router.php27
14 files changed, 601 insertions, 113 deletions
diff --git a/imperium/Action/Todo.php b/imperium/Action/Todo.php
new file mode 100644
index 0000000..110be62
--- /dev/null
+++ b/imperium/Action/Todo.php
@@ -0,0 +1,32 @@
+<?php
+
+
+namespace Imperium\Action;
+
+
+use DI\DependencyException;
+use DI\NotFoundException;
+use Imperium\Exception\Kedavra;
+use Imperium\Model\Model;
+
+class Todo extends Model
+{
+ protected $table = "toto";
+
+ protected $todo = true;
+
+ /**
+ *
+ * Create the table
+ *
+ * @return bool
+ *
+ * @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ public static function generate(): bool
+ {
+ return static::query()->connexion()->execute(static::$create_todo);
+ }
+} \ No newline at end of file
diff --git a/imperium/App.php b/imperium/App.php
index f303475..d856ece 100644
--- a/imperium/App.php
+++ b/imperium/App.php
@@ -326,6 +326,15 @@ namespace Imperium {
return $x instanceof RedirectResponse ? $x->send() : $x->call()->send();
}
+ if (equal(config('mode', 'mode'), 'todo') && equal($this->request()->getClientIp(),'127.0.0.1'))
+ {
+
+ $x = $this->router(ServerRequest::fromGlobals())->search();
+
+ return $x instanceof RedirectResponse ? $x->send() : $x->call()->send();
+ }
+
+
return $this->view('maintenance', [], 503, ['Retry-After' => 600])->send();
}
diff --git a/imperium/Command/AddRoute.php b/imperium/Command/AddRoute.php
index 43a16ab..29c050d 100644
--- a/imperium/Command/AddRoute.php
+++ b/imperium/Command/AddRoute.php
@@ -2,8 +2,11 @@
namespace Imperium\Command {
+ use DI\DependencyException;
+ use DI\NotFoundException;
use Imperium\Collection\Collect;
use Imperium\Exception\Kedavra;
+ use Imperium\Model\Task;
use Imperium\Model\Web;
use Imperium\Model\Admin;
use Symfony\Component\Console\Input\InputInterface;
@@ -36,7 +39,8 @@ namespace Imperium\Command {
* @param OutputInterface $output
*
* @throws Kedavra
- *
+ * @throws DependencyException
+ * @throws NotFoundException
*/
public function interact(InputInterface $input, OutputInterface $output)
{
@@ -51,15 +55,15 @@ namespace Imperium\Command {
do {
clear_terminal();
- $question = new Question("<info>Route for admin or web ?</info> : ");
+ $question = new Question("<info>Route for admin, web or task ?</info> : ");
- $question->setAutocompleterValues(['admin', 'web']);
+ $question->setAutocompleterValues(['admin', 'web','task']);
$route = $helper->ask($input, $output, $question);
$this->entry->put('route', $route);
- } while (is_null($route) || not_in(['admin', 'web'], $route));
+ } while (is_null($route) || not_in(['admin', 'web' ,'task'], $route));
do {
clear_terminal();
@@ -128,9 +132,68 @@ namespace Imperium\Command {
} while (is_null($action) || def(Web::where('action', EQUAL, $action)->all()));
- } else
+ } elseif($this->entry->get('route') == 'admin')
{
- do {
+
+
+ do {
+ clear_terminal();
+
+ $question = new Question("<info>Define the route name</info> : ");
+
+ $name = $helper->ask($input, $output, $question);
+
+ $this->entry->put('name', $name);
+
+ } while (is_null($name) || def(Admin::where('name', EQUAL, $name)->all()));
+
+ do {
+ clear_terminal();
+
+ $question = new Question("<info>Define the route url</info> : ");
+
+ $url = $helper->ask($input, $output, $question);
+
+ $this->entry->put('url', $url);
+
+ } while (is_null($url) || def(Admin::where('url', EQUAL, $url)->all()));
+
+
+ do {
+
+ clear_terminal();
+
+ $question = new Question("<info>Define the controller to call</info> : ");
+
+ $question->setAutocompleterValues(controllers());
+
+ $controller = $helper->ask($input, $output, $question);
+
+ $this->entry->put('controller', $controller);
+
+ } while (is_null($controller));
+
+ do {
+
+ clear_terminal();
+
+ $question = new Question("<info>Define the action to call</info> : ");
+
+ $x = "App\Controllers\\{$this->entry->get('controller')}";
+
+ if (class_exists($x))
+ $question->setAutocompleterValues(get_class_methods(new $x));
+
+ $action = $helper->ask($input, $output, $question);
+
+ $this->entry->put('action', $action);
+
+ } while (is_null($action) || def(Admin::where('action', EQUAL, $action)->all()));
+
+ }else
+ {
+ do
+ {
clear_terminal();
$question = new Question("<info>Define the route name</info> : ");
@@ -139,7 +202,7 @@ namespace Imperium\Command {
$this->entry->put('name', $name);
- } while (is_null($name) || def(Admin::where('name', EQUAL, $name)->all()));
+ } while (is_null($name) || def(Task::where('name', EQUAL, $name)->all()));
do {
clear_terminal();
@@ -150,8 +213,7 @@ namespace Imperium\Command {
$this->entry->put('url', $url);
- } while (is_null($url) || def(Admin::where('url', EQUAL, $url)->all()));
-
+ } while (is_null($url) || def(Task::where('url', EQUAL, $url)->all()));
do {
@@ -183,12 +245,21 @@ namespace Imperium\Command {
$this->entry->put('action', $action);
- } while (is_null($action) || def(Admin::where('action', EQUAL, $action)->all()));
-
+ } while (is_null($action) || def(Task::where('action', EQUAL, $action)->all()));
}
-
- $this->entry->get('route') == 'web' ? $this->routes->push(Web::create($this->entry->all())) : $this->routes->push(Admin::create($this->entry->all()));
+ switch ($this->entry->get('route'))
+ {
+ case 'admin':
+ $this->routes->push(Admin::create($this->entry->all()));
+ break;
+ case 'task':
+ $this->routes->push(Task::create($this->entry->all()));
+ break;
+ default:
+ $this->routes->push(Web::create($this->entry->all()));
+ break;
+ }
$this->entry->clear();
@@ -211,7 +282,7 @@ namespace Imperium\Command {
{
if ($this->routes->ok())
{
- $output->writeln('<bg=green;fg=white>All routes was successfully created</>');
+ $output->writeln('<info>All routes was successfully created</info>');
return 0;
}
$output->writeln('<bg=red;fg=white>Fail to create routes</>');
diff --git a/imperium/Command/Command.php b/imperium/Command/Command.php
index e5e9263..20bda27 100644
--- a/imperium/Command/Command.php
+++ b/imperium/Command/Command.php
@@ -46,7 +46,7 @@ namespace Imperium\Command {
public function run(): int
{
- $commands = [ 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 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/FindRoute.php b/imperium/Command/FindRoute.php
index 05afed6..f9f5a3b 100644
--- a/imperium/Command/FindRoute.php
+++ b/imperium/Command/FindRoute.php
@@ -2,8 +2,11 @@
namespace Imperium\Command {
+ use DI\DependencyException;
+ use DI\NotFoundException;
use Imperium\Exception\Kedavra;
use Imperium\Model\Admin;
+ use Imperium\Model\Task;
use Imperium\Model\Web;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -14,7 +17,13 @@ namespace Imperium\Command {
protected static $defaultName = "route:find";
+ /**
+ * @var string
+ */
private $search;
+ /**
+ * @var string
+ */
private $choose;
protected function configure()
@@ -31,6 +40,8 @@ namespace Imperium\Command {
*
*
* @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
*/
public function interact(InputInterface $input, OutputInterface $output)
{
@@ -42,32 +53,51 @@ namespace Imperium\Command {
do {
clear_terminal();
- $question = new Question("<info>Route for admin or web ?</info> : ");
+ $question = new Question("<info>Route for admin, web or task ?</info> : ");
- $question->setAutocompleterValues(['admin', 'web']);
+ $question->setAutocompleterValues(['admin', 'web','task']);
$this->choose = $helper->ask($input, $output, $question);
- } while (is_null($this->choose) || not_in(['admin', 'web'], $this->choose));
+ } while (is_null($this->choose) || not_in(['admin', 'web','task'], $this->choose));
do {
clear_terminal();
$question = new Question("<info>Please enter the search value : </info>");
- if (equal($this->choose,'web'))
- $question->setAutocompleterValues($this->web());
- else
- $question->setAutocompleterValues($this->admin());
-
- $this->search = $helper->ask($input, $output, $question);
+ switch ($this->choose)
+ {
+ case 'admin':
+ $question->setAutocompleterValues($this->admin());
+ break;
+ case 'task':
+ $question->setAutocompleterValues($this->task());
+ break;
+ default:
+ $question->setAutocompleterValues($this->web());
+ break;
+ }
+
+ $this->search = $helper->ask($input, $output, $question);
} while (is_null($this->search));
clear_terminal();
+ switch ($this->choose)
+ {
+ case 'admin':
+ routes($output,Admin::search($this->search)) ;
+ break;
+ case 'task':
+ routes($output, Task::search($this->search));
+ break;
+ default:
+ routes($output,Web::search($this->search));
+ break;
+ }
- $this->choose == 'admin' ? routes($output, Admin::search($this->search)) : routes($output, Web::search($this->search));
$question = new Question("<info>Continue [Y/n] : </info>", 'Y');
@@ -91,7 +121,15 @@ namespace Imperium\Command {
return 0;
}
- private function controller(bool $web = true): array
+ /**
+ * @param bool $web
+ * @param bool $admin
+ * @return array
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
+ private function controller(bool $web =true,bool $admin = false): array
{
$x = collect();
if ($web)
@@ -101,13 +139,33 @@ namespace Imperium\Command {
return $x->all();
}
- foreach (Admin::all() as $v)
+ if ($admin)
+ {
+ foreach (Admin::all() as $v)
+ $x->push($v->controller);
+
+
+ return $x->all();
+ }
+
+
+ foreach (Task::all() as $v)
$x->push($v->controller);
+
return $x->all();
+
}
- private function name(bool $web = true): array
+ /**
+ * @param bool $web
+ * @param bool $admin
+ * @return array
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
+ private function name(bool $web = true,bool $admin =false): array
{
$x = collect();
if ($web)
@@ -117,13 +175,29 @@ namespace Imperium\Command {
return $x->all();
}
- foreach (Admin::all() as $v)
+ if ($admin)
+ {
+ foreach (Admin::all() as $v)
+ $x->push($v->name);
+ return $x->all();
+ }
+
+ foreach (Task::all() as $v)
$x->push($v->name);
+
return $x->all();
}
- private function url(bool $web = true): array
+ /**
+ * @param bool $web
+ * @param bool $admin
+ * @return array
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
+ private function url(bool $web = true,bool $admin = false): array
{
$x = collect();
if ($web)
@@ -133,13 +207,30 @@ namespace Imperium\Command {
return $x->all();
}
- foreach (Admin::all() as $v)
+ if ($admin)
+ {
+ foreach (Admin::all() as $v)
+ $x->push($v->url);
+ return $x->all();
+ }
+
+
+ foreach (Task::all() as $v)
$x->push($v->url);
return $x->all();
+
}
- private function action(bool $web =true)
+ /**
+ * @param bool $web
+ * @param bool $admin
+ * @return array
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
+ private function action(bool $web =true,bool $admin = false)
{
$x = collect();
if ($web)
@@ -149,7 +240,16 @@ namespace Imperium\Command {
return $x->all();
}
- foreach (Admin::all() as $v)
+ if ($admin)
+ {
+ foreach (Admin::all() as $v)
+ $x->push($v->action);
+
+ return $x->all();
+ }
+
+
+ foreach (Task::all() as $v)
$x->push($v->action);
return $x->all();
@@ -157,19 +257,38 @@ namespace Imperium\Command {
/**
* @return array
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
*/
private function web()
{
return collect()->merge(controllers(), collect(METHOD_SUPPORTED)->for('strtolower')->all(),$this->name(), $this->url(),$this->action(), $this->controller())->all();
}
+
/**
* @return array
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
*/
private function admin()
{
- return collect()->merge(controllers(), collect(METHOD_SUPPORTED)->for('strtolower')->all(),$this->name(false),$this->url(false),$this->action(false),$this->controller(false))->all();
+ return collect()->merge(controllers(), collect(METHOD_SUPPORTED)->for('strtolower')->all(),$this->name(false,true),$this->url(false,true),$this->action(false,true),$this->controller(false,true))->all();
+ }
+
+ /**
+ * @return array
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
+ private function task()
+ {
+
+ return collect()->merge(controllers(), collect(METHOD_SUPPORTED)->for('strtolower')->all(),$this->name(false,false),$this->url(false,false),$this->action(false,false),$this->controller(false,false))->all();
}
}
diff --git a/imperium/Command/GenerateRouteBase.php b/imperium/Command/GenerateRouteBase.php
index 7b2121c..88d349d 100644
--- a/imperium/Command/GenerateRouteBase.php
+++ b/imperium/Command/GenerateRouteBase.php
@@ -2,10 +2,12 @@
namespace Imperium\Command
{
-
- use Imperium\Directory\Dir;
+
+ use Imperium\Action\Todo;
+ use Imperium\Directory\Dir;
use Imperium\Exception\Kedavra;
- use Imperium\Model\Web;
+ use Imperium\Model\Task;
+ use Imperium\Model\Web;
use Imperium\Model\Admin;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
@@ -33,6 +35,8 @@
{
Web::generate();
Admin::generate();
+ Task::generate();
+ Todo::generate();
return 0;
}
diff --git a/imperium/Command/ListRoute.php b/imperium/Command/ListRoute.php
index 0c611ae..15c1acb 100644
--- a/imperium/Command/ListRoute.php
+++ b/imperium/Command/ListRoute.php
@@ -2,9 +2,12 @@
namespace Imperium\Command
{
-
- use Imperium\Exception\Kedavra;
+
+ use DI\DependencyException;
+ use DI\NotFoundException;
+ use Imperium\Exception\Kedavra;
use Imperium\Model\Admin;
+ use Imperium\Model\Task;
use Imperium\Model\Web;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -25,37 +28,54 @@
$this->setDescription('List all routes');
}
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @throws Kedavra
+ */
public function interact(InputInterface $input, OutputInterface $output)
{
$helper = $this->getHelper('question');
do {
clear_terminal();
- $question = new Question("<info>Route for admin or web ?</info> : ");
+ $question = new Question("<info>Route for admin, web or task ?</info> : ");
- $question->setAutocompleterValues(['admin', 'web']);
+ $question->setAutocompleterValues(['admin', 'web','task']);
$this->choose = $helper->ask($input, $output, $question);
- } while (is_null($this->choose) || not_in(['admin', 'web'], $this->choose));
+ } while (is_null($this->choose) || not_in(['admin', 'web','task'], $this->choose));
}
/**
- *
- * List routes
- *
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @throws Kedavra
- * @return int|null
- *
- */
+ *
+ * List routes
+ *
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @return int|null
+ * @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
public function execute(InputInterface $input, OutputInterface $output)
{
+ switch ($this->choose)
+ {
+ case 'admin':
+ routes($output,Admin::all()) ;
+ break;
+ case 'task':
+ routes($output, Task::all());
+ break;
+ default:
+ routes($output,Web::all());
+ break;
+ }
- $this->choose == 'admin' ? routes($output,Admin::all()) : routes($output, Web::all());
return 0;
}
diff --git a/imperium/Command/RemoveRoute.php b/imperium/Command/RemoveRoute.php
index 7391417..f237b7d 100644
--- a/imperium/Command/RemoveRoute.php
+++ b/imperium/Command/RemoveRoute.php
@@ -2,15 +2,19 @@
namespace Imperium\Command;
- use Imperium\Exception\Kedavra;
+ use DI\DependencyException;
+ use DI\NotFoundException;
+ use Imperium\Exception\Kedavra;
use Imperium\Model\Admin;
+ use Imperium\Model\Task;
use Imperium\Model\Web;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
-
- class RemoveRoute extends \Symfony\Component\Console\Command\Command
+ use function collect;
+
+ class RemoveRoute extends \Symfony\Component\Console\Command\Command
{
protected static $defaultName = "route:destroy";
@@ -26,6 +30,9 @@
*/
private $names;
+ /**
+ * @var Helper
+ */
private $helper;
protected function configure()
@@ -33,27 +40,44 @@
$this->setDescription('Delete a route');
}
- public function name(bool $web = true)
+ /**
+ * @param bool $web
+ * @param bool $admin
+ * @return array
+ * @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ public function name(bool $web = true, $admin = false)
{
- $x = \collect();
+ $x = collect();
if ($web)
{
foreach (Web::all() as $v)
$x->push($v->name);
return $x->all();
}
+ if ($admin)
+ {
+ foreach (Admin::all() as $v)
+ $x->push($v->name);
- foreach (Admin::all() as $v)
+ return $x->all();
+ }
+ foreach (Task::all() as $v)
$x->push($v->name);
return $x->all();
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @throws Kedavra
- */
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
public function interact(InputInterface $input, OutputInterface $output)
{
@@ -62,28 +86,41 @@
do {
clear_terminal();
- $question = new Question("<info>Route for admin or web ?</info> : ");
+ $question = new Question("<info>Route for admin, web or task ?</info> : ");
- $question->setAutocompleterValues(['admin', 'web']);
+ $question->setAutocompleterValues(['admin', 'web','task']);
$this->choose = $this->helper->ask($input, $output, $question);
- } while (is_null($this->choose) || not_in(['admin', 'web'], $this->choose));
+ } while (is_null($this->choose) || not_in(['admin', 'web','task'], $this->choose));
+ switch ($this->choose)
+ {
+ case 'admin':
+ $this->names = $this->name(false);
+ break;
+ case 'task':
+ $this->names = $this->name(false,false);
+ break;
+ default:
+ $this->names = $this->name();
+ break;
+ }
- $this->names = $this->choose == 'web' ? $this->name() : $this->name(false);
}
-
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @throws Kedavra
- * @return int|void|null
- */
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @return int|void|null
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
public function execute(InputInterface $input, OutputInterface $output)
{
@@ -108,22 +145,32 @@
}while(is_null($x) || collect($this->names)->not_exist($x));
- $this->id = $this->choose == 'web' ? Web::by('name',$this->route_name)->id : Admin::by('name',$this->route_name)->id;
-
- if ($this->choose == 'web')
- {
- if(Web::destroy($this->id))
- {
- $output->writeln('<bg=green;fg=white>The route was removed successfully</>');
- return 0;
- }
- }else
+ switch ($this->choose)
{
- if(Admin::destroy($this->id))
- {
- $output->writeln('<bg=green;fg=white>The route was removed successfully</>');
- return 0;
- }
+ case 'admin':
+ $this->id = Admin::by('name',$this->route_name)->id;
+ if(Admin::destroy($this->id))
+ {
+ $output->writeln('<info>The route was removed successfully</info>');
+ return 0;
+ }
+ break;
+ case 'task':
+ $this->id = Task::by('name',$this->route_name)->id;
+ if(Task::destroy($this->id))
+ {
+ $output->writeln('<info>The route was removed successfully</info>');
+ return 0;
+ }
+ break;
+ default:
+ $this->id = Web::by('name',$this->route_name)->id;
+ if(Web::destroy($this->id))
+ {
+ $output->writeln('<info>The route was removed successfully</info>');
+ return 0;
+ }
+ break;
}
$output->writeln('<bg=red;fg=white>Fail to remove route</>');
diff --git a/imperium/Command/TodoMode.php b/imperium/Command/TodoMode.php
new file mode 100644
index 0000000..4200f9a
--- /dev/null
+++ b/imperium/Command/TodoMode.php
@@ -0,0 +1,30 @@
+<?php
+
+ namespace Imperium\Command
+ {
+
+ use Imperium\File\File;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+
+
+ class TodoMode extends Command
+ {
+
+ protected static $defaultName = 'app:todo';
+
+ protected function configure()
+ {
+
+ $this->setDescription('Turn application in todo mode')->setAliases(['todo']);
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ if((new File(base('config') .DIRECTORY_SEPARATOR . 'mode.yaml',EMPTY_AND_WRITE_FILE_MODE))->write("mode: todo")->flush())
+ $output->writeln("<info>Aplication is now in todo mode</info>");
+ }
+
+ }
+ }
diff --git a/imperium/Command/UpdateRoute.php b/imperium/Command/UpdateRoute.php
index 4b7f5a9..b563471 100644
--- a/imperium/Command/UpdateRoute.php
+++ b/imperium/Command/UpdateRoute.php
@@ -2,10 +2,13 @@
namespace Imperium\Command
{
-
- use Imperium\Collection\Collect;
+
+ use DI\DependencyException;
+ use DI\NotFoundException;
+ use Imperium\Collection\Collect;
use Imperium\Exception\Kedavra;
use Imperium\Model\Admin;
+ use Imperium\Model\Task;
use Imperium\Model\Web;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -38,7 +41,16 @@
$this->setDescription('Update a route');
}
- public function name(bool $web = true)
+
+ /**
+ * @param bool $web
+ * @param bool $admin
+ * @return array
+ * @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ private function name(bool $web = true, bool $admin = false)
{
$x = \collect();
if ($web)
@@ -48,7 +60,14 @@
return $x->all();
}
- foreach (Admin::all() as $v)
+ if ($admin)
+ {
+ foreach (Admin::all() as $v)
+ $x->push($v->name);
+
+ return $x->all();
+ }
+ foreach (Task::all() as $v)
$x->push($v->name);
return $x->all();
@@ -73,13 +92,13 @@
do {
clear_terminal();
- $question = new Question("<info>Route for admin or web ?</info> : ");
+ $question = new Question("<info>Route for admin, web or task ?</info> : ");
- $question->setAutocompleterValues(['admin', 'web']);
+ $question->setAutocompleterValues(['admin', 'web','task']);
$this->choose = $helper->ask($input, $output, $question);
- } while (is_null($this->choose) || not_in(['admin', 'web'], $this->choose));
+ } while (is_null($this->choose) || not_in(['admin', 'web','task'], $this->choose));
}
@@ -90,12 +109,14 @@
*
* @return int|null
* @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$helper = $this->getHelper('question');
- if ($this->choose == 'web' && not_def(Web::all()) || $this->choose == 'admin' && not_def(Admin::all()))
+ if ($this->choose == 'web' && not_def(Web::all()) || $this->choose == 'admin' && not_def(Admin::all()) || $this->choose === 'task' && not_def(Task::all()))
{
clear_terminal();
@@ -180,13 +201,14 @@
}while(is_null($action));
$this->entry->put('id', $route->id);
- }else {
+ }elseif( $this->choose == 'admin')
+ {
do {
clear_terminal();
$question = new Question("<info>Please enter the route name : </info>");
- $question->setAutocompleterValues($this->name(false));
+ $question->setAutocompleterValues($this->name(false,true));
$this->search = $helper->ask($input, $output, $question);
@@ -247,6 +269,74 @@
} while (is_null($action));
$this->entry->put('id', $route->id);
+ }else
+ {
+ do {
+ clear_terminal();
+
+ $question = new Question("<info>Please enter the route name : </info>");
+
+ $question->setAutocompleterValues($this->name(false,false));
+
+ $this->search = $helper->ask($input, $output, $question);
+
+ } while (is_null($this->search) && not_def(Admin::where('name', EQUAL, $this->search)->all()));
+
+ $route = Task::by('name', $this->search);
+
+ do {
+ $question = new Question("<info>Change the method</info> <comment>[{$route->method}]</comment> : ", $route->method);
+
+ $question->setAutocompleterValues(collect(METHOD_SUPPORTED)->for('strtolower')->all());
+
+ $method = strtoupper($helper->ask($input, $output, $question));
+
+ $this->entry->put('method', $method);
+
+ } while (is_null($method));
+
+ do {
+ $question = new Question("<info>Change the name</info> <comment>[{$route->name}]</comment> : ", $route->name);
+
+ $name = $helper->ask($input, $output, $question);
+
+ $this->entry->put('name', $name);
+
+ } while (def(Task::where('name', EQUAL, $name)->all()) && different($route->name, $name));
+
+
+ do {
+ $question = new Question("<info>Change the url</info> <comment>[{$route->url}]</comment> : ", $route->url);
+
+ $url = $helper->ask($input, $output, $question);
+
+ $this->entry->put('url', $url);
+
+ } while (def(Task::where('url', EQUAL, $url)->all()) && different($route->url, $url));
+
+ do {
+ $question = new Question("<info>Change the controller</info> <comment>[{$route->controller}]</comment> : ", $route->controller);
+ $question->setAutocompleterValues(controllers());
+ $controller = $helper->ask($input, $output, $question);
+
+ $this->entry->put('controller', $controller);
+
+ } while (is_null($controller));
+
+ do {
+ $question = new Question("<info>Change the action</info> <comment>[{$route->action}]</comment> : ", $route->action);
+ $x = "App\Controllers\\{$this->entry->get('controller')}";
+
+ if (class_exists($x))
+ $question->setAutocompleterValues(get_class_methods(new $x));
+
+ $action = $helper->ask($input, $output, $question);
+
+ $this->entry->put('action', $action);
+
+ } while (is_null($action));
+
+ $this->entry->put('id', $route->id);
}
$this->choose == 'admin' ? $this->routes->push(Admin::update($this->entry->get('id'),$this->entry->all())) : $this->routes->push(Web::update($this->entry->get('id'),$this->entry->all()));
diff --git a/imperium/Model/Model.php b/imperium/Model/Model.php
index d0ffb1e..b83ffad 100644
--- a/imperium/Model/Model.php
+++ b/imperium/Model/Model.php
@@ -69,7 +69,9 @@
*
*/
protected static $create_route_table_query = "CREATE TABLE IF NOT EXISTS routes ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT(255) NOT NULL UNIQUE,url TEXT(255) NOT NULL UNIQUE, controller TEXT(255) NOT NULL,action TEXT(255) NOT NULL,method TEXT(255) NOT NULL);";
-
+
+ protected static $create_todo = "CREATE TABLE IF NOT EXISTS todo ( id INTEGER PRIMARY KEY AUTOINCREMENT, task TEXT(255) NOT NULL UNIQUE, priority TEXT(255) NOT NULL, description TEXT(255) NOT NULL,done TEXT(255));";
+
/**
* @var bool
*/
@@ -81,6 +83,16 @@
protected $admin = false;
/**
+ * @var bool
+ */
+ protected $todo = false;
+
+ /**
+ * @var bool
+ */
+ protected $task = false;
+
+ /**
*
* Display all columns
*
@@ -574,7 +586,7 @@
*/
private function builder() : Query
{
- return Query::from($this->table, $this->routes,$this->admin)->primary($this->primary);
+ return Query::from($this->table, $this->routes,$this->admin,$this->todo,$this->task)->primary($this->primary);
}
}
diff --git a/imperium/Model/Task.php b/imperium/Model/Task.php
new file mode 100644
index 0000000..a1c15e6
--- /dev/null
+++ b/imperium/Model/Task.php
@@ -0,0 +1,29 @@
+<?php
+
+
+namespace Imperium\Model;
+
+
+use DI\DependencyException;
+use DI\NotFoundException;
+use Imperium\Exception\Kedavra;
+
+class Task extends Model
+{
+ protected $table = "routes";
+
+ protected $task = true;
+
+ /**
+ *
+ * @return bool
+ * @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ public static function generate(): bool
+ {
+ return static::query()->connexion()->execute(static::$create_route_table_query);
+ }
+
+} \ No newline at end of file
diff --git a/imperium/Query/Query.php b/imperium/Query/Query.php
index b45fdbf..8ac9f21 100644
--- a/imperium/Query/Query.php
+++ b/imperium/Query/Query.php
@@ -221,18 +221,24 @@
*
* @param bool $web
* @param bool $admin
+ * @param bool $todo
+ * @param bool $task
* @throws DependencyException
* @throws NotFoundException
*/
- public function __construct(bool $web = false,bool $admin = false)
+ public function __construct(bool $web = false,bool $admin = false,bool $todo =false,bool $task = false)
{
if ($web)
$this->connexion = connect(SQLITE, base('app'). DIRECTORY_SEPARATOR . 'Routing' .DIRECTORY_SEPARATOR. 'web.sqlite3');
elseif($admin)
$this->connexion = connect(SQLITE, base('app'). DIRECTORY_SEPARATOR . 'Routing' .DIRECTORY_SEPARATOR. 'admin.sqlite3');
+ elseif($task)
+ $this->connexion = connect(SQLITE, base('app'). DIRECTORY_SEPARATOR . 'Routing' .DIRECTORY_SEPARATOR. 'task.sqlite3');
+ elseif($todo)
+ $this->connexion = connect(SQLITE, base('app'). DIRECTORY_SEPARATOR . 'Tasks' .DIRECTORY_SEPARATOR. 'todo.sqlite3');
else
- $this->connexion = $this->app(Connect::class);
+ $this->connexion = $this->app(Connect::class);
}
/**
@@ -286,15 +292,17 @@
* @param bool $routes
* @param bool $admin
*
+ * @param bool $todo
+ * @param bool $task
* @return Query
*
* @throws DependencyException
* @throws NotFoundException
*/
- public static function from(string $table, bool $routes = false,bool $admin =false) : Query
+ public static function from(string $table, bool $routes = false,bool $admin =false,bool $todo = false,bool $task = false) : Query
{
- return (new static($routes,$admin))->select_table($table);
+ return (new static($routes,$admin,$todo,$task))->select_table($table);
}
/**
diff --git a/imperium/Routing/Router.php b/imperium/Routing/Router.php
index e86b7f2..d56d8ba 100644
--- a/imperium/Routing/Router.php
+++ b/imperium/Routing/Router.php
@@ -5,9 +5,10 @@
use DI\DependencyException;
use DI\NotFoundException;
- use Imperium\Directory\Dir;
+ use Imperium\Directory\Dir;
use Imperium\Exception\Kedavra;
use Imperium\Model\Admin;
+ use Imperium\Model\Task;
use Imperium\Model\Web;
use Imperium\Security\Csrf\CsrfMiddleware;
use Psr\Http\Message\ServerRequestInterface;
@@ -99,15 +100,31 @@
}else
{
- foreach(Web::where('method', EQUAL, $this->method)->all() as $route)
+ if (equal(config('mode', 'mode'), 'todo'))
{
- if($this->match($route->url))
+ foreach (Task::where('method',EQUAL,$this->method) as $route)
{
- $this->route = $route;
+ if($this->match($route->url))
+ {
+ $this->route = $route;
- return $this->result();
+ return $this->result();
+ }
}
}
+ else
+ {
+ foreach(Web::where('method', EQUAL, $this->method)->all() as $route)
+ {
+ if($this->match($route->url))
+ {
+ $this->route = $route;
+
+ return $this->result();
+ }
+ }
+ }
+
}