@@ -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 | } |
@@ -1,8 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Lepton\Helpers; |
| 3 | 3 | |
| 4 | -class Functions{ |
|
| 5 | -static function getDeclarationLine(\ReflectionProperty $prop){ |
|
| 4 | +class Functions { |
|
| 5 | +static function getDeclarationLine(\ReflectionProperty $prop) { |
|
| 6 | 6 | $declaringClass = $prop->getDeclaringClass(); |
| 7 | 7 | $propname = $prop->getName(); |
| 8 | 8 | $classFile = new \SplFileObject($declaringClass->getFileName()); |
@@ -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,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 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | class UrlResolver |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - public function __construct(private $pattern){} |
|
| 14 | + public function __construct(private $pattern) {} |
|
| 15 | 15 | |
| 16 | 16 | public function patternPrepare($pattern) |
| 17 | 17 | { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $is_match = preg_match(sprintf("/^%s$/", $pattern), $_SERVER['REQUEST_URI'], $parameters); |
| 52 | 52 | |
| 53 | 53 | // keep only string keys |
| 54 | - $parameters = array_filter($parameters, function ($k) { |
|
| 54 | + $parameters = array_filter($parameters, function($k) { |
|
| 55 | 55 | return is_string($k); |
| 56 | 56 | }, ARRAY_FILTER_USE_KEY); |
| 57 | 57 | return $is_match; |
@@ -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 |
@@ -11,29 +11,29 @@ discard block |
||
| 11 | 11 | public function __construct($dbhost = 'localhost', $dbuser = 'root', $dbpass = '', $dbname = '', $charset = 'utf8') { |
| 12 | 12 | $this->connection = new \mysqli($dbhost, $dbuser, $dbpass, $dbname); |
| 13 | 13 | if ($this->connection->connect_error) { |
| 14 | - $this->error('Failed to connect to MySQL - ' . $this->connection->connect_error); |
|
| 14 | + $this->error('Failed to connect to MySQL - '.$this->connection->connect_error); |
|
| 15 | 15 | } |
| 16 | 16 | $this->connection->set_charset($charset); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function query($query, &...$args) { |
| 20 | - if(!$this->query_closed){ |
|
| 20 | + if (!$this->query_closed) { |
|
| 21 | 21 | $this->query_closed = TRUE; |
| 22 | 22 | $this->query->close(); |
| 23 | 23 | } |
| 24 | 24 | if ($this->query = $this->connection->prepare($query)) { |
| 25 | - if(count($args)){ |
|
| 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 | 30 | $this->query->execute(); |
| 31 | 31 | if ($this->query->errno) { |
| 32 | - $this->error('Unable to process MySQL query (check your params) - ' . $this->query->error); |
|
| 32 | + $this->error('Unable to process MySQL query (check your params) - '.$this->query->error); |
|
| 33 | 33 | } |
| 34 | 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 | 37 | } |
| 38 | 38 | return $this; |
| 39 | 39 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $r[$key] = $val; |
| 56 | 56 | } |
| 57 | 57 | if ($callback != null && is_callable($callback)) { |
| 58 | - $value = $callback($r);//call_user_func($callback, $r); |
|
| 58 | + $value = $callback($r); //call_user_func($callback, $r); |
|
| 59 | 59 | if ($value == 'break') break; |
| 60 | 60 | } else { |
| 61 | 61 | $result[] = $r; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | return $result; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - public function fetch_result(){ |
|
| 85 | + public function fetch_result() { |
|
| 86 | 86 | return $this->query->get_result(); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function query($query, &...$args) { |
| 20 | - if(!$this->query_closed){ |
|
| 20 | + if(!$this->query_closed) { |
|
| 21 | 21 | $this->query_closed = TRUE; |
| 22 | 22 | $this->query->close(); |
| 23 | 23 | } |
| 24 | 24 | if ($this->query = $this->connection->prepare($query)) { |
| 25 | - if(count($args)){ |
|
| 25 | + if(count($args)) { |
|
| 26 | 26 | $types = implode(array_map(array($this, '_gettype'), $args)); |
| 27 | 27 | $this->query->bind_param($types, ...$args); |
| 28 | 28 | } |
@@ -56,7 +56,9 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | if ($callback != null && is_callable($callback)) { |
| 58 | 58 | $value = $callback($r);//call_user_func($callback, $r); |
| 59 | - if ($value == 'break') break; |
|
| 59 | + if ($value == 'break') { |
|
| 60 | + break; |
|
| 61 | + } |
|
| 60 | 62 | } else { |
| 61 | 63 | $result[] = $r; |
| 62 | 64 | } |
@@ -113,9 +115,15 @@ discard block |
||
| 113 | 115 | } |
| 114 | 116 | |
| 115 | 117 | 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'; |
|
| 118 | + if (is_string($var)) { |
|
| 119 | + return 's'; |
|
| 120 | + } |
|
| 121 | + if (is_float($var)) { |
|
| 122 | + return 'd'; |
|
| 123 | + } |
|
| 124 | + if (is_int($var)) { |
|
| 125 | + return 'i'; |
|
| 126 | + } |
|
| 119 | 127 | return 'b'; |
| 120 | 128 | } |
| 121 | 129 | |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | $this->mailer->addReplyTo($config->replyTo, $config->replyToName); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function send($to, $subject, $body, $attachments=array()) |
|
| 31 | + public function send($to, $subject, $body, $attachments = array()) |
|
| 32 | 32 | { |
| 33 | 33 | $this->mailer->addAddress($to); |
| 34 | 34 | $this->mailer->Subject = $subject; |
@@ -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 | |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | protected Request $request; |
| 15 | 15 | protected $middlewares = array(); |
| 16 | 16 | |
| 17 | - public function __construct($request){ |
|
| 17 | + public function __construct($request) { |
|
| 18 | 18 | $this->request = $request; |
| 19 | 19 | } |
| 20 | 20 | |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | * Returns the appropriate handler for the pending request |
| 62 | 62 | * |
| 63 | 63 | * @return AbstractHandler $handler |
| 64 | - */ |
|
| 64 | + */ |
|
| 65 | 65 | public static function getHandler(): AbstractHandler |
| 66 | 66 | { |
| 67 | 67 | $regex = '/\.(?:'.implode('|', static::$_config->static_files_extensions).')$/'; |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public static function run() |
| 31 | 31 | { |
| 32 | - if(! static::$_config) { |
|
| 32 | + if (!static::$_config) { |
|
| 33 | 33 | throw new \Exception("No config loaded!"); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | session_start(); |
| 37 | 37 | |
| 38 | - if(static::$_dbconfig->use_db) { |
|
| 38 | + if (static::$_dbconfig->use_db) { |
|
| 39 | 39 | static::$_db = new Database( |
| 40 | 40 | static::$_dbconfig->host, |
| 41 | 41 | static::$_dbconfig->user, |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $response = $handler->getResponse(); |
| 50 | 50 | $response->send(); |
| 51 | 51 | |
| 52 | - if(static::$_dbconfig->use_db) { |
|
| 52 | + if (static::$_dbconfig->use_db) { |
|
| 53 | 53 | static::$_db->close(); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -82,33 +82,33 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | public static function loadConfig(\stdClass $config) |
| 84 | 84 | { |
| 85 | - if(property_exists($config, "app")) { |
|
| 85 | + if (property_exists($config, "app")) { |
|
| 86 | 86 | static::$_config = $config->app; |
| 87 | 87 | } else { |
| 88 | 88 | throw new \Exception("No app configuration!"); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if(property_exists($config, "routes")) { |
|
| 91 | + if (property_exists($config, "routes")) { |
|
| 92 | 92 | static::$routes = $config->routes; |
| 93 | 93 | } else { |
| 94 | 94 | throw new \Exception("No routes configuration!"); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
| 98 | - if(property_exists($config, "database")) { |
|
| 98 | + if (property_exists($config, "database")) { |
|
| 99 | 99 | static::$_dbconfig = $config->database; |
| 100 | 100 | } else { |
| 101 | 101 | throw new \Exception("No database configuration!"); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
| 105 | - if(property_exists($config, "auth")) { |
|
| 105 | + if (property_exists($config, "auth")) { |
|
| 106 | 106 | static::$_auth = $config->auth; |
| 107 | 107 | } else { |
| 108 | 108 | throw new \Exception("No authentication configuration!"); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if(property_exists($config, "email")) { |
|
| 111 | + if (property_exists($config, "email")) { |
|
| 112 | 112 | static::$_email = $config->email; |
| 113 | 113 | } else { |
| 114 | 114 | throw new \Exception("No email configuration!"); |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Lepton\Http\Response; |
| 4 | 4 | |
| 5 | - class SuccessResponse extends HttpResponse |
|
| 5 | + class SuccessResponse extends HttpResponse |
|
| 6 | 6 | { |
| 7 | 7 | |
| 8 | 8 | public function __construct( |