Skip to content

Commit 6532545

Browse files
committed
Update
1 parent 4d707d7 commit 6532545

File tree

9 files changed

+55
-42
lines changed

9 files changed

+55
-42
lines changed

src/AbstractAuthController.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
abstract class AbstractAuthController extends BaseController
2121
{
2222
/**
23+
* Login.
24+
*
2325
* @access public
2426
* @return void
2527
*/
@@ -40,6 +42,8 @@ public function isAuthenticated() : bool
4042
}
4143

4244
/**
45+
* Authenticate user.
46+
*
4347
* @access protected
4448
* @param AuthenticationInterface $auth
4549
* @param array $args
@@ -52,25 +56,25 @@ protected function authenticate(AuthenticationInterface $auth, array $args = [])
5256

5357
// Get authentication
5458
$args = $this->mergeArray([
55-
'username' => $this->getRequest('username'),
56-
'password' => $this->getRequest('password')
59+
'user' => $this->getRequest('user'),
60+
'pswd' => $this->getRequest('pswd')
5761
], $args);
5862

59-
$username = (string)$args['username'];
60-
$password = (string)$args['password'];
63+
$user = (string)$args['user'];
64+
$pswd = (string)$args['pswd'];
6165

6266
// Authenticate override
63-
$this->doAction('authenticate', $username);
67+
$this->doAction('authenticate', $user);
6468

6569
// Verify authentication
66-
if ( ($user = $auth->getUser($username)) ) {
70+
if ( ($data = $auth->getUser($user)) ) {
6771

6872
// Check password
69-
if ( $this->isPassword($password, $user['password']) ) {
73+
if ( $this->isPassword($pswd, $data['password']) ) {
7074

7175
// Check password format
7276
if ( $this->applyFilter('auth-strong-pswd', false) ) {
73-
if ( !$this->isStrongPassword($password) ) {
77+
if ( !$this->isStrongPassword($pswd) ) {
7478
// Authenticate failed
7579
$msg = $this->applyFilter('auth-pswd-msg', 'Strong password required');
7680
$msg = $this->translate($msg);
@@ -86,15 +90,15 @@ protected function authenticate(AuthenticationInterface $auth, array $args = [])
8690
// Check valid session
8791
if ( $this->isValidSession() ) {
8892

89-
if ( $auth->hasSecret($username) ) {
90-
$this->setSession('--verify', $username);
93+
if ( $auth->hasSecret($user) ) {
94+
$this->setSession('--verify', $user);
9195
// Authenticate accepted
9296
$msg = $this->applyFilter('auth-accepted-msg', 'Accepted');
9397
$msg = $this->translate($msg);
9498
$this->setResponse($msg, [], 'accepted', 202);
9599

96100
} else {
97-
$this->setSession($auth->getKey(), $user[$auth->getKey()]);
101+
$this->setSession($auth->getKey(), $data[$auth->getKey()]);
98102
// Authenticate success
99103
$msg = $this->applyFilter('auth-success-msg', 'Connected');
100104
$msg = $this->translate($msg);
@@ -108,7 +112,7 @@ protected function authenticate(AuthenticationInterface $auth, array $args = [])
108112
}
109113

110114
// Authenticate failed override
111-
$this->doAction('auth-failed', $username);
115+
$this->doAction('auth-failed', $user);
112116

113117
// Authenticate failed
114118
$msg = $this->applyFilter('auth-error-msg', 'Authentication failed');

src/ApiController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ protected function isGranted(string $token) : bool
9090
]);
9191

9292
// Match authentication
93-
if (
94-
$user == $this->getApiUsername()
95-
&& $pswd == $this->getApiPassword()
96-
) {
93+
if ( $user == $this->getApiUsername() && $pswd == $this->getApiPassword() ) {
9794
return true;
9895
}
9996
}

src/BaseController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public function hasAccess() : bool
4242
$access = false;
4343

4444
// Allow local access
45-
if ( $this->searchString(['127.0.0.1', '::1'], $ip) ) {
45+
if ( $this->hasString(['127.0.0.1', '::1'], $ip) ) {
4646
$access = true;
4747

4848
} else {
4949

5050
// Check allowed IPs
5151
$allowed = $this->applyFilter('access-allowed-ip', $this->getAllowedAccess());
5252
if ( !empty($allowed) ) {
53-
if ( $this->searchString($allowed, $ip) ) {
53+
if ( $this->hasString($allowed, $ip) ) {
5454
$access = true;
5555

5656
} else {
@@ -60,7 +60,7 @@ public function hasAccess() : bool
6060
} else {
6161
// Deny access
6262
$denied = $this->applyFilter('access-denied-ip', $this->getDeniedAccess());
63-
if ( $this->searchString($denied, $ip) ) {
63+
if ( $this->hasString($denied, $ip) ) {
6464
$access = false;
6565

6666
} else {

src/Middleware.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ private function isApiController($class) : bool
287287
*/
288288
private function isAuthController($class) : bool
289289
{
290-
if ( $this->hasItem('parent', $class, __NAMESPACE__ . '\AbstractAuthController') ) {
290+
if ( $this->hasObject('parent', $class, __NAMESPACE__ . '\AbstractAuthController') ) {
291291
return true;
292292

293293
} elseif ( $this->hasAuthMiddlewareInterface($class) ) {
@@ -305,7 +305,7 @@ private function isAuthController($class) : bool
305305
*/
306306
private function isFrontClass($class) : bool
307307
{
308-
return $this->hasItem('parent', $class, __NAMESPACE__ . '\FrontController');
308+
return $this->hasObject('parent', $class, __NAMESPACE__ . '\FrontController');
309309
}
310310

311311
/**
@@ -317,7 +317,7 @@ private function isFrontClass($class) : bool
317317
*/
318318
private function isBackendClass($class) : bool
319319
{
320-
return $this->hasItem('parent', $class, __NAMESPACE__ . '\BackendController');
320+
return $this->hasObject('parent', $class, __NAMESPACE__ . '\BackendController');
321321
}
322322

323323
/**
@@ -329,7 +329,7 @@ private function isBackendClass($class) : bool
329329
*/
330330
private function isApiClass($class) : bool
331331
{
332-
return $this->hasItem('parent', $class, __NAMESPACE__ . '\ApiController');
332+
return $this->hasObject('parent', $class, __NAMESPACE__ . '\ApiController');
333333
}
334334

335335
/**
@@ -341,7 +341,7 @@ private function isApiClass($class) : bool
341341
*/
342342
private function hasBackendInterface($class) : bool
343343
{
344-
return $this->hasItem('interface', $class, 'BackendInterface');
344+
return $this->hasObject('interface', $class, 'BackendInterface');
345345
}
346346

347347
/**
@@ -353,7 +353,7 @@ private function hasBackendInterface($class) : bool
353353
*/
354354
private function hasFrontInterface($class) : bool
355355
{
356-
if ( $this->hasItem('interface', $class, 'FrontInterface') ) {
356+
if ( $this->hasObject('interface', $class, 'FrontInterface') ) {
357357
return true;
358358
}
359359
return false;
@@ -368,7 +368,7 @@ private function hasFrontInterface($class) : bool
368368
*/
369369
private function hasApiInterface($class) : bool
370370
{
371-
return $this->hasItem('interface', $class, 'ApiInterface');
371+
return $this->hasObject('interface', $class, 'ApiInterface');
372372
}
373373

374374
/**
@@ -380,7 +380,7 @@ private function hasApiInterface($class) : bool
380380
*/
381381
private function hasAuthMiddlewareInterface($class) : bool
382382
{
383-
return $this->hasItem('interface', $class, 'AuthMiddlewareInterface');
383+
return $this->hasObject('interface', $class, 'AuthMiddlewareInterface');
384384
}
385385

386386
/**
@@ -392,7 +392,7 @@ private function hasAuthMiddlewareInterface($class) : bool
392392
private function isModule() : bool
393393
{
394394
$module = $this->lowercase($this->match['target']);
395-
if ( $this->searchString($module, 'module') ) {
395+
if ( $this->hasString($module, 'module') ) {
396396
return true;
397397
}
398398
return false;

src/Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private function loadModules() : void
119119
if ( $config->enable ) {
120120
$basename = $this->basename($name);
121121
$namespace = "{$this->getModuleNamespace()}{$basename}\\{$basename}";
122-
if ( $this->hasFile("{$name}/{$basename}Module.php") ) {
122+
if ( $this->isFile("{$name}/{$basename}Module.php") ) {
123123
$module = "{$namespace}Module";
124124
new $module;
125125
}

src/Orm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ private function formatColumns($columns) : string
974974
if ( $columns == '*' || empty($columns) ) {
975975
return '*';
976976
}
977-
if ( $this->searchString($columns, ',') ) {
977+
if ( $this->hasString($columns, ',') ) {
978978
$columns = explode(',', $columns);
979979

980980
} else {

src/TraitConfiguration.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __wakeup()
6565
protected function initConfig()
6666
{
6767
// Parse config file
68-
if ( $this->hasFile(($path = $this->getConfigFile())) ) {
68+
if ( $this->isFile(($path = $this->getConfigFile())) ) {
6969
Validator::checkConfig(($config = $this->parseJson($path)));
7070
$this->global = $config;
7171

@@ -77,7 +77,7 @@ protected function initConfig()
7777
}
7878

7979
// Set routes config
80-
if ( $this->hasFile(($path = $this->getRoutesFile())) ) {
80+
if ( $this->isFile(($path = $this->getRoutesFile())) ) {
8181
Validator::checkRouteConfig(($routes = $this->parseJson($path, true)));
8282
$this->routes = $routes;
8383
}
@@ -153,7 +153,7 @@ protected function getConfigFile() : string
153153
protected function loadConfig(string $config, bool $isArray = false)
154154
{
155155
$dir = "{$this->getAppDir()}/Storage/config";
156-
if ( $this->hasFile(($json = "{$dir}/{$config}.json")) ) {
156+
if ( $this->isFile(($json = "{$dir}/{$config}.json")) ) {
157157
return $this->decodeJson($this->readfile($json), $isArray);
158158
}
159159
return false;
@@ -749,7 +749,7 @@ protected function isDebug() : bool
749749
protected function isAdmin() : bool
750750
{
751751
$url = Server::getBaseUrl();
752-
return $this->searchString($url, '/admin/');
752+
return $this->hasString($url, '/admin/');
753753
}
754754

755755
/**

src/TraitException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ trait TraitException
3131
public function throwError(int $code = 404, ?string $message = null) : void
3232
{
3333
$render = true;
34-
if ( $this->hasItem('method', $this, 'getApiBaseUrl') ) {
34+
if ( $this->hasObject('method', $this, 'getApiBaseUrl') ) {
3535
$url = $this->getServer('request-uri');
3636
$api = $this->getApiBaseUrl();
37-
if ( $this->searchString($url, $api) ) {
37+
if ( $this->hasString($url, $api) ) {
3838
$render = false;
3939
}
4040
}

src/View.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,31 @@
1515

1616
namespace FloatPHP\Kernel;
1717

18-
use FloatPHP\Interfaces\Kernel\{
19-
ViewInterface,
20-
CallableInterface
21-
};
18+
use FloatPHP\Interfaces\Kernel\{ViewInterface, CallableInterface};
2219

20+
/**
21+
* View controller.
22+
*
23+
* - Hooking
24+
* - Rendering
25+
* - Authentication
26+
* - Configuration
27+
* - Translation
28+
* - Formatting
29+
* - IO
30+
* - Caching
31+
* - Requesting
32+
* - Viewing
33+
* - Throwing
34+
*/
2335
class View extends Base implements ViewInterface
2436
{
2537
use \FloatPHP\Helpers\Framework\inc\TraitViewable;
2638

2739
/**
2840
* @access private
29-
* @var array $callables
30-
* @var array $content
41+
* @var array $callables, Custom view functions
42+
* @var array $content, Global view content
3143
*/
3244
private $callables = [];
3345
private $content = [];

0 commit comments

Comments
 (0)