aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-10-21 15:40:57 +0200
committerWilly Micieli <micieli@laposte.net>2019-10-21 15:42:03 +0200
commitb06775bc8bd6021dd4d9db4657d96a3b4b181a36 (patch)
tree49d4512066fc7eef8ac69987989c25597217389c
parente4a96961679d95e9adeac4f19996177b7f7e4f28 (diff)
downloadimperium-b06775bc8bd6021dd4d9db4657d96a3b4b181a36.zip
imperium-b06775bc8bd6021dd4d9db4657d96a3b4b181a36.tar.gz
refactor source code
-rw-r--r--helpers/web.php15
-rw-r--r--imperium/Model/Admin.php18
-rw-r--r--imperium/Model/Model.php386
-rw-r--r--imperium/Model/Web.php23
4 files changed, 240 insertions, 202 deletions
diff --git a/helpers/web.php b/helpers/web.php
index 33be7bf..5197fb5 100644
--- a/helpers/web.php
+++ b/helpers/web.php
@@ -185,13 +185,14 @@
if (!function_exists('env'))
{
- /**
- *
- * @param $variable
- *
- * @return array|false|string
- *
- */
+ /**
+ *
+ * @param $variable
+ *
+ * @return array|false|string
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
function env($variable)
{
diff --git a/imperium/Model/Admin.php b/imperium/Model/Admin.php
index 84fac28..49ed828 100644
--- a/imperium/Model/Admin.php
+++ b/imperium/Model/Admin.php
@@ -2,7 +2,9 @@
namespace Imperium\Model;
- use Imperium\Exception\Kedavra;
+ use DI\DependencyException;
+ use DI\NotFoundException;
+ use Imperium\Exception\Kedavra;
class Admin extends Model
{
@@ -11,13 +13,13 @@
protected $admin = true;
- /**
- *
- * @throws Kedavra
- *
- * @return bool
- *
- */
+ /**
+ *
+ * @return bool
+ * @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
public static function generate(): bool
{
return static::query()->connexion()->execute(static::$create_route_table_query);
diff --git a/imperium/Model/Model.php b/imperium/Model/Model.php
index e56c2a0..d0ffb1e 100644
--- a/imperium/Model/Model.php
+++ b/imperium/Model/Model.php
@@ -79,50 +79,54 @@
* @var bool
*/
protected $admin = false;
-
- /**
- *
- * Display all columns
- *
- * @throws Kedavra
- *
- * @return array
- *
- */
+
+ /**
+ *
+ * Display all columns
+ *
+ * @return array
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function columns() : array
{
-
return static::query()->columns();
}
-
-
- /**
- * @param int $begin
- * @param int $end
- * @param string $column
- *
- * @return Query
- *
- */
+
+
+ /**
+ * @param int $begin
+ * @param int $end
+ * @param string $column
+ *
+ * @return Query
+ *
+ * @throws DependencyException
+ * @throws NotFoundException
+ *
+ */
public static function between(int $begin, int $end, string $column = '') : Query
{
-
$column = def($column) ? $column : self::key();
return static::query()->between($column, $begin, $end);
}
-
- /**
- * Undocumented function
- *
- * @throws Kedavra
- *
- * @return array
- *
- */
+
+ /**
+ * Undocumented function
+ *
+ * @return array
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function all() : array
{
-
return static::query()->all();
}
@@ -131,44 +135,44 @@
*/
public static function key() : string
{
-
return static::$by;
}
-
- /**
- *
- * Display the primary key
- *
- * @throws Kedavra
- *
- * @return string
- *
- */
+
+ /**
+ *
+ * Display the primary key
+ *
+ * @return string
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function primary() : string
{
-
return static::query()->primary_key();
}
-
- /**
- *
- * @param mixed $expected
- *
- * @throws Kedavra
- *
- * @return object
- *
- */
+
+ /**
+ *
+ * @param mixed $expected
+ *
+ * @return object
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function get($expected) : object
{
-
is_true(not_def($expected), true, "Missing the expected value");
return self::by(self::key(), $expected);
}
-
/**
*
* Seed current table
@@ -177,7 +181,9 @@
*
* @return bool
*
+ * @throws DependencyException
* @throws Kedavra
+ * @throws NotFoundException
*
*/
public static function seed(int $records): bool
@@ -271,6 +277,7 @@
return static::query()->connexion()->execute($query);
}
+
/**
*
* Get all available types for current driver
@@ -279,6 +286,9 @@
*
* @return array
*
+ * @throws DependencyException
+ * @throws NotFoundException
+ *
*/
public static function types() : array
{
@@ -300,15 +310,15 @@
}
/**
- *
- * @param string $column
- * @param mixed $expected
- *
- * @throws Kedavra
- *
- * @return object
- *
- */
+ *
+ * @param string $column
+ * @param mixed $expected
+ *
+ * @return object
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
public static function by(string $column, $expected) : object
{
@@ -321,46 +331,54 @@
*
* Get only column values
*
- * @param string[] $columns
+ * @param string ...$columns
+ *
* @return array
+ *
+ * @throws DependencyException
* @throws Kedavra
+ * @throws NotFoundException
+ *
*/
public static function only(string ...$columns) : array
{
return static::query()->select($columns)->all();
}
- /**
- *
- *
- * @param string $x
- *
- * @throws Kedavra
- *
- * @return mixed
- *
- */
+ /**
+ *
+ * Search a value
+ *
+ * @param string $x
+ *
+ * @return mixed
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function search(string $x)
{
-
return static::query()->like($x)->all();
}
-
- /**
- *
- *
- * Add a new record
- *
- * @param array $values
- *
- * @throws Kedavra
- *
- * @return bool
- *
- */
+
+ /**
+ *
+ *
+ * Add a new record
+ *
+ * @param array $values
+ *
+ * @return bool
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function create(array $values) : bool
{
-
$x = collect(static::query()->columns())->join(',');
$values = collect($values)->for('htmlentities')->all();
@@ -390,7 +408,9 @@
*
* @return bool
*
+ * @throws DependencyException
* @throws Kedavra
+ * @throws NotFoundException
*
*/
public static function update(int $id,array $values): bool
@@ -414,103 +434,113 @@
return static::query()->connexion()->execute($command);
}
- /**
- *
- * Display all records with a pagination
- *
- * @param callable $callable
- * @param int $current_page
- *
- * @throws Kedavra
- *
- * @return string
- *
- */
+
+ /**
+ *
+ * Display all records with a pagination
+ *
+ * @param callable $callable
+ * @param int $current_page
+ *
+ * @return string
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function paginate($callable, int $current_page) : string
{
-
return static::query()->paginate($callable, $current_page, static::$limit);
}
-
- /**
- *
- * Destroy a record by id
- *
- * @param int $id
- *
- * @throws Kedavra
- *
- * @return bool
- *
- */
+
+ /**
+ *
+ * Destroy a record by id
+ *
+ * @param int $id
+ *
+ * @return bool
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function destroy(int $id) : bool
{
-
return static::query()->destroy($id);
}
-
- /**
- *
- * Count record in a table
- *
- * @throws Kedavra
- *
- * @return int
- *
- */
+
+ /**
+ *
+ * Count record in a table
+ *
+ * @return int
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function count() : int
{
-
return static::query()->sum();
}
-
- /**
- *
- * Generate a clause where
- *
- * @param string $column
- * @param string $condition
- * @param mixed $expected
- *
- * @throws Kedavra
- * @return Query
- *
- */
+
+ /**
+ *
+ * Generate a clause where
+ *
+ * @param string $column
+ * @param string $condition
+ * @param mixed $expected
+ *
+ * @return Query
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function where(string $column, string $condition, $expected) : Query
{
-
return static::query()->mode(SELECT)->where($column, $condition, $expected);
}
-
- /**
- *
- * Find a record by an id
- *
- * @param int $id
- *
- * @throws Kedavra
- *
- * @return object
- *
- */
+
+ /**
+ *
+ * Find a record by an id
+ *
+ * @param int $id
+ *
+ * @return object
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function find(int $id)
{
-
return static::query()->find($id);
}
-
- /**
- *
- * Use a different where clause
- *
- * @param string $column
- * @param mixed $expected
- *
- * @throws Kedavra
- *
- * @return Query
- *
- */
+
+ /**
+ *
+ * Use a different where clause
+ *
+ * @param mixed $expected
+ *
+ * @param string $column
+ *
+ * @return Query
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
public static function different($expected, string $column = '') : Query
{
@@ -518,15 +548,19 @@
return self::where($column, DIFFERENT, $expected);
}
-
- /**
- * Begin querying the model.
- *
- * @return Query
- */
+
+ /**
+ *
+ * Begin querying the model.
+ *
+ * @return Query
+ *
+ * @throws DependencyException
+ * @throws NotFoundException
+ *
+ */
public static function query() : Query
{
-
return (new static)->builder();
}
@@ -534,12 +568,12 @@
*
* @throws DependencyException
* @throws NotFoundException
+ *
* @return Query
*
*/
private function builder() : Query
{
-
return Query::from($this->table, $this->routes,$this->admin)->primary($this->primary);
}
diff --git a/imperium/Model/Web.php b/imperium/Model/Web.php
index b30842a..7a2f07e 100644
--- a/imperium/Model/Web.php
+++ b/imperium/Model/Web.php
@@ -2,23 +2,24 @@
namespace Imperium\Model;
- use Imperium\Exception\Kedavra;
- use Imperium\File\File;
-
+ use DI\DependencyException;
+ use DI\NotFoundException;
+ use Imperium\Exception\Kedavra;
+
class Web extends Model
{
protected $table = "routes";
protected $routes = true;
-
- /**
- *
- * @throws Kedavra
- *
- * @return bool
- *
- */
+
+ /**
+ *
+ * @return bool
+ * @throws Kedavra
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
public static function generate(): bool
{
return static::query()->connexion()->execute(static::$create_route_table_query);