Skip to content

Commit

Permalink
Merge pull request #46 from Lemon-Framework/master
Browse files Browse the repository at this point in the history
v2 changes develped in master
  • Loading branch information
tenmajkl authored Nov 21, 2021
2 parents 389084f + 7a4ded7 commit 729f072
Show file tree
Hide file tree
Showing 33 changed files with 83 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/testing/
/vendor/
**/*.swp
.phpunit.result.cache
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ your_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))
2 changes: 1 addition & 1 deletion src/Exceptions/ViewException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

class ViewException extends \Exception {}

?>

11 changes: 5 additions & 6 deletions src/Http/MiddlewareCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -36,13 +36,13 @@ public function add($middlewares)
*/
private function parse($middlewares)
{
if (gettype($this->middlewares) == "string")
return explode("|", $this->middlewares);
if (is_string($middlewares))
return explode("|", $middlewares);
return $middlewares;
}

/**
* Executes given midlewares
* Executes given middlewares
*
* @param Request $request
*/
Expand Down Expand Up @@ -70,4 +70,3 @@ public function terminate(Request $request)
}
}

?>
2 changes: 1 addition & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ function header($name)

}

?>

12 changes: 6 additions & 6 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -181,4 +181,4 @@ static function handle(int $code, $action)

}

?>

4 changes: 2 additions & 2 deletions src/Http/Routing/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -109,4 +109,4 @@ public function run()
}
}

?>

4 changes: 2 additions & 2 deletions src/Http/Routing/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ 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;

}

?>

5 changes: 2 additions & 3 deletions src/Http/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -120,4 +120,3 @@ public function toResponse(Request $request, Array $params)
}
}

?>
8 changes: 4 additions & 4 deletions src/Http/Routing/RouteCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class RouteCore
*
* @param String $path
* @param Array $methods
* @param Closure|String|Array
* @param Closure|String|Array $action
*
* @return Route
*/
static function createRoute(String $path, Array $methods, $action)
{
if (gettype($action) == "string")
if (is_string($action))
{
$action = explode(":", $action);
if (!isset($action[1]))
Expand Down Expand Up @@ -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;
}

Expand All @@ -170,4 +170,4 @@ public static function execute()
}
}

?>

21 changes: 14 additions & 7 deletions src/Http/Routing/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ class RouteGroup
*/
public $routes;

/**
* Positions that will get unset after parsing
*/
public $unset_positions;

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->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()
{
Expand All @@ -51,17 +56,20 @@ public function resolve()
if (is_array($route))
$this->resolveRoute($pos, $route);

else if (get_class($route) == "Lemon\Http\Routing\RouteGroup")
else if ($route instanceof \Lemon\Http\Routing\RouteGroup)
$this->resolveRoute($pos, $route->routes);
}

foreach ($this->unset_positions as $position)
unset($this->routes[$position]);
}

/**
* Resolves routes that aren't Route instance
*/
public function resolveRoute($pos, $routes)
{
unset($this->routes[$pos]);
array_push($this->unset_positions, $pos);
$this->routes = array_merge($this->routes, $routes);
}

Expand All @@ -81,4 +89,3 @@ public function update()


}

2 changes: 1 addition & 1 deletion src/Kernel/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ public function boot()
}
}

?>

2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Builders/builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ function build($arguments)
$builder->execute();
}

?>

4 changes: 2 additions & 2 deletions src/Kernel/Lemonade/Builders/licenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function licenseType()
return;
}

if ($type == "custom")
if ($type === "custom")
{
$license = readline("Type your license content: ");
$this->parameters["license"] = $license;
Expand Down Expand Up @@ -103,4 +103,4 @@ public function buildLicense()

}

?>

2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Builders/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];
?>

2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Helpers/commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"repl" => "repl"

];
?>

2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ function textFormat($text, $color)
return "\033[{$color}m{$text}\033[0m";
}

?>

2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Helpers/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ function version()
echo "\n->{$version}\n";
}

?>

4 changes: 2 additions & 2 deletions src/Kernel/Lemonade/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]();
Expand All @@ -33,4 +33,4 @@ public function execute()

}

?>

2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Repl/repl.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ function repl($arguments, $directory)
$repl->run($directory);
}

?>

6 changes: 3 additions & 3 deletions src/Kernel/Lemonade/Server/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down Expand Up @@ -95,4 +95,4 @@ function serve($arguments, $directory)
$server->run();
}

?>

8 changes: 4 additions & 4 deletions src/Kernel/loader.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* Loads all files from specific folder
* Inspired by loader from CoolFido
*
* @param String $dirname
* Inspired by loader from CoolFido
*
* @param String $dir
*
*/
function loader(String $dir)
Expand All @@ -22,4 +22,4 @@ function loader(String $dir)
}
}

?>

8 changes: 4 additions & 4 deletions src/Sessions/Csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -53,7 +53,7 @@ static function check()
*/
static function getToken()
{
return isset($_SESSION["csrf_token"]) ? $_SESSION["csrf_token"] : "";
return $_SESSION["csrf_token"] ?? "";
}
}
?>

2 changes: 1 addition & 1 deletion src/Sessions/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ static function start()
}
}

?>

2 changes: 1 addition & 1 deletion src/Utils/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ public static function all()

}

?>

Loading

0 comments on commit 729f072

Please sign in to comment.