Skip to content

Commit d1cdcaa

Browse files
authored
Merge pull request #337 from gessyken/5.x
Fix: PHP 8.1+ compatibility and bootstrap improvements
2 parents 1cc5876 + 749c332 commit d1cdcaa

5 files changed

Lines changed: 63 additions & 32 deletions

File tree

src/Application/Application.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,31 @@ public function __invoke(...$params): mixed
422422

423423
return $this->capsule->bind($params[0], $params[1]);
424424
}
425+
426+
/**
427+
* Send the application response
428+
*
429+
* @return void
430+
*/
431+
public function send(): void
432+
{
433+
$this->run();
434+
}
435+
436+
/**
437+
* Delegate method calls to the router
438+
*
439+
* @param string $method
440+
* @param array $args
441+
* @return mixed
442+
* @throws ApplicationException
443+
*/
444+
public function __call(string $method, array $args): mixed
445+
{
446+
if (!method_exists($this->router, $method)) {
447+
throw new ApplicationException("Method [$method] does not exist in Application.");
448+
}
449+
450+
return call_user_func_array([$this->router, $method], $args);
451+
}
425452
}

src/Security/Tokenize.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Tokenize
2424
* @return ?array
2525
* @throws SessionException
2626
*/
27-
public static function csrf(int $time = null): ?array
27+
public static function csrf(?int $time = null): ?array
2828
{
2929
static::makeCsrfToken($time);
3030

@@ -53,9 +53,9 @@ public static function makeCsrfToken(?int $time = null): bool
5353
Session::getInstance()->add(
5454
'__bow.csrf',
5555
[
56-
'token' => $token,
57-
'expire_at' => time() + static::$expire_at,
58-
'field' => '<input type="hidden" name="_token" value="' . $token . '"/>'
56+
'token' => $token,
57+
'expire_at' => time() + static::$expire_at,
58+
'field' => '<input type="hidden" name="_token" value="' . $token . '"/>'
5959
]
6060
);
6161

@@ -114,7 +114,7 @@ public static function verify(string $token, bool $strict = false): bool
114114
* @return bool
115115
* @throws SessionException
116116
*/
117-
public static function csrfExpired(int $time = null): bool
117+
public static function csrfExpired(?int $time = null): bool
118118
{
119119
if (Session::getInstance()->has('__bow.csrf')) {
120120
return false;

src/Session/Session.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ private function __construct(array $config)
7171
// We merge configuration
7272
$this->config = array_merge(
7373
[
74-
'name' => 'Bow',
75-
'path' => '/',
76-
'domain' => null,
77-
'secure' => false,
78-
'httponly' => false,
79-
'save_path' => null,
74+
'name' => 'Bow',
75+
'path' => '/',
76+
'domain' => null,
77+
'secure' => false,
78+
'httponly' => false,
79+
'save_path' => null,
8080
],
8181
$config
8282
);
@@ -214,18 +214,22 @@ private function generateId(): string
214214
}
215215

216216
/**
217-
* Set session cookie params
217+
* Set session cookie parameters
218218
*
219219
* @return void
220220
*/
221221
private function setCookieParameters(): void
222222
{
223+
$domain = $this->config['domain'] ?? null;
224+
$secure = (bool)$this->config["secure"];
225+
$httponly = (bool)$this->config["httponly"];
226+
223227
session_set_cookie_params(
224228
(int)$this->config["lifetime"],
225229
$this->config["path"],
226-
$this->config['domain'],
227-
$this->config["secure"],
228-
$this->config["httponly"]
230+
$domain,
231+
$secure,
232+
$httponly
229233
);
230234
}
231235

src/Storage/Service/DiskFilesystemService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getBaseDirectory(): string
5757
*
5858
* @return array|bool|string
5959
*/
60-
public function store(UploadedFile $file, $location = null, array $option = []): array|bool|string
60+
public function store(UploadedFile $file, string|array|null $location = null, array $option = []): array|bool|string
6161
{
6262
if (is_array($location)) {
6363
$option = $location;

src/Support/helpers.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function request(): Request
136136
* @return DB
137137
* @throws ConnectionException
138138
*/
139-
function db(string $name = null, callable $cb = null): DB
139+
function db(?string $name = null, ?callable $cb = null): DB
140140
{
141141
if (func_num_args() == 0) {
142142
return DB::getInstance();
@@ -195,7 +195,7 @@ function view(string $template, int|array $data = [], int $code = 200): View
195195
* @throws ConnectionException
196196
* @deprecated
197197
*/
198-
function table(string $name, string $connexion = null): QueryBuilder
198+
function table(string $name, ?string $connexion = null): QueryBuilder
199199
{
200200
if (is_string($connexion)) {
201201
db($connexion);
@@ -213,7 +213,7 @@ function table(string $name, string $connexion = null): QueryBuilder
213213
* @param string|null $name
214214
* @return int
215215
*/
216-
function get_last_insert_id(string $name = null): int
216+
function get_last_insert_id(?string $name = null): int
217217
{
218218
return DB::lastInsertId($name);
219219
}
@@ -228,7 +228,7 @@ function get_last_insert_id(string $name = null): int
228228
* @return Bow\Database\QueryBuilder
229229
* @throws ConnectionException
230230
*/
231-
function db_table(string $name, string $connexion = null): QueryBuilder
231+
function db_table(string $name, ?string $connexion = null): QueryBuilder
232232
{
233233
if (is_string($connexion)) {
234234
db($connexion);
@@ -362,7 +362,7 @@ function sep(): string
362362
* @return ?array
363363
* @throws SessionException
364364
*/
365-
function create_csrf_token(int $time = null): ?array
365+
function create_csrf_token(?int $time = null): ?array
366366
{
367367
return Tokenize::csrf($time);
368368
}
@@ -463,7 +463,7 @@ function verify_csrf(string $token, bool $strict = false): bool
463463
* @return bool
464464
* @throws SessionException
465465
*/
466-
function csrf_time_is_expired(string $time = null): bool
466+
function csrf_time_is_expired(?string $time = null): bool
467467
{
468468
return Tokenize::csrfExpired($time);
469469
}
@@ -580,7 +580,7 @@ function get_header(string $key): ?string
580580
* @param string|null $path
581581
* @return Redirect
582582
*/
583-
function redirect(string $path = null): Redirect
583+
function redirect(?string $path = null): Redirect
584584
{
585585
$redirect = Redirect::getInstance();
586586

@@ -600,7 +600,7 @@ function redirect(string $path = null): Redirect
600600
* @param array $parameters
601601
* @return string
602602
*/
603-
function url(string|array $url = null, array $parameters = []): string
603+
function url(string|array|null $url = null, array $parameters = []): string
604604
{
605605
$current = trim(request()->url(), '/');
606606

@@ -783,9 +783,9 @@ function flash(string $key, string $message): mixed
783783
* @return MailAdapterInterface|bool
784784
*/
785785
function email(
786-
string $view = null,
786+
?string $view = null,
787787
array $data = [],
788-
callable $cb = null
788+
?callable $cb = null
789789
): MailAdapterInterface|bool {
790790
if ($view === null) {
791791
return Mail::getInstance();
@@ -820,7 +820,7 @@ function raw_email(string $to, string $subject, string $message, array $headers
820820
* @return mixed
821821
* @throws SessionException
822822
*/
823-
function session(array|string $value = null, mixed $default = null): mixed
823+
function session(array|string|null $value = null, mixed $default = null): mixed
824824
{
825825
if ($value == null) {
826826
return Session::getInstance();
@@ -849,7 +849,7 @@ function session(array|string $value = null, mixed $default = null): mixed
849849
* @return string|array|object|null
850850
*/
851851
function cookie(
852-
string $key = null,
852+
?string $key = null,
853853
mixed $data = null,
854854
int $expiration = 3600
855855
): string|array|object|null {
@@ -990,7 +990,7 @@ function app_file_system(string $disk): DiskFilesystemService
990990
* @return mixed
991991
* @throws ErrorException
992992
*/
993-
function cache(string $key = null, mixed $value = null, int $ttl = null): mixed
993+
function cache(?string $key = null, mixed $value = null, ?int $ttl = null): mixed
994994
{
995995
$instance = Cache::getInstance();
996996

@@ -1039,7 +1039,7 @@ function app_now(): Carbon
10391039
* @param mixed $hash_value
10401040
* @return bool|string
10411041
*/
1042-
function app_hash(string $data, string $hash_value = null): bool|string
1042+
function app_hash(string $data, ?string $hash_value = null): bool|string
10431043
{
10441044
if (!is_null($hash_value)) {
10451045
return Hash::check($data, $hash_value);
@@ -1058,7 +1058,7 @@ function app_hash(string $data, string $hash_value = null): bool|string
10581058
* @return bool|string
10591059
* @deprecated
10601060
*/
1061-
function bow_hash(string $data, string $hash_value = null): bool|string
1061+
function bow_hash(string $data, ?string $hash_value = null): bool|string
10621062
{
10631063
return app_hash($data, $hash_value);
10641064
}
@@ -1074,7 +1074,7 @@ function bow_hash(string $data, string $hash_value = null): bool|string
10741074
* @return string|Translator
10751075
*/
10761076
function app_trans(
1077-
string $key = null,
1077+
?string $key = null,
10781078
array $data = [],
10791079
bool $choose = false
10801080
): string|Translator {

0 commit comments

Comments
 (0)