@@ -3,12 +3,12 @@ |
||
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | 5 | class PrimaryKey extends Field{ |
| 6 | - public function __construct(private int $max_length = 32, mixed ...$options){ |
|
| 6 | + public function __construct(private int $max_length = 32, mixed ...$options){ |
|
| 7 | 7 | parent::__construct(...$options); |
| 8 | - } |
|
| 8 | + } |
|
| 9 | 9 | |
| 10 | - public function validate($value){ |
|
| 10 | + public function validate($value){ |
|
| 11 | 11 | if(is_null($value) && (!$this->null)) return false; |
| 12 | 12 | return true; |
| 13 | - } |
|
| 13 | + } |
|
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -3,12 +3,12 @@ |
||
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | 5 | class NumberField extends Field{ |
| 6 | - public function __construct(private int $max_length = 32, mixed ...$options){ |
|
| 6 | + public function __construct(private int $max_length = 32, mixed ...$options){ |
|
| 7 | 7 | parent::__construct(...$options); |
| 8 | - } |
|
| 8 | + } |
|
| 9 | 9 | |
| 10 | - public function validate($value){ |
|
| 10 | + public function validate($value){ |
|
| 11 | 11 | if(is_null($value) && (!$this->null)) return false; |
| 12 | 12 | return true; |
| 13 | - } |
|
| 13 | + } |
|
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -5,18 +5,18 @@ |
||
| 5 | 5 | class TextField extends Field{ |
| 6 | 6 | |
| 7 | 7 | |
| 8 | - private $max_length; |
|
| 9 | - private $nullable; |
|
| 8 | + private $max_length; |
|
| 9 | + private $nullable; |
|
| 10 | 10 | |
| 11 | - public function __construct($max_length = 128, $nullable = false ){ |
|
| 11 | + public function __construct($max_length = 128, $nullable = false ){ |
|
| 12 | 12 | $this->max_length = $max_length; |
| 13 | 13 | $this->nullable = $nullable; |
| 14 | - } |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function validate($value){ |
|
| 16 | + public function validate($value){ |
|
| 17 | 17 | return true; |
| 18 | 18 | if(is_null($value) && (!$this->nullable)) return false; |
| 19 | 19 | if(strlen($value) > $this->max_length) return false; |
| 20 | 20 | return true; |
| 21 | - } |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |
@@ -3,11 +3,11 @@ |
||
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | 5 | class DateTimeField extends Field{ |
| 6 | - public function __construct(...$args){ |
|
| 6 | + public function __construct(...$args){ |
|
| 7 | 7 | parent::__construct(...$args); |
| 8 | - } |
|
| 8 | + } |
|
| 9 | 9 | |
| 10 | - public function validate($value){ |
|
| 10 | + public function validate($value){ |
|
| 11 | 11 | return true; |
| 12 | - } |
|
| 12 | + } |
|
| 13 | 13 | } |
| 14 | 14 | \ No newline at end of file |
@@ -3,21 +3,21 @@ |
||
| 3 | 3 | |
| 4 | 4 | class Functions{ |
| 5 | 5 | static function getDeclarationLine(\ReflectionProperty $prop){ |
| 6 | - $declaringClass = $prop->getDeclaringClass(); |
|
| 7 | - $propname = $prop->getName(); |
|
| 8 | - $classFile = new \SplFileObject($declaringClass->getFileName()); |
|
| 9 | - foreach ($classFile as $line => $content) { |
|
| 10 | - if (preg_match( |
|
| 11 | - '/ |
|
| 6 | + $declaringClass = $prop->getDeclaringClass(); |
|
| 7 | + $propname = $prop->getName(); |
|
| 8 | + $classFile = new \SplFileObject($declaringClass->getFileName()); |
|
| 9 | + foreach ($classFile as $line => $content) { |
|
| 10 | + if (preg_match( |
|
| 11 | + '/ |
|
| 12 | 12 | (private|protected|public|var|static) # match visibility or var |
| 13 | 13 | \s # followed 1 whitespace |
| 14 | 14 | \$'.$propname.' # followed by the var name $bar |
| 15 | 15 | /x', |
| 16 | - $content) |
|
| 17 | - ) { |
|
| 18 | - return $line + 1; |
|
| 19 | - } |
|
| 20 | - } |
|
| 21 | - return 1; |
|
| 16 | + $content) |
|
| 17 | + ) { |
|
| 18 | + return $line + 1; |
|
| 19 | + } |
|
| 20 | + } |
|
| 21 | + return 1; |
|
| 22 | 22 | } |
| 23 | 23 | } |
@@ -5,6 +5,6 @@ |
||
| 5 | 5 | |
| 6 | 6 | class MatchRoute extends BaseMatch |
| 7 | 7 | { |
| 8 | - public function __construct(public $controller, public $method, public $parameters){} |
|
| 8 | + public function __construct(public $controller, public $method, public $parameters){} |
|
| 9 | 9 | |
| 10 | 10 | } |
@@ -5,9 +5,9 @@ |
||
| 5 | 5 | |
| 6 | 6 | class MatchFile extends BaseMatch |
| 7 | 7 | { |
| 8 | - public function __construct(public $filePath, public $contentType) |
|
| 9 | - { |
|
| 8 | + public function __construct(public $filePath, public $contentType) |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | 13 | } |
@@ -3,43 +3,43 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class Database { |
| 5 | 5 | |
| 6 | - protected $connection; |
|
| 7 | - protected $query; |
|
| 8 | - protected $show_errors = TRUE; |
|
| 9 | - protected $query_closed = TRUE; |
|
| 10 | - |
|
| 11 | - public function __construct($dbhost = 'localhost', $dbuser = 'root', $dbpass = '', $dbname = '', $charset = 'utf8') { |
|
| 12 | - $this->connection = new \mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
| 13 | - if ($this->connection->connect_error) { |
|
| 14 | - $this->error('Failed to connect to MySQL - ' . $this->connection->connect_error); |
|
| 15 | - } |
|
| 16 | - $this->connection->set_charset($charset); |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - public function query($query, &...$args) { |
|
| 6 | + protected $connection; |
|
| 7 | + protected $query; |
|
| 8 | + protected $show_errors = TRUE; |
|
| 9 | + protected $query_closed = TRUE; |
|
| 10 | + |
|
| 11 | + public function __construct($dbhost = 'localhost', $dbuser = 'root', $dbpass = '', $dbname = '', $charset = 'utf8') { |
|
| 12 | + $this->connection = new \mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
| 13 | + if ($this->connection->connect_error) { |
|
| 14 | + $this->error('Failed to connect to MySQL - ' . $this->connection->connect_error); |
|
| 15 | + } |
|
| 16 | + $this->connection->set_charset($charset); |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + public function query($query, &...$args) { |
|
| 20 | 20 | if(!$this->query_closed){ |
| 21 | - $this->query_closed = TRUE; |
|
| 22 | - $this->query->close(); |
|
| 21 | + $this->query_closed = TRUE; |
|
| 22 | + $this->query->close(); |
|
| 23 | 23 | } |
| 24 | - if ($this->query = $this->connection->prepare($query)) { |
|
| 25 | - if(count($args)){ |
|
| 24 | + if ($this->query = $this->connection->prepare($query)) { |
|
| 25 | + if(count($args)){ |
|
| 26 | 26 | $types = implode(array_map(array($this, '_gettype'), $args)); |
| 27 | 27 | $this->query->bind_param($types, ...$args); |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - $this->query->execute(); |
|
| 31 | - if ($this->query->errno) { |
|
| 30 | + $this->query->execute(); |
|
| 31 | + if ($this->query->errno) { |
|
| 32 | 32 | $this->error('Unable to process MySQL query (check your params) - ' . $this->query->error); |
| 33 | - } |
|
| 34 | - $this->query_closed = FALSE; |
|
| 33 | + } |
|
| 34 | + $this->query_closed = FALSE; |
|
| 35 | 35 | } else { |
| 36 | - $this->error('Unable to prepare MySQL statement (check your syntax) - ' . $this->connection->error); |
|
| 36 | + $this->error('Unable to prepare MySQL statement (check your syntax) - ' . $this->connection->error); |
|
| 37 | + } |
|
| 38 | + return $this; |
|
| 37 | 39 | } |
| 38 | - return $this; |
|
| 39 | - } |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - public function fetch_all($callback = null) { |
|
| 42 | + public function fetch_all($callback = null) { |
|
| 43 | 43 | $params = array(); |
| 44 | 44 | $row = array(); |
| 45 | 45 | $meta = $this->query->result_metadata(); |
@@ -50,74 +50,74 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | $result = array(); |
| 52 | 52 | while ($this->query->fetch()) { |
| 53 | - $r = array(); |
|
| 54 | - foreach ($row as $key => $val) { |
|
| 53 | + $r = array(); |
|
| 54 | + foreach ($row as $key => $val) { |
|
| 55 | 55 | $r[$key] = $val; |
| 56 | - } |
|
| 57 | - if ($callback != null && is_callable($callback)) { |
|
| 56 | + } |
|
| 57 | + if ($callback != null && is_callable($callback)) { |
|
| 58 | 58 | $value = $callback($r);//call_user_func($callback, $r); |
| 59 | 59 | if ($value == 'break') break; |
| 60 | - } else { |
|
| 60 | + } else { |
|
| 61 | 61 | $result[] = $r; |
| 62 | - } |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | $this->query_closed = TRUE; |
| 65 | 65 | return $result; |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function fetch_array() { |
|
| 68 | + public function fetch_array() { |
|
| 69 | 69 | $params = array(); |
| 70 | 70 | $row = array(); |
| 71 | 71 | $meta = $this->query->result_metadata(); |
| 72 | 72 | while ($field = $meta->fetch_field()) { |
| 73 | - $params[] = &$row[$field->name]; |
|
| 73 | + $params[] = &$row[$field->name]; |
|
| 74 | 74 | } |
| 75 | 75 | $this->query->bind_result(...$params); |
| 76 | 76 | $result = array(); |
| 77 | - while ($this->query->fetch()) { |
|
| 78 | - foreach ($row as $key => $val) { |
|
| 79 | - $result[$key] = $val; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - return $result; |
|
| 83 | - } |
|
| 77 | + while ($this->query->fetch()) { |
|
| 78 | + foreach ($row as $key => $val) { |
|
| 79 | + $result[$key] = $val; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + return $result; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public function fetch_result(){ |
|
| 86 | - return $this->query->get_result(); |
|
| 87 | - } |
|
| 85 | + public function fetch_result(){ |
|
| 86 | + return $this->query->get_result(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - public function close() { |
|
| 93 | - return $this->connection->close(); |
|
| 94 | - } |
|
| 92 | + public function close() { |
|
| 93 | + return $this->connection->close(); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function num_rows() { |
|
| 97 | - $this->query->store_result(); |
|
| 98 | - return $this->query->num_rows; |
|
| 99 | - } |
|
| 96 | + public function num_rows() { |
|
| 97 | + $this->query->store_result(); |
|
| 98 | + return $this->query->num_rows; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - public function affected_rows() { |
|
| 102 | - return $this->query->affected_rows; |
|
| 103 | - } |
|
| 101 | + public function affected_rows() { |
|
| 102 | + return $this->query->affected_rows; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - public function last_insert_id() { |
|
| 105 | + public function last_insert_id() { |
|
| 106 | 106 | return $this->connection->insert_id; |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - public function error($error) { |
|
| 109 | + public function error($error) { |
|
| 110 | 110 | if ($this->show_errors) { |
| 111 | 111 | die($error); |
| 112 | 112 | } |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - private function _gettype($var) { |
|
| 116 | - if (is_string($var)) return 's'; |
|
| 117 | - if (is_float($var)) return 'd'; |
|
| 118 | - if (is_int($var)) return 'i'; |
|
| 119 | - return 'b'; |
|
| 120 | - } |
|
| 115 | + private function _gettype($var) { |
|
| 116 | + if (is_string($var)) return 's'; |
|
| 117 | + if (is_float($var)) return 'd'; |
|
| 118 | + if (is_int($var)) return 'i'; |
|
| 119 | + return 'b'; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | ?> |
| 124 | 124 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | protected $middlewares = array(); |
| 16 | 16 | |
| 17 | 17 | public function __construct($request){ |
| 18 | - $this->request = $request; |
|
| 18 | + $this->request = $request; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function addMiddlewares($middlewares) { |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | public function getResponse() : HttpResponse{ |
| 27 | - $matcher = $this->resolveRequest(); |
|
| 28 | - return $this->handle($matcher); |
|
| 27 | + $matcher = $this->resolveRequest(); |
|
| 28 | + return $this->handle($matcher); |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |