Skip to content

Commit ec0174b

Browse files
author
Anton
authored
Merge pull request #475 from bluzphp/develop
Added support PHP 8
2 parents 3aaaf2c + 8659fe0 commit ec0174b

File tree

19 files changed

+1745
-385
lines changed

19 files changed

+1745
-385
lines changed

src/Common/Singleton.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,4 @@ private function __construct()
6868
private function __clone()
6969
{
7070
}
71-
72-
/**
73-
* Disabled by access level
74-
*/
75-
private function __wakeup()
76-
{
77-
}
7871
}

src/Router/Router.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ protected function urlCustom(string $module, string $controller, array $params):
408408
$getParams[$key] = $value;
409409
continue;
410410
}
411+
if (is_numeric($value)) {
412+
$value = (string) $value;
413+
}
411414
$url = str_replace('{$' . $key . '}', $value, $url, $replaced);
412415
// if not replaced, setup param as GET
413416
if (!$replaced) {

src/Session/Adapter/Cache.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
/**
1818
* Cache session handler
1919
*
20-
* @todo Migrate to {@link https://github.com/php-cache/session-handler PSR-6 Session handler}
2120
* @package Bluz\Session\Adapter
2221
*/
2322
class Cache extends AbstractAdapter implements \SessionHandlerInterface

src/Session/Session.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,27 @@ public function getAdapter(): string
262262
*/
263263
protected function init(): bool
264264
{
265+
if ($this->sessionHandler) {
266+
return true;
267+
}
268+
265269
if ('files' === $this->adapter) {
270+
$this->sessionHandler = new \SessionHandler();
266271
// try to apply settings
267272
if ($settings = $this->getOption('settings', 'files')) {
268273
$this->setSavePath($settings['save_path']);
269274
}
270-
return true;
275+
return session_set_save_handler($this->sessionHandler);
271276
}
272-
if (null === $this->sessionHandler) {
273-
$adapterClass = '\\Bluz\\Session\\Adapter\\' . ucfirst($this->adapter);
274-
if (!class_exists($adapterClass) || !is_subclass_of($adapterClass, SessionHandlerInterface::class)) {
275-
throw new ComponentException("Class for session adapter `{$this->adapter}` not found");
276-
}
277-
$settings = $this->getOption('settings', $this->adapter) ?: [];
278277

279-
$this->adapter = new $adapterClass($settings);
280-
return session_set_save_handler($this->adapter);
278+
$adapterClass = '\\Bluz\\Session\\Adapter\\' . ucfirst($this->adapter);
279+
if (!class_exists($adapterClass) || !is_subclass_of($adapterClass, SessionHandlerInterface::class)) {
280+
throw new ComponentException("Class for session adapter `{$this->adapter}` not found");
281281
}
282-
return true;
282+
$settings = $this->getOption('settings', $this->adapter) ?: [];
283+
284+
$this->sessionHandler = new $adapterClass($settings);
285+
return session_set_save_handler($this->sessionHandler);
283286
}
284287

285288
/**

src/Validator/Rule/AbstractFilterRule.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,9 @@ abstract protected function validateClean($input);
3838
* Setup validation rule
3939
*
4040
* @param string $additionalChars
41-
*
42-
* @throws \Bluz\Validator\Exception\ComponentException
4341
*/
44-
public function __construct($additionalChars = '')
42+
public function __construct(string $additionalChars = '')
4543
{
46-
if (!is_string($additionalChars)) {
47-
throw new ComponentException('Invalid list of additional characters to be loaded');
48-
}
4944
$this->additionalChars .= $additionalChars;
5045
}
5146

src/Validator/Rule/BetweenInclusiveRule.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ class BetweenInclusiveRule extends BetweenRule
3030
*/
3131
public function getDescription(): string
3232
{
33-
return __('must be inclusive between "%1" and "%2"', $this->minValue, $this->maxValue);
33+
34+
$min = $this->minValue;
35+
$max = $this->maxValue;
36+
37+
if ($min instanceof \DateTime) {
38+
$min = date_format($min, 'r');
39+
}
40+
if ($max instanceof \DateTime) {
41+
$max = date_format($max, 'r');
42+
}
43+
44+
return __('must be inclusive between "%1s" and "%2s"', $min, $max);
3445
}
3546
}

src/Validator/Rule/BetweenRule.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ public function validate($input): bool
7272
*/
7373
public function getDescription(): string
7474
{
75-
return __('must be between "%1" and "%2"', $this->minValue, $this->maxValue);
75+
$min = $this->minValue;
76+
$max = $this->maxValue;
77+
78+
if ($min instanceof \DateTime) {
79+
$min = date_format($min, 'r');
80+
}
81+
if ($max instanceof \DateTime) {
82+
$max = date_format($max, 'r');
83+
}
84+
85+
return __('must be between "%1s" and "%2s"', $min, $max);
7686
}
7787
}

src/Validator/Rule/CreditCardRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CreditCardRule extends AbstractRule
3333
*/
3434
public function validate($input): bool
3535
{
36-
$input = preg_replace('([ \.-])', '', $input);
36+
$input = preg_replace('([ \.-])', '', (string) $input);
3737

3838
if (!is_numeric($input)) {
3939
return false;

src/Validator/Rule/NegativeRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ class NegativeRule extends AbstractRule
3232
*/
3333
public function validate($input): bool
3434
{
35-
return $input < 0;
35+
return is_numeric($input) && $input < 0;
3636
}
3737
}

src/Validator/Rule/PositiveRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ class PositiveRule extends AbstractRule
3232
*/
3333
public function validate($input): bool
3434
{
35-
return $input > 0;
35+
return is_numeric($input) && $input > 0;
3636
}
3737
}

0 commit comments

Comments
 (0)