diff --git a/src/Application/Application.php b/src/Application/Application.php index 6571268e..d6c3c93d 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -422,4 +422,31 @@ public function __invoke(...$params): mixed return $this->capsule->bind($params[0], $params[1]); } + + /** + * Send the application response + * + * @return void + */ + public function send(): void + { + $this->run(); + } + + /** + * Delegate method calls to the router + * + * @param string $method + * @param array $args + * @return mixed + * @throws ApplicationException + */ + public function __call(string $method, array $args): mixed + { + if (!method_exists($this->router, $method)) { + throw new ApplicationException("Method [$method] does not exist in Application."); + } + + return call_user_func_array([$this->router, $method], $args); + } } diff --git a/src/Security/Tokenize.php b/src/Security/Tokenize.php index f8079f74..ca67d079 100644 --- a/src/Security/Tokenize.php +++ b/src/Security/Tokenize.php @@ -24,7 +24,7 @@ class Tokenize * @return ?array * @throws SessionException */ - public static function csrf(int $time = null): ?array + public static function csrf(?int $time = null): ?array { static::makeCsrfToken($time); @@ -53,9 +53,9 @@ public static function makeCsrfToken(?int $time = null): bool Session::getInstance()->add( '__bow.csrf', [ - 'token' => $token, - 'expire_at' => time() + static::$expire_at, - 'field' => '' + 'token' => $token, + 'expire_at' => time() + static::$expire_at, + 'field' => '' ] ); @@ -114,7 +114,7 @@ public static function verify(string $token, bool $strict = false): bool * @return bool * @throws SessionException */ - public static function csrfExpired(int $time = null): bool + public static function csrfExpired(?int $time = null): bool { if (Session::getInstance()->has('__bow.csrf')) { return false; diff --git a/src/Session/Session.php b/src/Session/Session.php index 5b29fa10..c4d8eff5 100644 --- a/src/Session/Session.php +++ b/src/Session/Session.php @@ -71,12 +71,12 @@ private function __construct(array $config) // We merge configuration $this->config = array_merge( [ - 'name' => 'Bow', - 'path' => '/', - 'domain' => null, - 'secure' => false, - 'httponly' => false, - 'save_path' => null, + 'name' => 'Bow', + 'path' => '/', + 'domain' => null, + 'secure' => false, + 'httponly' => false, + 'save_path' => null, ], $config ); @@ -214,18 +214,22 @@ private function generateId(): string } /** - * Set session cookie params + * Set session cookie parameters * * @return void */ private function setCookieParameters(): void { + $domain = $this->config['domain'] ?? null; + $secure = (bool)$this->config["secure"]; + $httponly = (bool)$this->config["httponly"]; + session_set_cookie_params( (int)$this->config["lifetime"], $this->config["path"], - $this->config['domain'], - $this->config["secure"], - $this->config["httponly"] + $domain, + $secure, + $httponly ); } diff --git a/src/Storage/Service/DiskFilesystemService.php b/src/Storage/Service/DiskFilesystemService.php index 38e4c7d6..361549a0 100644 --- a/src/Storage/Service/DiskFilesystemService.php +++ b/src/Storage/Service/DiskFilesystemService.php @@ -57,7 +57,7 @@ public function getBaseDirectory(): string * * @return array|bool|string */ - public function store(UploadedFile $file, $location = null, array $option = []): array|bool|string + public function store(UploadedFile $file, string|array|null $location = null, array $option = []): array|bool|string { if (is_array($location)) { $option = $location; diff --git a/src/Support/helpers.php b/src/Support/helpers.php index b864a9e1..a5aacf09 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -136,7 +136,7 @@ function request(): Request * @return DB * @throws ConnectionException */ - function db(string $name = null, callable $cb = null): DB + function db(?string $name = null, ?callable $cb = null): DB { if (func_num_args() == 0) { return DB::getInstance(); @@ -195,7 +195,7 @@ function view(string $template, int|array $data = [], int $code = 200): View * @throws ConnectionException * @deprecated */ - function table(string $name, string $connexion = null): QueryBuilder + function table(string $name, ?string $connexion = null): QueryBuilder { if (is_string($connexion)) { db($connexion); @@ -213,7 +213,7 @@ function table(string $name, string $connexion = null): QueryBuilder * @param string|null $name * @return int */ - function get_last_insert_id(string $name = null): int + function get_last_insert_id(?string $name = null): int { return DB::lastInsertId($name); } @@ -228,7 +228,7 @@ function get_last_insert_id(string $name = null): int * @return Bow\Database\QueryBuilder * @throws ConnectionException */ - function db_table(string $name, string $connexion = null): QueryBuilder + function db_table(string $name, ?string $connexion = null): QueryBuilder { if (is_string($connexion)) { db($connexion); @@ -362,7 +362,7 @@ function sep(): string * @return ?array * @throws SessionException */ - function create_csrf_token(int $time = null): ?array + function create_csrf_token(?int $time = null): ?array { return Tokenize::csrf($time); } @@ -463,7 +463,7 @@ function verify_csrf(string $token, bool $strict = false): bool * @return bool * @throws SessionException */ - function csrf_time_is_expired(string $time = null): bool + function csrf_time_is_expired(?string $time = null): bool { return Tokenize::csrfExpired($time); } @@ -580,7 +580,7 @@ function get_header(string $key): ?string * @param string|null $path * @return Redirect */ - function redirect(string $path = null): Redirect + function redirect(?string $path = null): Redirect { $redirect = Redirect::getInstance(); @@ -600,7 +600,7 @@ function redirect(string $path = null): Redirect * @param array $parameters * @return string */ - function url(string|array $url = null, array $parameters = []): string + function url(string|array|null $url = null, array $parameters = []): string { $current = trim(request()->url(), '/'); @@ -783,9 +783,9 @@ function flash(string $key, string $message): mixed * @return MailAdapterInterface|bool */ function email( - string $view = null, + ?string $view = null, array $data = [], - callable $cb = null + ?callable $cb = null ): MailAdapterInterface|bool { if ($view === null) { return Mail::getInstance(); @@ -820,7 +820,7 @@ function raw_email(string $to, string $subject, string $message, array $headers * @return mixed * @throws SessionException */ - function session(array|string $value = null, mixed $default = null): mixed + function session(array|string|null $value = null, mixed $default = null): mixed { if ($value == null) { return Session::getInstance(); @@ -849,7 +849,7 @@ function session(array|string $value = null, mixed $default = null): mixed * @return string|array|object|null */ function cookie( - string $key = null, + ?string $key = null, mixed $data = null, int $expiration = 3600 ): string|array|object|null { @@ -990,7 +990,7 @@ function app_file_system(string $disk): DiskFilesystemService * @return mixed * @throws ErrorException */ - function cache(string $key = null, mixed $value = null, int $ttl = null): mixed + function cache(?string $key = null, mixed $value = null, ?int $ttl = null): mixed { $instance = Cache::getInstance(); @@ -1039,7 +1039,7 @@ function app_now(): Carbon * @param mixed $hash_value * @return bool|string */ - function app_hash(string $data, string $hash_value = null): bool|string + function app_hash(string $data, ?string $hash_value = null): bool|string { if (!is_null($hash_value)) { return Hash::check($data, $hash_value); @@ -1058,7 +1058,7 @@ function app_hash(string $data, string $hash_value = null): bool|string * @return bool|string * @deprecated */ - function bow_hash(string $data, string $hash_value = null): bool|string + function bow_hash(string $data, ?string $hash_value = null): bool|string { return app_hash($data, $hash_value); } @@ -1074,7 +1074,7 @@ function bow_hash(string $data, string $hash_value = null): bool|string * @return string|Translator */ function app_trans( - string $key = null, + ?string $key = null, array $data = [], bool $choose = false ): string|Translator {