Skip to content

Commit 4d707d7

Browse files
committed
Update
PHP ^8.2 | PSR
1 parent f6c1bae commit 4d707d7

16 files changed

+313
-325
lines changed

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "floatphp/kernel",
3-
"version" : "1.2.4",
3+
"version" : "1.3.0",
44
"type": "library",
55
"description": "FloatPHP Kernel Components",
66
"keywords": ["php","micro-framework","framework","PSR","ORM","jakiboy","composer"],
@@ -19,11 +19,11 @@
1919
"ext-intl": "*",
2020
"twig/twig": "^3.14.2",
2121
"justinrainbow/json-schema": "^6.0.0",
22-
"floatphp/classes": "^1.2.0",
23-
"floatphp/helpers": "^1.2.0",
24-
"floatphp/interfaces": "^1.2.0",
25-
"floatphp/exceptions": "^1.2.0",
26-
"floatphp/cli": "^1.2.0"
22+
"floatphp/classes": "^1.3.0",
23+
"floatphp/helpers": "^1.3.0",
24+
"floatphp/interfaces": "^1.3.0",
25+
"floatphp/exceptions": "^1.3.0",
26+
"floatphp/cli": "^1.3.0"
2727
},
2828
"autoload": {
2929
"psr-4" : {

src/AbstractAuthController.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author : Jakiboy
44
* @package : FloatPHP
55
* @subpackage : Kernel Component
6-
* @version : 1.2.x
6+
* @version : 1.3.x
77
* @copyright : (c) 2018 - 2024 Jihad Sinnaour <[email protected]>
88
* @link : https://floatphp.com
99
* @license : MIT
@@ -38,17 +38,17 @@ public function isAuthenticated() : bool
3838
}
3939
return false;
4040
}
41-
41+
4242
/**
4343
* @access protected
4444
* @param AuthenticationInterface $auth
4545
* @param array $args
4646
* @return void
4747
*/
48-
protected function authenticate(AuthenticationInterface $auth, array $args = [])
48+
protected function authenticate(AuthenticationInterface $auth, array $args = []) : void
4949
{
5050
// Security
51-
$this->verifyRequest(true);
51+
$this->verifyRequest(force: true);
5252

5353
// Get authentication
5454
$args = $this->mergeArray([
@@ -69,10 +69,10 @@ protected function authenticate(AuthenticationInterface $auth, array $args = [])
6969
if ( $this->isPassword($password, $user['password']) ) {
7070

7171
// Check password format
72-
if ( $this->applyFilter('auth-strong-password', false) ) {
72+
if ( $this->applyFilter('auth-strong-pswd', false) ) {
7373
if ( !$this->isStrongPassword($password) ) {
7474
// Authenticate failed
75-
$msg = $this->applyFilter('auth-password-message', 'Strong password required');
75+
$msg = $this->applyFilter('auth-pswd-msg', 'Strong password required');
7676
$msg = $this->translate($msg);
7777
$this->setResponse($msg, [], 'warning');
7878
}
@@ -89,14 +89,14 @@ protected function authenticate(AuthenticationInterface $auth, array $args = [])
8989
if ( $auth->hasSecret($username) ) {
9090
$this->setSession('--verify', $username);
9191
// Authenticate accepted
92-
$msg = $this->applyFilter('auth-accepted-message', 'Accepted');
92+
$msg = $this->applyFilter('auth-accepted-msg', 'Accepted');
9393
$msg = $this->translate($msg);
9494
$this->setResponse($msg, [], 'accepted', 202);
9595

9696
} else {
97-
$this->setSession($auth->getKey(),$user[$auth->getKey()]);
97+
$this->setSession($auth->getKey(), $user[$auth->getKey()]);
9898
// Authenticate success
99-
$msg = $this->applyFilter('auth-success-message', 'Connected');
99+
$msg = $this->applyFilter('auth-success-msg', 'Connected');
100100
$msg = $this->translate($msg);
101101
$this->setResponse($msg);
102102
}
@@ -111,7 +111,7 @@ protected function authenticate(AuthenticationInterface $auth, array $args = [])
111111
$this->doAction('auth-failed', $username);
112112

113113
// Authenticate failed
114-
$msg = $this->applyFilter('auth-error-message', 'Authentication failed');
114+
$msg = $this->applyFilter('auth-error-msg', 'Authentication failed');
115115
$msg = $this->translate($msg);
116116
$this->setResponse($msg, [], 'error', 401);
117117
}

src/ApiController.php

+23-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author : Jakiboy
44
* @package : FloatPHP
55
* @subpackage : Kernel Component
6-
* @version : 1.2.x
6+
* @version : 1.3.x
77
* @copyright : (c) 2018 - 2024 Jihad Sinnaour <[email protected]>
88
* @link : https://floatphp.com
99
* @license : MIT
@@ -30,35 +30,37 @@ public function isHttpAuthenticated() : bool
3030
$this->initConfig();
3131

3232
// Basic authentication
33-
if ( $this->applyFilter('basic-authentication', true) ) {
33+
if ( $this->applyFilter('basic-auth', true) ) {
3434
if ( $this->isBasicAuth() ) {
3535

3636
$user = $this->getBasicAuthUser();
3737
$pswd = $this->getBasicAuthPwd();
3838

39-
// API authenticate override
39+
// API authenticate override
4040
$this->doAction('api-authenticate', [
4141
'username' => $user,
4242
'address' => $this->getServerIp(),
4343
'method' => 'basic'
4444
]);
4545

46-
if ( $user == $this->getApiUsername()
47-
&& $pswd == $this->getApiPassword() ) {
48-
return true;
49-
}
46+
if (
47+
$user == $this->getApiUsername()
48+
&& $pswd == $this->getApiPassword()
49+
) {
50+
return true;
51+
}
5052
}
5153
}
5254

5355
// Bearer token authentication
54-
if ( $this->applyFilter('bearer-authentication', true) ) {
56+
if ( $this->applyFilter('bearer-auth', true) ) {
5557
if ( ($token = $this->getBearerToken()) ) {
56-
return $this->isGranted($token);
58+
return $this->isGranted($token);
5759
}
5860
}
5961

6062
// Extra authentication
61-
if ( $this->applyFilter('extra-authentication', false) ) {
63+
if ( $this->applyFilter('extra-auth', false) ) {
6264
return $this->applyFilter('extra-authenticated', false);
6365
}
6466

@@ -74,25 +76,27 @@ public function isHttpAuthenticated() : bool
7476
*/
7577
protected function isGranted(string $token) : bool
7678
{
77-
$access = $this->getAccessToken($token, $this->getSecret(true));
78-
$user = $access['user'] ?? false;
79-
$pswd = $access['pswd'] ?? false;
79+
$access = $this->getAccessToken($token, $this->getSecret(true));
80+
$user = $access['user'] ?? false;
81+
$pswd = $access['pswd'] ?? false;
8082

81-
if ( $user && $pswd ) {
83+
if ( $user && $pswd ) {
8284

83-
// API authenticate override
85+
// API authenticate override
8486
$this->doAction('api-authenticate', [
8587
'username' => $user,
8688
'address' => $this->getServerIp(),
8789
'method' => 'token'
8890
]);
8991

9092
// Match authentication
91-
if ( $user == $this->getApiUsername()
92-
&& $pswd == $this->getApiPassword() ) {
93-
return true;
93+
if (
94+
$user == $this->getApiUsername()
95+
&& $pswd == $this->getApiPassword()
96+
) {
97+
return true;
9498
}
95-
}
99+
}
96100

97101
return false;
98102
}

src/BackendController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author : Jakiboy
44
* @package : FloatPHP
55
* @subpackage : Kernel Component
6-
* @version : 1.2.x
6+
* @version : 1.3.x
77
* @copyright : (c) 2018 - 2024 Jihad Sinnaour <[email protected]>
88
* @link : https://floatphp.com
99
* @license : MIT

src/Base.php

+24-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author : Jakiboy
44
* @package : FloatPHP
55
* @subpackage : Kernel Component
6-
* @version : 1.2.x
6+
* @version : 1.3.x
77
* @copyright : (c) 2018 - 2024 Jihad Sinnaour <[email protected]>
88
* @link : https://floatphp.com
99
* @license : MIT
@@ -27,13 +27,13 @@ class Base
2727
\FloatPHP\Helpers\Framework\inc\TraitThrowable,
2828
\FloatPHP\Helpers\Framework\inc\TraitAuthenticatable;
2929

30-
/**
30+
/**
3131
* Get token (CSRF).
3232
*
33-
* @access protected
34-
* @param string $action
35-
* @return string
36-
*/
33+
* @access protected
34+
* @param string $action
35+
* @return string
36+
*/
3737
protected function getToken(?string $action = null) : string
3838
{
3939
// Set filtered token data
@@ -63,7 +63,7 @@ protected function getToken(?string $action = null) : string
6363
$session = $this->getSession('--token') ?: [];
6464

6565
// Set session token data
66-
if ( !isset($session[$token])) {
66+
if ( !isset($session[$token]) ) {
6767
$session[$token] = $data;
6868
$this->setSession('--token', $session);
6969
}
@@ -84,10 +84,10 @@ protected function getLanguage() : string
8484
if ( $this->hasRequest('--lang') ) {
8585
return $this->getRequest('--lang');
8686
}
87-
if ( !($lang = $this->getSession('--lang')) ) {
88-
$lang = $this->getSession('--default-lang');
89-
}
90-
return (string)$lang;
87+
if ( !($lang = $this->getSession('--lang')) ) {
88+
$lang = $this->getSession('--default-lang');
89+
}
90+
return (string)$lang;
9191
}
9292

9393
/**
@@ -111,17 +111,17 @@ protected function translate(string $string) : string
111111
/**
112112
* Translate array of strings.
113113
*
114-
* @access protected
115-
* @param array $strings
116-
* @return array
117-
*/
118-
protected function translateArray(array $strings = []) : array
119-
{
120-
foreach ($strings as $key => $value) {
121-
$strings[$key] = $this->translate($value);
122-
}
123-
return $strings;
124-
}
114+
* @access protected
115+
* @param array $strings
116+
* @return array
117+
*/
118+
protected function translateArray(array $strings = []) : array
119+
{
120+
foreach ($strings as $key => $value) {
121+
$strings[$key] = $this->translate($value);
122+
}
123+
return $strings;
124+
}
125125

126126
/**
127127
* Translate string with variables,
@@ -152,9 +152,9 @@ public function translateVar(string $string, $vars = null) : string
152152
* @param array $strings
153153
* @return array
154154
*/
155-
protected function translateDeepStrings(array $strings)
155+
protected function translateDeepStrings(array $strings) : array
156156
{
157-
$this->recursiveArray($strings, function(&$string) {
157+
$this->recursiveArray($strings, function (&$string) : void {
158158
if ( $this->isType('string', $string) ) {
159159
$string = $this->translate($string);
160160
}

0 commit comments

Comments
 (0)