2020-08-04 11:25:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Config;
|
2020-05-27 18:46:16 +02:00
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
use App\Authorization\FlatAuthorization;
|
|
|
|
use App\Authorization\GroupModel;
|
2021-05-19 16:35:13 +00:00
|
|
|
use App\Authorization\PermissionModel;
|
2020-08-05 16:10:39 +00:00
|
|
|
use App\Libraries\Breadcrumb;
|
2021-04-02 17:20:02 +00:00
|
|
|
use App\Libraries\Negotiate;
|
|
|
|
use App\Libraries\Router;
|
2020-07-31 16:05:10 +00:00
|
|
|
use App\Models\UserModel;
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\Config\BaseService;
|
2021-04-02 17:20:02 +00:00
|
|
|
use CodeIgniter\HTTP\Request;
|
|
|
|
use CodeIgniter\HTTP\RequestInterface;
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\Model;
|
2021-04-02 17:20:02 +00:00
|
|
|
use CodeIgniter\Router\RouteCollectionInterface;
|
2020-07-31 16:05:10 +00:00
|
|
|
use Myth\Auth\Models\LoginModel;
|
2020-05-27 18:46:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Services Configuration file.
|
|
|
|
*
|
2021-05-19 16:35:13 +00:00
|
|
|
* Services are simply other classes/libraries that the system uses to do its job. This is used by CodeIgniter to allow
|
|
|
|
* the core of the framework to be swapped out easily without affecting the usage within the rest of your application.
|
2020-05-27 18:46:16 +02:00
|
|
|
*
|
2021-05-19 16:35:13 +00:00
|
|
|
* This file holds any application-specific services, or service overrides that you might need. An example has been
|
|
|
|
* included with the general method format you should use for your service methods. For more examples, see the core
|
|
|
|
* Services file at system/Config/Services.php.
|
2020-05-27 18:46:16 +02:00
|
|
|
*/
|
2021-04-02 17:20:02 +00:00
|
|
|
class Services extends BaseService
|
2020-05-27 18:46:16 +02:00
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2021-05-19 16:35:13 +00:00
|
|
|
* The Router class uses a RouteCollection's array of routes, and determines the correct Controller and Method to
|
|
|
|
* execute.
|
2021-05-20 17:13:13 +00:00
|
|
|
*
|
|
|
|
* @noRector PHPStan\Reflection\MissingMethodFromReflectionException
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
|
|
|
public static function router(
|
2021-05-14 17:59:35 +00:00
|
|
|
?RouteCollectionInterface $routes = null,
|
|
|
|
?Request $request = null,
|
2021-04-02 17:20:02 +00:00
|
|
|
bool $getShared = true
|
2021-05-14 17:59:35 +00:00
|
|
|
): Router {
|
2021-04-02 17:20:02 +00:00
|
|
|
if ($getShared) {
|
|
|
|
return static::getSharedInstance('router', $routes, $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
$routes = $routes ?? static::routes();
|
|
|
|
$request = $request ?? static::request();
|
|
|
|
|
|
|
|
return new Router($routes, $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-19 16:35:13 +00:00
|
|
|
* The Negotiate class provides the content negotiation features for working the request to determine correct
|
|
|
|
* language, encoding, charset, and more.
|
2021-05-20 17:13:13 +00:00
|
|
|
*
|
|
|
|
* @noRector PHPStan\Reflection\MissingMethodFromReflectionException
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
2021-05-19 16:35:13 +00:00
|
|
|
public static function negotiator(?RequestInterface $request = null, bool $getShared = true): Negotiate
|
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
if ($getShared) {
|
|
|
|
return static::getSharedInstance('negotiator', $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
$request = $request ?? static::request();
|
|
|
|
|
|
|
|
return new Negotiate($request);
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-07-31 16:05:10 +00:00
|
|
|
public static function authentication(
|
|
|
|
string $lib = 'local',
|
|
|
|
Model $userModel = null,
|
|
|
|
Model $loginModel = null,
|
|
|
|
bool $getShared = true
|
|
|
|
) {
|
|
|
|
if ($getShared) {
|
2021-05-19 16:35:13 +00:00
|
|
|
return self::getSharedInstance('authentication', $lib, $userModel, $loginModel,);
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// config() checks first in app/Config
|
|
|
|
$config = config('Auth');
|
|
|
|
|
|
|
|
$class = $config->authenticationLibs[$lib];
|
|
|
|
|
|
|
|
$instance = new $class($config);
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($userModel === null) {
|
2020-07-31 16:05:10 +00:00
|
|
|
$userModel = new UserModel();
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($loginModel === null) {
|
2020-07-31 16:05:10 +00:00
|
|
|
$loginModel = new LoginModel();
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
return $instance->setUserModel($userModel)
|
|
|
|
->setLoginModel($loginModel);
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-07-31 16:05:10 +00:00
|
|
|
public static function authorization(
|
|
|
|
Model $groupModel = null,
|
|
|
|
Model $permissionModel = null,
|
|
|
|
Model $userModel = null,
|
|
|
|
bool $getShared = true
|
|
|
|
) {
|
|
|
|
if ($getShared) {
|
2021-05-19 16:35:13 +00:00
|
|
|
return self::getSharedInstance('authorization', $groupModel, $permissionModel, $userModel,);
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if ($groupModel === null) {
|
2020-07-31 16:05:10 +00:00
|
|
|
$groupModel = new GroupModel();
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if ($permissionModel === null) {
|
2020-07-31 16:05:10 +00:00
|
|
|
$permissionModel = new PermissionModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance = new FlatAuthorization($groupModel, $permissionModel);
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if ($userModel === null) {
|
2020-07-31 16:05:10 +00:00
|
|
|
$userModel = new UserModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance->setUserModel($userModel);
|
|
|
|
}
|
2020-08-05 16:10:39 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public static function breadcrumb(bool $getShared = true): Breadcrumb
|
2020-08-05 16:10:39 +00:00
|
|
|
{
|
|
|
|
if ($getShared) {
|
|
|
|
return self::getSharedInstance('breadcrumb');
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Breadcrumb();
|
|
|
|
}
|
2020-05-27 18:46:16 +02:00
|
|
|
}
|