From 42f6bb3c6ca38cf6ad2d3624c7e87337509584b3 Mon Sep 17 00:00:00 2001 From: Matias Ibargoyen Date: Thu, 11 Nov 2021 12:23:39 +0000 Subject: [PATCH 1/9] :rotating_light: removes unnecessary closing tags --- src/Exceptions/ViewException.php | 2 +- src/Http/MiddlewareCollection.php | 2 +- src/Http/Request.php | 2 +- src/Http/Response.php | 2 +- src/Http/Routing/Dispatcher.php | 2 +- src/Http/Routing/Helpers.php | 2 +- src/Http/Routing/Route.php | 2 +- src/Http/Routing/RouteCore.php | 2 +- src/Kernel/Application.php | 2 +- src/Kernel/Lemonade/Builders/builder.php | 2 +- src/Kernel/Lemonade/Builders/licenses.php | 2 +- src/Kernel/Lemonade/Builders/templates.php | 2 +- src/Kernel/Lemonade/Helpers/commands.php | 2 +- src/Kernel/Lemonade/Helpers/helpers.php | 2 +- src/Kernel/Lemonade/Helpers/info.php | 2 +- src/Kernel/Lemonade/Kernel.php | 2 +- src/Kernel/Lemonade/Repl/repl.php | 2 +- src/Kernel/Lemonade/Server/server.php | 2 +- src/Kernel/loader.php | 2 +- src/Sessions/Csrf.php | 2 +- src/Sessions/Session.php | 2 +- src/Utils/Env.php | 2 +- src/Utils/constants.php | 2 +- src/Utils/http.php | 2 +- src/Utils/page.php | 2 +- src/Utils/utils.php | 2 +- src/Views/Tag.php | 2 +- src/Views/View.php | 2 +- src/Views/ViewCompiler.php | 2 +- src/Views/views.php | 2 +- 30 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Exceptions/ViewException.php b/src/Exceptions/ViewException.php index 5bb714d9..ec17ce2b 100644 --- a/src/Exceptions/ViewException.php +++ b/src/Exceptions/ViewException.php @@ -4,4 +4,4 @@ class ViewException extends \Exception {} -?> + diff --git a/src/Http/MiddlewareCollection.php b/src/Http/MiddlewareCollection.php index 79de91ea..f8e251e3 100644 --- a/src/Http/MiddlewareCollection.php +++ b/src/Http/MiddlewareCollection.php @@ -70,4 +70,4 @@ public function terminate(Request $request) } } -?> + diff --git a/src/Http/Request.php b/src/Http/Request.php index f22d3907..ffcc4930 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -109,4 +109,4 @@ function header($name) } -?> + diff --git a/src/Http/Response.php b/src/Http/Response.php index ffea207c..13c622ba 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -181,4 +181,4 @@ static function handle(int $code, $action) } -?> + diff --git a/src/Http/Routing/Dispatcher.php b/src/Http/Routing/Dispatcher.php index 81a46673..cdf39acc 100644 --- a/src/Http/Routing/Dispatcher.php +++ b/src/Http/Routing/Dispatcher.php @@ -109,4 +109,4 @@ public function run() } } -?> + diff --git a/src/Http/Routing/Helpers.php b/src/Http/Routing/Helpers.php index 1303b10c..40145082 100644 --- a/src/Http/Routing/Helpers.php +++ b/src/Http/Routing/Helpers.php @@ -28,4 +28,4 @@ function getParamTypes($callback) } -?> + diff --git a/src/Http/Routing/Route.php b/src/Http/Routing/Route.php index 56cd4a43..b428c9bd 100644 --- a/src/Http/Routing/Route.php +++ b/src/Http/Routing/Route.php @@ -120,4 +120,4 @@ public function toResponse(Request $request, Array $params) } } -?> + diff --git a/src/Http/Routing/RouteCore.php b/src/Http/Routing/RouteCore.php index 7e49c38a..f2f26b63 100644 --- a/src/Http/Routing/RouteCore.php +++ b/src/Http/Routing/RouteCore.php @@ -170,4 +170,4 @@ public static function execute() } } -?> + diff --git a/src/Kernel/Application.php b/src/Kernel/Application.php index c24974d5..a4a1dffc 100644 --- a/src/Kernel/Application.php +++ b/src/Kernel/Application.php @@ -73,4 +73,4 @@ public function boot() } } -?> + diff --git a/src/Kernel/Lemonade/Builders/builder.php b/src/Kernel/Lemonade/Builders/builder.php index bec70ce6..c654dd67 100644 --- a/src/Kernel/Lemonade/Builders/builder.php +++ b/src/Kernel/Lemonade/Builders/builder.php @@ -134,4 +134,4 @@ function build($arguments) $builder->execute(); } -?> + diff --git a/src/Kernel/Lemonade/Builders/licenses.php b/src/Kernel/Lemonade/Builders/licenses.php index db9bbbf7..a31c359e 100644 --- a/src/Kernel/Lemonade/Builders/licenses.php +++ b/src/Kernel/Lemonade/Builders/licenses.php @@ -103,4 +103,4 @@ public function buildLicense() } -?> + diff --git a/src/Kernel/Lemonade/Builders/templates.php b/src/Kernel/Lemonade/Builders/templates.php index f9d3eeaf..ab962c32 100644 --- a/src/Kernel/Lemonade/Builders/templates.php +++ b/src/Kernel/Lemonade/Builders/templates.php @@ -39,4 +39,4 @@ "mit" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/licences/mit.txt", "apache" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/licences/apache.txt" ]; -?> + diff --git a/src/Kernel/Lemonade/Helpers/commands.php b/src/Kernel/Lemonade/Helpers/commands.php index 7bf40781..005a7c92 100644 --- a/src/Kernel/Lemonade/Helpers/commands.php +++ b/src/Kernel/Lemonade/Helpers/commands.php @@ -20,4 +20,4 @@ "repl" => "repl" ]; -?> + diff --git a/src/Kernel/Lemonade/Helpers/helpers.php b/src/Kernel/Lemonade/Helpers/helpers.php index f80e648a..ae0c4f0f 100644 --- a/src/Kernel/Lemonade/Helpers/helpers.php +++ b/src/Kernel/Lemonade/Helpers/helpers.php @@ -6,4 +6,4 @@ function textFormat($text, $color) return "\033[{$color}m{$text}\033[0m"; } -?> + diff --git a/src/Kernel/Lemonade/Helpers/info.php b/src/Kernel/Lemonade/Helpers/info.php index 2aaafddb..855f88a3 100644 --- a/src/Kernel/Lemonade/Helpers/info.php +++ b/src/Kernel/Lemonade/Helpers/info.php @@ -45,4 +45,4 @@ function version() echo "\n->{$version}\n"; } -?> + diff --git a/src/Kernel/Lemonade/Kernel.php b/src/Kernel/Lemonade/Kernel.php index 8fb08274..c9d90b5c 100644 --- a/src/Kernel/Lemonade/Kernel.php +++ b/src/Kernel/Lemonade/Kernel.php @@ -33,4 +33,4 @@ public function execute() } -?> + diff --git a/src/Kernel/Lemonade/Repl/repl.php b/src/Kernel/Lemonade/Repl/repl.php index de6eb202..2c2def7d 100644 --- a/src/Kernel/Lemonade/Repl/repl.php +++ b/src/Kernel/Lemonade/Repl/repl.php @@ -123,4 +123,4 @@ function repl($arguments, $directory) $repl->run($directory); } -?> + diff --git a/src/Kernel/Lemonade/Server/server.php b/src/Kernel/Lemonade/Server/server.php index a781ec08..e2672687 100644 --- a/src/Kernel/Lemonade/Server/server.php +++ b/src/Kernel/Lemonade/Server/server.php @@ -95,4 +95,4 @@ function serve($arguments, $directory) $server->run(); } -?> + diff --git a/src/Kernel/loader.php b/src/Kernel/loader.php index 24f7d704..92ff2076 100644 --- a/src/Kernel/loader.php +++ b/src/Kernel/loader.php @@ -22,4 +22,4 @@ function loader(String $dir) } } -?> + diff --git a/src/Sessions/Csrf.php b/src/Sessions/Csrf.php index c2af1b00..17f73082 100644 --- a/src/Sessions/Csrf.php +++ b/src/Sessions/Csrf.php @@ -56,4 +56,4 @@ static function getToken() return isset($_SESSION["csrf_token"]) ? $_SESSION["csrf_token"] : ""; } } -?> + diff --git a/src/Sessions/Session.php b/src/Sessions/Session.php index 24e5b8d6..b8e10906 100644 --- a/src/Sessions/Session.php +++ b/src/Sessions/Session.php @@ -34,4 +34,4 @@ static function start() } } -?> + diff --git a/src/Utils/Env.php b/src/Utils/Env.php index 1d9493b3..b9716bbc 100644 --- a/src/Utils/Env.php +++ b/src/Utils/Env.php @@ -115,4 +115,4 @@ public static function all() } -?> + diff --git a/src/Utils/constants.php b/src/Utils/constants.php index fb970354..48809e17 100644 --- a/src/Utils/constants.php +++ b/src/Utils/constants.php @@ -64,4 +64,4 @@ 'white' => "[37m", ]; -?> + diff --git a/src/Utils/http.php b/src/Utils/http.php index a5181f7d..7ea67342 100644 --- a/src/Utils/http.php +++ b/src/Utils/http.php @@ -70,4 +70,4 @@ function response($body="") } -?> + diff --git a/src/Utils/page.php b/src/Utils/page.php index 71768c11..c97a7838 100644 --- a/src/Utils/page.php +++ b/src/Utils/page.php @@ -9,4 +9,4 @@ function status_page($code) echo "Lemon"; } -?> + diff --git a/src/Utils/utils.php b/src/Utils/utils.php index 4b925fcb..82111d91 100644 --- a/src/Utils/utils.php +++ b/src/Utils/utils.php @@ -52,4 +52,4 @@ function dd($value) die(); } -?> + diff --git a/src/Views/Tag.php b/src/Views/Tag.php index 5edc5f7c..90a9961f 100644 --- a/src/Views/Tag.php +++ b/src/Views/Tag.php @@ -36,4 +36,4 @@ public function compile(Array $matches) } -?> + diff --git a/src/Views/View.php b/src/Views/View.php index d044053c..8f0edbe3 100644 --- a/src/Views/View.php +++ b/src/Views/View.php @@ -41,4 +41,4 @@ public function __construct(String $name, Array $result, Array $args = []) } -?> + diff --git a/src/Views/ViewCompiler.php b/src/Views/ViewCompiler.php index 11e2533e..16c05362 100644 --- a/src/Views/ViewCompiler.php +++ b/src/Views/ViewCompiler.php @@ -114,4 +114,4 @@ public static function compile(String $view_name, Array $arguments) } } -?> + diff --git a/src/Views/views.php b/src/Views/views.php index 720c75e8..a27d4608 100644 --- a/src/Views/views.php +++ b/src/Views/views.php @@ -12,4 +12,4 @@ function view($name, $arguments = []) return ViewCompiler::compile($name, $arguments); } -?> + From 08e4c2297a99ffe9b4d70826caba107f72ace001 Mon Sep 17 00:00:00 2001 From: Matias Ibargoyen Date: Thu, 11 Nov 2021 12:38:07 +0000 Subject: [PATCH 2/9] :pencil2: Fixing typos. --- src/Http/MiddlewareCollection.php | 2 +- src/Utils/constants.php | 2 +- src/Utils/utils.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Http/MiddlewareCollection.php b/src/Http/MiddlewareCollection.php index 79de91ea..c0b0d72f 100644 --- a/src/Http/MiddlewareCollection.php +++ b/src/Http/MiddlewareCollection.php @@ -42,7 +42,7 @@ private function parse($middlewares) } /** - * Executes given midlewares + * Executes given middlewares * * @param Request $request */ diff --git a/src/Utils/constants.php b/src/Utils/constants.php index fb970354..a7c54006 100644 --- a/src/Utils/constants.php +++ b/src/Utils/constants.php @@ -53,7 +53,7 @@ * In this array are stored colors for console function * * */ -const COLLORS = [ +const COLORS = [ 'black' => "[30m", 'red' => "[31m", 'green' => "[32m", diff --git a/src/Utils/utils.php b/src/Utils/utils.php index 4b925fcb..ff26ec34 100644 --- a/src/Utils/utils.php +++ b/src/Utils/utils.php @@ -9,7 +9,7 @@ * * Types text to php console * - * Mainly debuging tool + * Mainly debugging tool * * @param string $text * @param string $color @@ -17,7 +17,7 @@ * */ function console($text, $color="white") { - $colors = COLLORS; + $colors = COLORS; if (isset($colors[$color])) { $color = $colors[$color]; From c7797371617645048f7bf1b71fb3c32611c9d287 Mon Sep 17 00:00:00 2001 From: Matias Ibargoyen Date: Thu, 11 Nov 2021 14:38:11 +0000 Subject: [PATCH 3/9] :bulb: fixes doc blocks --- src/Http/Response.php | 2 +- src/Http/Routing/Route.php | 2 +- src/Http/Routing/RouteCore.php | 2 +- src/Kernel/loader.php | 6 +++--- src/Utils/utils.php | 2 +- src/Views/Tag.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Http/Response.php b/src/Http/Response.php index 13c622ba..ee5c1d36 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -171,7 +171,7 @@ private function handleBody() * Sets status code handler * * @param int $code - * @param Closure|String $callback|$function_name + * @param Closure|String $action * * */ static function handle(int $code, $action) diff --git a/src/Http/Routing/Route.php b/src/Http/Routing/Route.php index b428c9bd..eff4e757 100644 --- a/src/Http/Routing/Route.php +++ b/src/Http/Routing/Route.php @@ -52,7 +52,7 @@ public function __construct(String $path, Array $methods, $action) /** * Adds new middleware * - * @param String|Array $middleware_param + * @param String|Array $middlewares */ public function middleware($middlewares) { diff --git a/src/Http/Routing/RouteCore.php b/src/Http/Routing/RouteCore.php index f2f26b63..18c938e7 100644 --- a/src/Http/Routing/RouteCore.php +++ b/src/Http/Routing/RouteCore.php @@ -33,7 +33,7 @@ class RouteCore * * @param String $path * @param Array $methods - * @param Closure|String|Array + * @param Closure|String|Array $action * * @return Route */ diff --git a/src/Kernel/loader.php b/src/Kernel/loader.php index 92ff2076..b86e6458 100644 --- a/src/Kernel/loader.php +++ b/src/Kernel/loader.php @@ -1,9 +1,9 @@ Date: Thu, 11 Nov 2021 14:48:50 +0000 Subject: [PATCH 4/9] :recycle: refactoring to use null coalescing --- src/Http/Routing/RouteGroup.php | 6 +++--- src/Kernel/Lemonade/Kernel.php | 2 +- src/Kernel/Lemonade/Server/server.php | 4 ++-- src/Sessions/Csrf.php | 2 +- src/Utils/utils.php | 9 +-------- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Http/Routing/RouteGroup.php b/src/Http/Routing/RouteGroup.php index 7f113cda..9aa997fd 100644 --- a/src/Http/Routing/RouteGroup.php +++ b/src/Http/Routing/RouteGroup.php @@ -33,9 +33,9 @@ class RouteGroup public function __construct(Array $parameters, Array $routes) { - $this->name = isset($parameters["name"]) ? $parameters["name"] : ""; - $this->middlewares = isset($parameters["middlewares"]) ? $parameters["middlewares"] : []; - $this->prefix = isset($parameters["prefix"]) ? $parameters["prefix"] : "/"; + $this->name = $parameters["name"] ?? ""; + $this->middlewares = $parameters["middlewares"] ?? []; + $this->prefix = $parameters["prefix"] ?? "/"; $this->routes = $routes; $this->resolve(); $this->update(); diff --git a/src/Kernel/Lemonade/Kernel.php b/src/Kernel/Lemonade/Kernel.php index c9d90b5c..690834d7 100644 --- a/src/Kernel/Lemonade/Kernel.php +++ b/src/Kernel/Lemonade/Kernel.php @@ -24,7 +24,7 @@ public function __construct($command, $directory) public function execute() { - $command = isset($this->command[1]) ? $this->command[1] : ""; + $command = $this->command[1] ?? ""; $arguments = array_slice($this->command, 2); $commands = COMMANDS; isset($commands[$command]) ? $commands[$command]($arguments, $this->directory) : $commands["-h"](); diff --git a/src/Kernel/Lemonade/Server/server.php b/src/Kernel/Lemonade/Server/server.php index e2672687..a827da79 100644 --- a/src/Kernel/Lemonade/Server/server.php +++ b/src/Kernel/Lemonade/Server/server.php @@ -55,8 +55,8 @@ private function build() { $arguments = $this->parse(); - $address = isset($arguments['host']) ? $arguments['host'] : "localhost"; - $port = isset($arguments['port']) ? $arguments['port'] : "8000"; + $address = $arguments['host'] ?? "localhost"; + $port = $arguments['port'] ?? "8000"; $dir = $this->directory."/public/"; $command = "php -S {$address}:{$port} -t {$dir}"; diff --git a/src/Sessions/Csrf.php b/src/Sessions/Csrf.php index 17f73082..d940d158 100644 --- a/src/Sessions/Csrf.php +++ b/src/Sessions/Csrf.php @@ -53,7 +53,7 @@ static function check() */ static function getToken() { - return isset($_SESSION["csrf_token"]) ? $_SESSION["csrf_token"] : ""; + return $_SESSION["csrf_token"] ?? ""; } } diff --git a/src/Utils/utils.php b/src/Utils/utils.php index 1684e700..fc7eb313 100644 --- a/src/Utils/utils.php +++ b/src/Utils/utils.php @@ -18,14 +18,7 @@ function console($text, $color="white") { $colors = COLORS; - if (isset($colors[$color])) - { - $color = $colors[$color]; - } - else - { - $color = $colors["white"]; - } + $color = $colors[$color] ?? $colors["white"]; error_log("\n\n\033".$color.$text."\033[0m\n"); } From 559895bc6b7a927d91526d424cd0c09ca2c08c7a Mon Sep 17 00:00:00 2001 From: Matias Ibargoyen Date: Thu, 11 Nov 2021 15:13:42 +0000 Subject: [PATCH 5/9] :recycle: refactors away from usages of get_class and gettype --- src/Http/MiddlewareCollection.php | 2 +- src/Http/Response.php | 8 ++++---- src/Http/Routing/Helpers.php | 2 +- src/Http/Routing/RouteCore.php | 2 +- src/Http/Routing/RouteGroup.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Http/MiddlewareCollection.php b/src/Http/MiddlewareCollection.php index 5a4ad88d..16103833 100644 --- a/src/Http/MiddlewareCollection.php +++ b/src/Http/MiddlewareCollection.php @@ -36,7 +36,7 @@ public function add($middlewares) */ private function parse($middlewares) { - if (gettype($this->middlewares) == "string") + if (is_string($this->middlewares)) return explode("|", $this->middlewares); return $middlewares; } diff --git a/src/Http/Response.php b/src/Http/Response.php index 13c622ba..36782d25 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -146,20 +146,20 @@ private function handleBody() return; } - if (gettype($body) == "array") + if (is_array($body)) { header("Content-type:application/json"); echo json_encode($body); return; } - if (gettype($body) != "object") + if (!is_object($body)) return; - if (get_class($body) == "Lemon\Http\Response") + if ($body instanceof Response) $body->terminate(); - if (get_class($body) == "Lemon\Views\View") + if ($body instanceof \Lemon\Views\View) { extract($body->arguments); eval($body->compiled_template); diff --git a/src/Http/Routing/Helpers.php b/src/Http/Routing/Helpers.php index 40145082..b377c2f0 100644 --- a/src/Http/Routing/Helpers.php +++ b/src/Http/Routing/Helpers.php @@ -21,7 +21,7 @@ function getParamTypes($callback) $type = $param->getType(); if (!$type) $type = "mixed"; - $types[array_search($param, $params)] = gettype($type) == "string" ? $type : $type->__toString(); + $types[array_search($param, $params)] = is_string($type) ? $type : $type->__toString(); } return $types; diff --git a/src/Http/Routing/RouteCore.php b/src/Http/Routing/RouteCore.php index f2f26b63..81958609 100644 --- a/src/Http/Routing/RouteCore.php +++ b/src/Http/Routing/RouteCore.php @@ -39,7 +39,7 @@ class RouteCore */ static function createRoute(String $path, Array $methods, $action) { - if (gettype($action) == "string") + if (is_string($action)) { $action = explode(":", $action); if (!isset($action[1])) diff --git a/src/Http/Routing/RouteGroup.php b/src/Http/Routing/RouteGroup.php index 7f113cda..3cef95af 100644 --- a/src/Http/Routing/RouteGroup.php +++ b/src/Http/Routing/RouteGroup.php @@ -51,7 +51,7 @@ public function resolve() if (is_array($route)) $this->resolveRoute($pos, $route); - else if (get_class($route) == "Lemon\Http\Routing\RouteGroup") + else if ($route instanceof RouteGroup) $this->resolveRoute($pos, $route->routes); } } From d5a3136b5d6e5d80921edb08f7207bc8dbe656b8 Mon Sep 17 00:00:00 2001 From: TENMAJKL Date: Thu, 11 Nov 2021 21:53:57 +0100 Subject: [PATCH 6/9] Added contribution info --- .phpunit.result.cache | 1 + README.md | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 00000000..0b8f4fc4 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"\/Users\/misa\/Lemon\/tests\/Http\/Routing\/RouteTest.php::router":5,"\/Users\/misa\/Lemon\/tests\/Views\/ViewTest.php::basic":4,"\/Users\/misa\/Lemon\/tests\/Http\/Routing\/RouteTest.php::basic":4,"\/Users\/misa\/Lemon\/tests\/Support\/Http\/Routing\/HelperTest.php::getParamTypes":4},"times":{"\/Users\/misa\/Lemon\/tests\/ExampleTest.php::example":0.002,"\/Users\/misa\/Lemon\/tests\/Http\/Routing\/RouteTest.php::router":0.007,"\/Users\/misa\/Lemon\/tests\/Http\/Routing\/RouteTest.php::basic":0.007,"\/Users\/misa\/Lemon\/tests\/Views\/ViewTest.php::basic":0.001,"\/Users\/misa\/Lemon\/tests\/Support\/Http\/Routing\/HelperTest.php::getParamTypes":0}} \ No newline at end of file diff --git a/README.md b/README.md index 6739ac31..480330db 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,6 @@ project/ If you want to build bigger starting app, type `php lemonade build type:project` +# Contributing + +Any contributions that don't rewrite whole framework are welcomend. But please use latest develop branch. (Currently [v3-develop](https://github.com/Lemon-Framework/Lemon/tree/v3-develop)) From ff5546c8f5ef596f5afedd0a950293b5c689e700 Mon Sep 17 00:00:00 2001 From: TENMAJKL Date: Thu, 11 Nov 2021 21:54:35 +0100 Subject: [PATCH 7/9] removed phpunit cache --- .gitignore | 1 + .phpunit.result.cache | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 .phpunit.result.cache diff --git a/.gitignore b/.gitignore index ddd7aff1..60228d69 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /testing/ /vendor/ **/*.swp +.phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 0b8f4fc4..00000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":{"\/Users\/misa\/Lemon\/tests\/Http\/Routing\/RouteTest.php::router":5,"\/Users\/misa\/Lemon\/tests\/Views\/ViewTest.php::basic":4,"\/Users\/misa\/Lemon\/tests\/Http\/Routing\/RouteTest.php::basic":4,"\/Users\/misa\/Lemon\/tests\/Support\/Http\/Routing\/HelperTest.php::getParamTypes":4},"times":{"\/Users\/misa\/Lemon\/tests\/ExampleTest.php::example":0.002,"\/Users\/misa\/Lemon\/tests\/Http\/Routing\/RouteTest.php::router":0.007,"\/Users\/misa\/Lemon\/tests\/Http\/Routing\/RouteTest.php::basic":0.007,"\/Users\/misa\/Lemon\/tests\/Views\/ViewTest.php::basic":0.001,"\/Users\/misa\/Lemon\/tests\/Support\/Http\/Routing\/HelperTest.php::getParamTypes":0}} \ No newline at end of file From d188d08d05e4a5722cc72807221f0587e4ca8f05 Mon Sep 17 00:00:00 2001 From: Matias Ibargoyen Date: Fri, 12 Nov 2021 01:15:29 +0000 Subject: [PATCH 8/9] applies strict comparison --- src/Http/Routing/Dispatcher.php | 2 +- src/Http/Routing/Route.php | 2 +- src/Http/Routing/RouteCore.php | 2 +- src/Kernel/Lemonade/Builders/licenses.php | 2 +- src/Sessions/Csrf.php | 4 ++-- src/Utils/http.php | 4 ++-- src/Utils/utils.php | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Http/Routing/Dispatcher.php b/src/Http/Routing/Dispatcher.php index cdf39acc..bfaaa7ed 100644 --- a/src/Http/Routing/Dispatcher.php +++ b/src/Http/Routing/Dispatcher.php @@ -38,7 +38,7 @@ public function __construct(Array $routes) */ private function parseGet() { - if (preg_match("/\\?(.+)/", $this->request_uri, $matches) == 1) + if (preg_match("/\\?(.+)/", $this->request_uri, $matches) === 1) { $this->request_uri = str_replace("{$matches[0]}", "", $this->request_uri); parse_str($matches[1], $get_args); diff --git a/src/Http/Routing/Route.php b/src/Http/Routing/Route.php index eff4e757..95bddf84 100644 --- a/src/Http/Routing/Route.php +++ b/src/Http/Routing/Route.php @@ -100,7 +100,7 @@ public function toResponse(Request $request, Array $params) $arguments = []; foreach ($param_types as $type) { - if ($type == "Lemon\Http\Request") + if ($type === "Lemon\Http\Request") { array_push($arguments, $request); continue; diff --git a/src/Http/Routing/RouteCore.php b/src/Http/Routing/RouteCore.php index 98ec6791..5e8354c6 100644 --- a/src/Http/Routing/RouteCore.php +++ b/src/Http/Routing/RouteCore.php @@ -146,7 +146,7 @@ public static function controller(String $base, String $controller) public static function byName(String $name) { foreach (self::$routes as $route) - if ($route->name == $name) + if ($route->name === $name) return $route; } diff --git a/src/Kernel/Lemonade/Builders/licenses.php b/src/Kernel/Lemonade/Builders/licenses.php index a31c359e..d0ece372 100644 --- a/src/Kernel/Lemonade/Builders/licenses.php +++ b/src/Kernel/Lemonade/Builders/licenses.php @@ -44,7 +44,7 @@ private function licenseType() return; } - if ($type == "custom") + if ($type === "custom") { $license = readline("Type your license content: "); $this->parameters["license"] = $license; diff --git a/src/Sessions/Csrf.php b/src/Sessions/Csrf.php index d940d158..a919b207 100644 --- a/src/Sessions/Csrf.php +++ b/src/Sessions/Csrf.php @@ -14,7 +14,7 @@ class Csrf */ static function setToken() { - if ($_SERVER["REQUEST_METHOD"] == "GET") + if ($_SERVER["REQUEST_METHOD"] === "GET") { $token = uniqid(); $token = hash("sha256", $token); @@ -32,7 +32,7 @@ static function check() { if (isset($_POST["csrf_token"]) && isset($_SESSION["csrf_token"])) { - if ($_POST["csrf_token"] != $_SESSION["csrf_token"]) + if ($_POST["csrf_token"] !== $_SESSION["csrf_token"]) { Response::raise(400); exit(); diff --git a/src/Utils/http.php b/src/Utils/http.php index 7ea67342..fd2e1dbf 100644 --- a/src/Utils/http.php +++ b/src/Utils/http.php @@ -47,10 +47,10 @@ function route(String $name) */ function to_route(String $route_name, Array $dynamic_params=[]) { - $route_name = $route_name == "/" ? "main" : $route_name; + $route_name = $route_name === "/" ? "main" : $route_name; if ($route = route($route_name)) { - $path = $route->path == "" ? "/" : $route->path; + $path = $route->path === "" ? "/" : $route->path; foreach ($dynamic_params as $param) $path = preg_replace("/{[^}]+}/", $param, $path); return redirect("/$path"); diff --git a/src/Utils/utils.php b/src/Utils/utils.php index 23c4af45..f3bf6cb2 100644 --- a/src/Utils/utils.php +++ b/src/Utils/utils.php @@ -31,7 +31,7 @@ function console($text, $color="white") * */ function isUserPodvodnik($user) { - return $user == "CoolFido"; + return $user === "CoolFido"; } /** From ae98cf5c92b8d6a078c312537a8c868a623fc4d8 Mon Sep 17 00:00:00 2001 From: TENMAJKL Date: Sun, 21 Nov 2021 14:53:19 +0100 Subject: [PATCH 9/9] Fixed nested route groups, fixed middleware in group --- src/Http/MiddlewareCollection.php | 9 ++++----- src/Http/Routing/Route.php | 1 - src/Http/Routing/RouteGroup.php | 15 +++++++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Http/MiddlewareCollection.php b/src/Http/MiddlewareCollection.php index 16103833..d063c00a 100644 --- a/src/Http/MiddlewareCollection.php +++ b/src/Http/MiddlewareCollection.php @@ -22,9 +22,9 @@ public function __construct($middlewares=[]) * @param String|Array $middlewares */ public function add($middlewares) - { + { $parsed = $this->parse($middlewares); - array_push($this->middlewares, $parsed); + $this->middlewares = array_merge($this->middlewares, $parsed); return $this; } @@ -36,8 +36,8 @@ public function add($middlewares) */ private function parse($middlewares) { - if (is_string($this->middlewares)) - return explode("|", $this->middlewares); + if (is_string($middlewares)) + return explode("|", $middlewares); return $middlewares; } @@ -70,4 +70,3 @@ public function terminate(Request $request) } } - diff --git a/src/Http/Routing/Route.php b/src/Http/Routing/Route.php index eff4e757..5c092ec1 100644 --- a/src/Http/Routing/Route.php +++ b/src/Http/Routing/Route.php @@ -120,4 +120,3 @@ public function toResponse(Request $request, Array $params) } } - diff --git a/src/Http/Routing/RouteGroup.php b/src/Http/Routing/RouteGroup.php index 166d716e..7126f204 100644 --- a/src/Http/Routing/RouteGroup.php +++ b/src/Http/Routing/RouteGroup.php @@ -30,6 +30,10 @@ class RouteGroup */ public $routes; + /** + * Positions that will get unset after parsing + */ + public $unset_positions; public function __construct(Array $parameters, Array $routes) { @@ -37,12 +41,13 @@ public function __construct(Array $parameters, Array $routes) $this->middlewares = $parameters["middlewares"] ?? []; $this->prefix = $parameters["prefix"] ?? "/"; $this->routes = $routes; + $this->unset_positions = []; $this->resolve(); $this->update(); } /** - * Resolves nested route groups and arrays of routes + * Resolves nested route groups and arays of routes */ public function resolve() { @@ -51,9 +56,12 @@ public function resolve() if (is_array($route)) $this->resolveRoute($pos, $route); - else if ($route instanceof RouteGroup) + else if ($route instanceof \Lemon\Http\Routing\RouteGroup) $this->resolveRoute($pos, $route->routes); } + + foreach ($this->unset_positions as $position) + unset($this->routes[$position]); } /** @@ -61,7 +69,7 @@ public function resolve() */ public function resolveRoute($pos, $routes) { - unset($this->routes[$pos]); + array_push($this->unset_positions, $pos); $this->routes = array_merge($this->routes, $routes); } @@ -81,4 +89,3 @@ public function update() } -