aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-04-18 15:51:34 +0200
committerWilly Micieli <micieli@laposte.net>2019-04-18 15:51:34 +0200
commit92d742b7d72b3215d0703e602f8065a470af8b35 (patch)
tree0c1478a4c8a54ee26cf4e5b0595f80dbbb7ce056
parent5539f9913440377699dec6662dc77410640bc147 (diff)
downloadimperium-92d742b7d72b3215d0703e602f8065a470af8b35.zip
imperium-92d742b7d72b3215d0703e602f8065a470af8b35.tar.gz
fix bugs add functionalities
-rw-r--r--Makefile2
-rw-r--r--config/twig.yaml2
-rw-r--r--db/seeds/BaseSeeds.php2
-rw-r--r--db/seeds/HelperSeeds.php2
-rw-r--r--db/seeds/HelpersSeeds.php2
-rw-r--r--db/seeds/ImperiumSeeds.php3
-rw-r--r--db/seeds/ModelSeeds.php3
-rw-r--r--helpers/helpers.php49
-rw-r--r--imperium/Asset/Asset.php1
-rw-r--r--imperium/Command/AddRoutes.php4
-rw-r--r--imperium/Command/App.php79
-rw-r--r--imperium/Command/Command.php4
-rw-r--r--imperium/Command/FindRoute.php103
-rw-r--r--imperium/Command/RemoveRoutes.php31
-rw-r--r--imperium/Command/UpdateRoutes.php12
-rw-r--r--imperium/Connexion/Connect.php6
-rw-r--r--imperium/Directory/Dir.php46
-rw-r--r--imperium/File/File.php14
-rw-r--r--imperium/Html/Form/Form.php8
-rw-r--r--imperium/Management.php4
-rw-r--r--imperium/Model/Model.php31
-rw-r--r--imperium/Query/Query.php39
-rw-r--r--imperium/Users/Users.php2
-rw-r--r--imperium/View/View.php77
-rw-r--r--phinx.php4
-rw-r--r--tests/mysql/query/QueryTest.php135
26 files changed, 523 insertions, 142 deletions
diff --git a/Makefile b/Makefile
index 0daf4ea..9614a50 100644
--- a/Makefile
+++ b/Makefile
@@ -106,8 +106,6 @@ migrate_sqlite: ## Seed sqlite database
dbs: clean ## Create all databases
@psql -c "create database $(BASE);" -U postgres
@mysql -uroot -p$(MYSQL_PASSWORD) -e "CREATE DATABASE $(BASE);"
- @touch $(BASE).sqlite3 && chmod 777 $(BASE).sqlite3
clean: ## Remove all databases
psql -c "DROP DATABASE IF EXISTS $(BASE);" -U postgres
mysql -uroot -p$(MYSQL_PASSWORD) -e "DROP DATABASE IF EXISTS $(BASE);"
- $(RM) $(BASE).sqlite3
diff --git a/config/twig.yaml b/config/twig.yaml
index 9911f62..78a165a 100644
--- a/config/twig.yaml
+++ b/config/twig.yaml
@@ -1,2 +1,2 @@
namespaces:
- admin: 'admin' \ No newline at end of file
+ admin: 'admin'
diff --git a/db/seeds/BaseSeeds.php b/db/seeds/BaseSeeds.php
index 54d116d..55fa752 100644
--- a/db/seeds/BaseSeeds.php
+++ b/db/seeds/BaseSeeds.php
@@ -15,7 +15,7 @@ class BaseSeeds extends AbstractSeed
*/
public function run()
{
- $driver = $this->getAdapter()->getAdapterType();
+
$country = [];
diff --git a/db/seeds/HelperSeeds.php b/db/seeds/HelperSeeds.php
index 8d7730f..b71aafb 100644
--- a/db/seeds/HelperSeeds.php
+++ b/db/seeds/HelperSeeds.php
@@ -14,7 +14,7 @@ class HelperSeeds extends AbstractSeed
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
- {$driver = $this->getAdapter()->getAdapterType();
+ {
$country = [];
$number = 100;
diff --git a/db/seeds/HelpersSeeds.php b/db/seeds/HelpersSeeds.php
index f414603..0162d34 100644
--- a/db/seeds/HelpersSeeds.php
+++ b/db/seeds/HelpersSeeds.php
@@ -15,7 +15,7 @@ class HelpersSeeds extends AbstractSeed
*/
public function run()
{
- $driver = $this->getAdapter()->getAdapterType();
+
$country = [];
$number = 100;
diff --git a/db/seeds/ImperiumSeeds.php b/db/seeds/ImperiumSeeds.php
index 51757f7..375f477 100644
--- a/db/seeds/ImperiumSeeds.php
+++ b/db/seeds/ImperiumSeeds.php
@@ -14,7 +14,8 @@ class ImperiumSeeds extends AbstractSeed
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
- {$driver = $this->getAdapter()->getAdapterType();
+ {
+
$country = [];
$number = 100;
diff --git a/db/seeds/ModelSeeds.php b/db/seeds/ModelSeeds.php
index 28d0db7..d44cb20 100644
--- a/db/seeds/ModelSeeds.php
+++ b/db/seeds/ModelSeeds.php
@@ -14,7 +14,8 @@ class ModelSeeds extends AbstractSeed
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
- {$driver = $this->getAdapter()->getAdapterType();
+ {
+
$country = [];
$number = 100;
diff --git a/helpers/helpers.php b/helpers/helpers.php
index 937a69b..8f5d3f4 100644
--- a/helpers/helpers.php
+++ b/helpers/helpers.php
@@ -126,12 +126,12 @@ if (not_exist('current_user'))
*
* Get the user if is logged
*
- * @return Collection
+ * @return object
*
* @throws Exception
*
*/
- function current_user(): Collection
+ function current_user()
{
return app()->auth()->current();
}
@@ -1744,6 +1744,51 @@ if (not_exist('commands'))
}
}
+
+if (not_exist('extensions'))
+{
+ /**
+ *
+ * Return all available command
+ *
+ * @param string $expected
+ * @return array
+ *
+ * @throws Exception
+ */
+ function extensions(string $expected): array
+ {
+ $core_path = core_path(collection(config('app','dir'))->get('app'));
+
+ $dir = $core_path . DIRECTORY_SEPARATOR . 'Twig' . DIRECTORY_SEPARATOR. $expected;
+
+ is_false(Dir::is($core_path),true,"The directory $core_path was not found");
+
+ is_false(Dir::is($dir),true,"The directory $dir was not found");
+
+ $namespace = config('app','namespace') . "\\Extentions\\$expected";
+
+ $path = realpath($dir);
+
+ $data = glob($path .DIRECTORY_SEPARATOR . '*.php');
+
+ $x = collection();
+
+ foreach ($data as $c)
+ {
+ $code = collection(explode(DIRECTORY_SEPARATOR,$c))->last();
+
+ $class = collection(explode('.',$code))->begin();
+
+ $code = "$namespace\\$class";
+
+ $x->add(new $code(),strtolower($class));
+ }
+
+ return $x->collection();
+ }
+}
+
if (not_exist('simply_view'))
{
diff --git a/imperium/Asset/Asset.php b/imperium/Asset/Asset.php
index 4492f4f..f81e246 100644
--- a/imperium/Asset/Asset.php
+++ b/imperium/Asset/Asset.php
@@ -37,6 +37,7 @@ namespace Imperium\Asset {
* @param string $filename
*
* @param string $type
+ *
* @return string
*/
public static function js(string $filename,string $type =''): string
diff --git a/imperium/Command/AddRoutes.php b/imperium/Command/AddRoutes.php
index 4056d10..a729ea8 100644
--- a/imperium/Command/AddRoutes.php
+++ b/imperium/Command/AddRoutes.php
@@ -1,11 +1,9 @@
<?php
-
namespace Imperium\Command {
use Imperium\Routing\Router;
- use Sinergi\BrowserDetector\Os;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -116,7 +114,7 @@ namespace Imperium\Command {
$data = collection();
foreach ($this->routes as $route)
- $data->add(app()->model()->from(Router::ROUTES)->insert_new_record($route));
+ $data->add(app()->model()->from(Router::ROUTES)->insert_new_record($route));
if ($data->not_exist(false))
$output->write("<info>All routes has been successfully created</info>\n");
diff --git a/imperium/Command/App.php b/imperium/Command/App.php
index 285c5ea..d1a869a 100644
--- a/imperium/Command/App.php
+++ b/imperium/Command/App.php
@@ -22,6 +22,7 @@ namespace Imperium\Command {
private $namespace;
private $cache;
private $web;
+ private $database_dir;
protected function configure()
{
@@ -59,9 +60,13 @@ namespace Imperium\Command {
$this->web = 'web';
- $question = new Question("<info>Enabled cache ? </info><comment>[false]</comment> : ",'false');
+ $question = new Question("<info>Cache directory </info> <comment>[cache]</comment> : ",'cache');
$this->cache = $helper->ask($input,$output,$question);
+
+ $question = new Question("<info>Set the migrations, seeding, dump directory name </info> <comment>[db]</comment> : ",'db');
+
+ $this->database_dir = $helper->ask($input,$output,$question);
}
public function execute(InputInterface $input, OutputInterface $output)
@@ -72,15 +77,14 @@ namespace Imperium\Command {
File::create($file);
- File::put($file,"dir:\n app: '$this->app_dir'\n controller: '$this->controller_dir'\n command: '$this->command_dir'\n middleware: '$this->middleware_dir'\n view: '$this->views_dir'\nnamespace: '$this->namespace'\nweb_root: '$this->web'\ndevelopment_server_port: '3000'\nconfig:\n cache: $this->cache\n charset: 'utf-8'");
+ File::put($file,"dir:\n app: '$this->app_dir'\n controller: '$this->controller_dir'\n command: '$this->command_dir'\n middleware: '$this->middleware_dir'\n view: '$this->views_dir'\n db: '$this->database_dir'\n\nnamespace: '$this->namespace'\nweb_root: '$this->web'\ndevelopment_server_port: '3000'\nconfig:\n cache: '$this->cache'\n charset: 'utf-8'");
Dir::create('locales');
Dir::create('po');
- Dir::create('db');
- Dir::create("db/seeds");
- Dir::create("db/migrations");
- Dir::create("db/dump");
+
+ Dir::structure($this->database_dir,'seeds','migrations','dump');
+
File::remove_if_exist('phinx.php');
File::create('phinx.php');
@@ -89,8 +93,8 @@ namespace Imperium\Command {
\$file = 'db';
return [
\"paths\" => [
- \"migrations\" => \"db/migrations\",
- \"seeds\" => \"db/seeds\"
+ \"migrations\" => \"{$this->database_dir}/migrations\",
+ \"seeds\" => \"{$this->database_dir}/seeds\"
],
\"environments\" =>
[
@@ -110,38 +114,28 @@ return [
$app = $this->app_dir;
$web = $this->web;
- $command = $app .DIRECTORY_SEPARATOR . $this->command_dir;
- $controllers = $app .DIRECTORY_SEPARATOR . $this->controller_dir;
- $middleware = $app .DIRECTORY_SEPARATOR . $this->middleware_dir;
$views = $app .DIRECTORY_SEPARATOR . $this->views_dir;
- Dir::remove($app);
- Dir::create($app);
- Dir::remove($web);
- Dir::create($web);
+ Dir::structure($app,$this->controller_dir,$this->middleware_dir,$this->views_dir,$this->command_dir,'Helpers');
- Dir::create($command);
- Dir::create($controllers);
- Dir::create($middleware);
- Dir::create($views);
+ Dir::structure("$app/Assets",'js','sass');
+
+ Dir::structure("$app/Twig",'Extensions','Functions','Filters','Tags','Tests','Globals');
+
+ Dir::structure($web,'img','css','js');
+
+ File::structure("$app/Helpers",'web.php','admin.php');
+
+ File::put("$app/Helpers/web.php","<?php\n");
+ File::put("$app/Helpers/admin.php","<?php\n");
+
+ Dir::copy('assets_demo',"assets");
- Dir::checkout($app);
- Dir::create('Helpers');
-
- Dir::create('Assets');
- Dir::create('Assets/sass');
-
- Dir::create('Assets/js');
-
- Dir::checkout('Helpers');
- File::create('web.php');
- File::create('admin.php');
- File::put("web.php","<?php\n");
- File::put("admin.php","<?php\n");
- Dir::checkout('../..');
Dir::copy('assets',"$app/Assets");
+
Dir::remove('assets');
+
Dir::checkout($views);
$layout ='layout.twig';
@@ -174,22 +168,22 @@ return [
{% if logged() %}
<li class=\"nav-item dropdown\">
<a class=\"nav-link dropdown-toggle\" href=\"#\" id=\"user\" role=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\">
- {{ user().get('username') }}
+ {{ user()->username }}
</a>
<div class=\"dropdown-menu\" aria-labelledby=\"user\">
- {% if user().get('id') == \"1\" %}
- <a class=\"dropdown-item\" href=\"{{ route('admin') }}\">{{ t('Admin') }}</a>
- <a class=\"dropdown-item\" href=\"{{ route('home') }}\">{{ t('Home') }}</a>
+ {% if user()->id == \"1\" %}
+ <a class=\"dropdown-item\" href=\"{{ route('admin') }}\">Admin</a>
+ <a class=\"dropdown-item\" href=\"{{ route('home') }}\">Home</a>
{% else %}
- <a class=\"dropdown-item\" href=\"{{ route('home') }}\">{{ t('Home') }}</a>
+ <a class=\"dropdown-item\" href=\"{{ route('home') }}\">Home</a>
{% endif %}
<div class=\"dropdown-divider\"></div>
- <a class=\"dropdown-item\" href=\"{{ route('logout') }}\">{{ t('Logout') }}</a>
+ <a class=\"dropdown-item\" href=\"{{ route('logout') }}\">Logout</a>
</div>
</li>
{% else %}
<li class=\"nav-item\">
- <a class=\"nav-link\" href=\"{{ route('login') }}\">{{ t('Login') }}</a>
+ <a class=\"nav-link\" href=\"{{ route('login') }}\">Login</a>
</li>
{% endif %}
</ul>
@@ -238,16 +232,11 @@ return [
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L]
</IfModule>');
- Dir::create('img');
- Dir::create('css');
- Dir::create('js');
Dir::checkout('..');
Dir::remove('tmp');
-
-
return 0;
}
diff --git a/imperium/Command/Command.php b/imperium/Command/Command.php
index 7e028d6..046a746 100644
--- a/imperium/Command/Command.php
+++ b/imperium/Command/Command.php
@@ -19,7 +19,6 @@ namespace Imperium\Command {
*
* @param string $name
* @param string $version
- *
*/
public function __construct(string $name = "UNKNOWN", string $version = 'UNKNOWN')
{
@@ -59,7 +58,8 @@ namespace Imperium\Command {
new GenerateCommand(),
new DumpDatabase(),
new UpdateDatabase(),
- new GenerateMigrations()
+ new GenerateMigrations(),
+ new FindRoute()
diff --git a/imperium/Command/FindRoute.php b/imperium/Command/FindRoute.php
new file mode 100644
index 0000000..e279b85
--- /dev/null
+++ b/imperium/Command/FindRoute.php
@@ -0,0 +1,103 @@
+<?php
+
+
+namespace Imperium\Command {
+
+
+ use Imperium\Routing\Router;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Question\Question;
+
+ class FindRoute extends Command
+ {
+ protected static $defaultName = 'routes:find';
+
+ private $name;
+
+ private function clean()
+ {
+ clear_terminal();
+ }
+
+ protected function configure()
+ {
+ $this->setDescription('Find a route');
+ }
+
+
+ public function interact(InputInterface $input, OutputInterface $output)
+ {
+ $helper = $this->getHelper('question');
+
+ do {
+ $this->clean();
+ $question = new Question("<info>Please enter the route name : </info>");
+
+ $this->name = $helper->ask($input, $output, $question);
+
+ if (app()->table_exist(Router::ROUTES))
+ {
+ $routes = app()->model()->from(Router::ROUTES)->search($this->name);
+
+ if (def($routes))
+ {
+ $output->write("+-----------------------+-----------------------+-------------------------------+-------------------------------+---------------------+\n");
+ $output->write("|\tMETHOD\t\t|\tNAME\t\t|\tURL\t\t\t|\tCONTROLLER\t\t|\tACTION\t\t|\n");
+ $output->write("+-----------------------+-----------------------+-------------------------------+-------------------------------+---------------------+\n");
+ foreach ($routes as $route)
+ {
+ $name = $route->name;
+ $url = $route->url;
+ $controller = $route->controller;
+ $action = $route->action;
+ $method = $route->method;
+
+ $output->write("|\t$method\t\t");
+
+ if (length($name) < 8)
+ $output->write("|\t$name\t\t|");
+ else
+ $output->write("|\t$name\t|");
+
+ if (length($url) < 8)
+ $output->write("\t$url\t\t\t|");
+ else
+ $output->write("\t$url\t\t|");
+
+
+ if (length($controller) < 8)
+ $output->write("\t$controller\t\t\t|");
+ else if(length($controller)> 15)
+ $output->write("\t$controller\t|");
+ else
+ $output->write("\t$controller\t\t|");
+
+ if (length($action) < 8)
+ $output->write("\t$action\t\t|\n");
+ else
+ $output->write("\t$action\t|\n");
+
+ $output->write("+-----------------------+-----------------------+-------------------------------+-------------------------------+---------------------+\n");
+ }
+ }else{
+ $output->write("<error>No routes found</error>\n");
+ }
+ }else{
+ $output->write("<error>The routes table was not fond</error>\n");
+ }
+
+ $question = new Question("<info>Continue searching ? [Y/n] : </info>",'Y');
+ $continue = strtoupper($helper->ask($input, $output, $question));
+ $continue = $continue === 'Y';
+ }while (is_null($this->name) || $continue);
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $output->write("<info>Bye</info>\n");
+ }
+
+ }
+} \ No newline at end of file
diff --git a/imperium/Command/RemoveRoutes.php b/imperium/Command/RemoveRoutes.php
index 577eee3..6274c2f 100644
--- a/imperium/Command/RemoveRoutes.php
+++ b/imperium/Command/RemoveRoutes.php
@@ -30,9 +30,18 @@ namespace Imperium\Command {
public function interact(InputInterface $input, OutputInterface $output)
{
-
$helper = $this->getHelper('question');
+ do {
+ $this->clean();
+ $question = new Question("<info>Please enter the route name : </info>");
+
+ $this->name = $helper->ask($input, $output, $question);
+
+ }while (is_null($this->name));
+ while (not_def($this->get($this->name)))
+ {
+
do {
$this->clean();
$question = new Question("<info>Please enter the route name : </info>");
@@ -41,32 +50,16 @@ namespace Imperium\Command {
}while (is_null($this->name));
+ }
- while (not_def($this->get($this->name)))
- {
-
- do {
- $this->clean();
- $question = new Question("<info>Please enter the route name : </info>");
-
- $this->name = $helper->ask($input, $output, $question);
-
-
- }while (is_null($this->name));
- }
-
- foreach ($this->get($this->name) as $route)
- $this->id = $route->id;
}
public function execute(InputInterface $input, OutputInterface $output)
{
-
- if (app()->model()->from(Router::ROUTES)->remove($this->id))
+ if (app()->model()->query()->from(Router::ROUTES)->mode(DELETE)->where('name',EQUAL,$this->name)->delete())
$output->write("<info>The route has been deleted successfully</info>\n");
else
$output->write("<error>The route deletion has failed</error>\n");
-
}
diff --git a/imperium/Command/UpdateRoutes.php b/imperium/Command/UpdateRoutes.php
index 620f942..388d92f 100644
--- a/imperium/Command/UpdateRoutes.php
+++ b/imperium/Command/UpdateRoutes.php
@@ -53,18 +53,6 @@ namespace Imperium\Command {
}while (is_null($this->name));
- while (not_def($this->get($this->name)))
- {
-
- do {
- $this->clean();
- $question = new Question("<info>Please enter the route name : </info>");
-
- $this->name = $helper->ask($input, $output, $question);
-
-
- }while (is_null($this->name));
- }
$this->clean();
$this->print($output);
foreach ($this->get($this->name) as $route)
diff --git a/imperium/Connexion/Connect.php b/imperium/Connexion/Connect.php
index 2c03f50..dbfe522 100644
--- a/imperium/Connexion/Connect.php
+++ b/imperium/Connexion/Connect.php
@@ -164,9 +164,7 @@ namespace Imperium\Connexion {
{
- $this->dump_path = dirname(config_path()) .DIRECTORY_SEPARATOR . $dump_path;
-
- Dir::create($this->dump_path);
+ $this->dump_path = dirname(config_path()) .DIRECTORY_SEPARATOR . collection(config('app','dir'))->get('db') . DIRECTORY_SEPARATOR . $dump_path;
$this->driver = $driver;
@@ -554,7 +552,6 @@ namespace Imperium\Connexion {
$this->instance = new PDO("$driver:host=$host;dbname=$database",$username,$password);
}catch (PDOException $e)
{
- d($e->errorInfo,$this->instance->errorInfo(),$e->getLine(),$e->getMessage());
return $e->getMessage();
}
}
@@ -572,6 +569,7 @@ namespace Imperium\Connexion {
return $this->instance;
}
$this->instance->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
+ $this->instance->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
return $this->instance;
}
diff --git a/imperium/Directory/Dir.php b/imperium/Directory/Dir.php
index 697cb72..97a19b0 100644
--- a/imperium/Directory/Dir.php
+++ b/imperium/Directory/Dir.php
@@ -25,7 +25,7 @@ namespace Imperium\Directory {
'.gitignore',
'.hgignore',
);
-
+
/**
* @param string $directory
@@ -59,6 +59,26 @@ namespace Imperium\Directory {
return false;
}
+
+ /**
+ *
+ * Create a structure
+ *
+ * @param string $source
+ * @param string ...$dirs
+ *
+ * @throws Exception
+ *
+ */
+ public static function structure(string $source,string ...$dirs): void
+ {
+ if (self::is($source))
+ self::remove($source);
+
+ self::create($source);
+ foreach ($dirs as $dir)
+ self::create("$source/$dir");
+ }
/**
*
* Remove all files in the directory expect ignore files
@@ -89,15 +109,16 @@ namespace Imperium\Directory {
}
/**
- *
+ *
* Copy a dir
- *
- * @param string $source Source path
- * @param string $dest Destination path
- * @param int $permissions New folder creation permissions
*
- * @return bool
- *
+ * @param string $source Source path
+ * @param string $dest Destination path
+ * @param int $permissions New folder creation permissions
+ *
+ * @return bool
+ *
+ * @throws Exception
*/
public static function copy(string $source,string $dest,int $permissions = 0755): bool
{
@@ -139,7 +160,9 @@ namespace Imperium\Directory {
}
/**
- *
+ * @param string $dir
+ * @param int $sorting_order
+ * @return array
*/
public static function scan(string $dir,$sorting_order = SCANDIR_SORT_ASCENDING ): array
{
@@ -152,16 +175,15 @@ namespace Imperium\Directory {
*
* @method create
*
- * @param string $directory The name of directory
+ * @param string $directory The name of directory
*
+ * @param int $permissions
* @return bool
*
* @throws Exception
- *
*/
public static function create(string $directory,int $permissions = 0755): bool
{
-
return is_false(self::is($directory)) ? mkdir($directory,$permissions): false;
}
diff --git a/imperium/File/File.php b/imperium/File/File.php
index 58571a2..260f197 100644
--- a/imperium/File/File.php
+++ b/imperium/File/File.php
@@ -387,6 +387,20 @@ namespace Imperium\File {
}
/**
+ * Generate file in the source dir
+ *
+ * @param string $source
+ * @param string ...$filenames
+ *
+ * @return void
+ *
+ */
+ public static function structure(string $source,string ...$filenames):void
+ {
+ foreach ($filenames as $filename)
+ self::create("$source/$filename");
+ }
+ /**
* Get the files's last modification time.
*
* @param string $filename
diff --git a/imperium/Html/Form/Form.php b/imperium/Html/Form/Form.php
index bf7494d..f15b695 100644
--- a/imperium/Html/Form/Form.php
+++ b/imperium/Html/Form/Form.php
@@ -1330,6 +1330,14 @@ namespace Imperium\Html\Form {
}
+ /**
+ * @param string $column
+ * @param string $value
+ * @param string $table
+ *
+ * @return Form
+ *
+ */
public function primary(string $column,string $value,string $table) : Form
{
append($this->form,'<input type="hidden" name="'.$column.'" value="'.$value.'"> <input type="hidden" name="__table__" value="'.$table.'"> ');
diff --git a/imperium/Management.php b/imperium/Management.php
index e230068..26bd72c 100644
--- a/imperium/Management.php
+++ b/imperium/Management.php
@@ -589,12 +589,10 @@ namespace Imperium {
* Dump a base or tables
*
* @param bool $base
- * @param string[] $tables
+ * @param string ...$tables
*
* @return bool
*
- * @throws Exception
- *
*/
public function dump(bool $base,string ...$tables) : bool;
diff --git a/imperium/Model/Model.php b/imperium/Model/Model.php
index 275ed21..f469932 100644
--- a/imperium/Model/Model.php
+++ b/imperium/Model/Model.php
@@ -298,13 +298,14 @@ namespace Imperium\Model {
* @param string $column
* @param mixed $expected
*
- * @return object
+ * @return array
*
* @throws Exception
+ *
*/
- public function by(string $column,$expected)
+ public function by(string $column,$expected): array
{
- return $this->from($this->current())->by($column,$expected);
+ return $this->from($this->current())->where($column,EQUAL,$expected)->get();
}
/**
@@ -359,13 +360,12 @@ namespace Imperium\Model {
*
* @method search
*
- * @param string $value The value to search
+ * @param string $value The value to search
* @param bool $json_output To save data in a json file
*
- * @return object|bool
+ * @return array|string
*
* @throws Exception
- *
*/
public function search(string $value,bool $json_output = false)
{
@@ -568,18 +568,14 @@ namespace Imperium\Model {
*
* @method get
*
- * @param bool $use_fetch
- * @return mixed
+ * @return array
*
* @throws Exception
*/
- public function get(bool $use_fetch = false)
+ public function get(): array
{
is_true(not_def($this->column,$this->expected,$this->condition),true,"The where clause was not found");
- if ($use_fetch)
- return def($this->only) ? $this->query()->from($this->current())->mode(Query::SELECT)->where($this->column,$this->condition,$this->expected)->only($this->only)->use_fetch()->get() : $this->query()->from($this->current())->mode(Query::SELECT)->where($this->column,$this->condition,$this->expected)->use_fetch()->get();
-
return def($this->only) ? $this->query()->from($this->current())->mode(Query::SELECT)->where($this->column,$this->condition,$this->expected)->only($this->only)->get() : $this->query()->from($this->current())->mode(Query::SELECT)->where($this->column,$this->condition,$this->expected)->get();
}
@@ -672,7 +668,6 @@ namespace Imperium\Model {
}
-
/**
*
* Get the news records with a limit and order by clause
@@ -681,11 +676,11 @@ namespace Imperium\Model {
* @param int $limit
* @param int $offset
*
- * @return object
+ * @return array
*
* @throws Exception
*/
- public function news(string $order_column,int $limit,int $offset = 0)
+ public function news(string $order_column,int $limit,int $offset = 0): array
{
return $this->query()->from($this->current())->mode(Query::SELECT)->limit($limit,$offset)->order_by($order_column)->get();
}
@@ -698,11 +693,11 @@ namespace Imperium\Model {
* @param int $limit
* @param int $offset
*
- * @return object
+ * @return array
*
* @throws Exception
*/
- public function last(string $order_column,int $limit,int $offset = 0)
+ public function last(string $order_column,int $limit,int $offset = 0): array
{
return $this->query()->from($this->current())->mode(Query::SELECT)->limit($limit,$offset)->order_by($order_column,ASC)->get();
}
@@ -744,7 +739,7 @@ namespace Imperium\Model {
*
* @method find_or_fail
*
- * @param int $id The record id
+ * @param int $id The record id
*
* @return object
*
diff --git a/imperium/Query/Query.php b/imperium/Query/Query.php
index 66bcdd9..530c997 100644
--- a/imperium/Query/Query.php
+++ b/imperium/Query/Query.php
@@ -187,6 +187,16 @@ namespace Imperium\Query {
private $use_fetch = false;
/**
+ * @var string
+ */
+ private $and;
+
+ /**
+ * @var string
+ */
+ private $or;
+
+ /**
*
* The constructor
*
@@ -242,6 +252,8 @@ namespace Imperium\Query {
$join = def($this->join) ? $this->join : '';
$union = def($this->union) ? $this->union : '';
$mode = def($this->mode) ? $this->mode : '';
+ $or = def($this->or) ? $this->or : '';
+ $and = def($this->and) ? $this->and : '';
$columns = def($this->columns) ? $this->columns : "*";
@@ -250,14 +262,14 @@ namespace Imperium\Query {
switch($mode)
{
case Query::SELECT:
- return "SELECT $columns $table $where $order $limit";
+ return "SELECT $columns $table $where $and $or $order $limit";
break;
case Query::DELETE :
- return "DELETE $table $where";
+ return "DELETE $table $where $and $or";
break;
case Query::UNION:
case Query::UNION_ALL:
- return "$union $where $order $limit";
+ return "$union $where $and $or $order $limit";
break;
case collection(self::JOIN_MODE)->exist($mode) :
return "$join $order $limit";
@@ -367,13 +379,13 @@ namespace Imperium\Query {
* @method get
*
* @return mixed
- *
+ *
* @throws Exception
*
*/
public function get()
{
- return $this->use_fetch ? $this->connexion->fetch($this->sql()) : $this->connexion->request($this->sql());
+ return $this->use_fetch ? $this->connexion->fetch($this->sql()) : $this->connexion->request($this->sql());
}
/**
@@ -611,16 +623,20 @@ namespace Imperium\Query {
*
* Add on the where clause an and clause
*
- * @param string $value
+ * @param string $column
* @param string $condition
* @param string $expected
*
* @return Query
*
+ * @throws Exception
*/
- public function and(string $value, string $condition, string $expected): Query
+ public function and(string $column, string $condition, string $expected): Query
{
- append($this->where," AND $value $condition '$expected'");
+ if (is_string($expected))
+ $this->and = "AND $column $condition {$this->connexion->instance()->quote($expected)}";
+ else
+ $this->and = "AND $column $condition $expected";
return $this;
}
@@ -635,10 +651,15 @@ namespace Imperium\Query {
*
* @return Query
*
+ * @throws Exception
+ *
*/
public function or(string $value, string $condition, string $expected): Query
{
- append($this->where," OR $value $condition '$expected'");
+ if (is_string($expected))
+ $this->or = "OR $value $condition {$this->connexion->instance()->quote($expected)}";
+ else
+ $this->or = "OR $value $condition $expected";
return $this;
}
diff --git a/imperium/Users/Users.php b/imperium/Users/Users.php
index ce87650..7ab800b 100644
--- a/imperium/Users/Users.php
+++ b/imperium/Users/Users.php
@@ -221,7 +221,7 @@ namespace Imperium\Users {
$this->check($driver);
- return equal($driver,Connect::MYSQL) ? $this->connexion->execute("SET PASSWORD FOR '$user'@'localhost' = PASSWORD('$password');FLUSH PRIVILEGES") : $this->connexion->execute( "ALTER ROLE $user WITH PASSWORD '$password'");
+ return equal($driver,MYSQL) ? $this->connexion->execute("SET PASSWORD FOR '$user'@'localhost' = PASSWORD('$password');FLUSH PRIVILEGES;") : $this->connexion->execute( "ALTER ROLE $user WITH PASSWORD '$password'");
}
diff --git a/imperium/View/View.php b/imperium/View/View.php
index 651bf58..ea76655 100644
--- a/imperium/View/View.php
+++ b/imperium/View/View.php
@@ -209,7 +209,7 @@ namespace Imperium\View {
$functions->add(new TwigFunction('js',
- function (string $name,string $type = '')
+ function (string $name,string $type = 'js')
{
return js($name,$type);
}
@@ -311,6 +311,18 @@ namespace Imperium\View {
$this->add_functions($functions->collection());
+ $this->add_extensions(extensions('Extensions'));
+
+ $this->add_filters(extensions('Filters'));
+
+ $this->add_functions(extensions('Functions'));
+
+ $this->add_globals(extensions('Globals'));
+
+ $this->add_tags(extensions('Tags'));
+
+ $this->add_test(extensions('Tests'));
+
putenv("LC_ALL={$this->locale()}");
setlocale(LC_ALL, $this->locale());
@@ -511,7 +523,7 @@ namespace Imperium\View {
* @throws Exception
*
*/
- public function locale_path():string
+ public function locale_path(): string
{
$dir = dirname(core_path(collection(config('app','dir'))->get('app'))) . DIRECTORY_SEPARATOR . 'po';
@@ -519,5 +531,66 @@ namespace Imperium\View {
return realpath($dir);
}
+
+ /**
+ *
+ * Add twig filters
+ *
+ * @param array $filters
+ *
+ */
+ public function add_filters(array $filters): void
+ {
+ foreach ($filters as $filter)
+ $this->twig->addFilter($filter);
+
+ }
+
+ /**
+ *
+ * Add twig test
+ *
+ * @param array $tests
+ *
+ */
+ public function add_test(array $tests): void
+ {
+ foreach ($tests as $test)
+ $this->twig->addTest($test);
+ }
+
+ /**
+ *
+ * Add twig global
+ *
+ * @param array $globals
+ *
+ */
+ public function add_globals(array $globals): void
+ {
+ foreach ($globals as $k => $v)
+ $this->twig->addGlobal($k,$v);
+ }
+
+ /**
+ * Add twig extensions
+ *
+ * @param array $extensions
+ *
+ */
+ public function add_extensions(array $extensions): void
+ {
+ foreach ($extensions as $extension)
+ $this->twig->addExtension($extension);
+ }
+
+ /**
+ * @param array $extensions
+ */
+ public function add_tags(array $extensions): void
+ {
+ foreach ($extensions as $extension)
+ $this->twig->addTokenParser($extension);
+ }
}
} \ No newline at end of file
diff --git a/phinx.php b/phinx.php
index aa1a22d..79fd059 100644
--- a/phinx.php
+++ b/phinx.php
@@ -3,8 +3,8 @@
$file = 'db';
return [
"paths" => [
- "migrations" => "db/migrations",
- "seeds" => "db/seeds"
+ "migrations" => "azerty/migrations",
+ "seeds" => "azerty/seeds"
],
"environments" =>
[
diff --git a/tests/mysql/query/QueryTest.php b/tests/mysql/query/QueryTest.php
new file mode 100644
index 0000000..e022aaf
--- /dev/null
+++ b/tests/mysql/query/QueryTest.php
@@ -0,0 +1,135 @@
+<?php
+
+namespace Testing\mysql\query {
+
+
+ use Exception;
+ use Imperium\Query\Query;
+ use Symfony\Component\DependencyInjection\Tests\Compiler\E;
+ use Testing\DatabaseTest;
+
+
+ class QueryTest extends DatabaseTest
+ {
+
+
+ /**
+ * @var Query
+ */
+ private $query;
+ /**
+ * @var string
+ */
+ private $second_table;
+
+
+ public function setUp():void
+ {
+ $this->table = 'query';
+ $this->second_table = 'helpers';
+ $this->query = $this->mysql()->query()->from($this->table);
+
+ }
+
+
+ /**
+ * @throws \Exception
+ */
+ public function test_where()
+ {
+
+ $this->assertNotEmpty($this->query->mode(SELECT)->where('id','=',5)->only('date')->sql());
+
+
+ $b = '1988-07-15 00:00:00';
+ $e = '2010-07-30 00:00:00';
+
+ $this->assertNotEmpty($this->query->mode(Query::SELECT)->where('id','!=',1)->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::SELECT)->where('name','!=','will')->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::SELECT)->like('a')->get());
+
+
+ $this->assertNotEmpty($this->query->mode(Query::SELECT)->between('id',1,16)->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::SELECT)->only('id')->between('id',1,16)->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::SELECT)->only('id')->between('date',$b,$e)->get());
+
+
+ $this->assertStringNotContainsString("ORDER BY ",$this->query->mode(Query::DELETE)->where('id','=',16)->sql());
+
+
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function test_union()
+ {
+
+
+ $limit = 10;
+
+ $columns = 'id, name';
+
+ $this->assertNotEmpty($this->query->mode(Query::UNION)->union($this->table,$this->second_table,'','')->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::UNION_ALL)->union($this->table,$this->second_table,'','')->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::UNION)->union($this->table,$this->second_table,$columns, $columns)->limit($limit,0)->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::UNION_ALL)->union($this->table,$this->second_table,$columns,$columns)->limit($limit,0)->get());
+
+
+
+ $this->assertNotEmpty($this->query->mode(Query::UNION)->union($this->table,$this->second_table,'','')->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::UNION_ALL)->union($this->table,$this->second_table,'','')->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::UNION)->union($this->table,$this->second_table,'','')->limit($limit,0)->get());
+
+ $this->assertNotEmpty($this->query->mode(Query::UNION_ALL)->union($this->table,$this->second_table,'','')->limit($limit,0)->get());
+
+
+ $this->assertCount($limit,$this->query->mode(Query::UNION)->union($this->table,$this->second_table,'','')->limit($limit,0)->get());
+
+ $this->assertCount($limit,$this->query->mode(Query::UNION_ALL)->union($this->table,$this->second_table,'','')->limit($limit,0)->get());
+
+
+ }
+
+ public function test_join()
+ {
+ $this->assertNotEmpty($this->query->mode(INNER_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id')->get());
+ $this->assertNotEmpty($this->query->mode(INNER_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id','id')->get());
+
+ $this->assertNotEmpty($this->query->mode(CROSS_JOIN)->join(DIFFERENT,$this->table,$this->second_table,'id','id','id')->get());
+
+ $this->assertNotEmpty($this->query->mode(CROSS_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id')->get());
+ $this->assertNotEmpty($this->query->mode(CROSS_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id','id')->get());
+
+ $this->assertNotEmpty($this->query->mode(LEFT_JOIN)->join(DIFFERENT,$this->table,$this->second_table,'id','id')->get());
+ $this->assertNotEmpty($this->query->mode(LEFT_JOIN)->join(DIFFERENT,$this->table,$this->second_table,'id','id','id')->get());
+
+ $this->assertNotEmpty($this->query->mode(LEFT_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id')->get());
+ $this->assertNotEmpty($this->query->mode(LEFT_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id','id')->get());
+
+
+ $this->assertNotEmpty($this->query->mode(RIGHT_JOIN)->join(DIFFERENT,$this->table,$this->second_table,'id','id')->get());
+ $this->assertNotEmpty($this->query->mode(RIGHT_JOIN)->join(DIFFERENT,$this->table,$this->second_table,'id','id','id')->get());
+
+
+ $this->assertNotEmpty($this->query->mode(RIGHT_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id')->get());
+ $this->assertNotEmpty($this->query->mode(RIGHT_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id','id')->get());
+
+ $this->assertNotEmpty($this->query->mode(INNER_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id')->get());
+ $this->assertNotEmpty($this->query->mode(INNER_JOIN)->join(EQUAL,$this->table,$this->second_table,'id','id','id')->get());
+
+
+ }
+
+
+ }
+}