diff --git a/bin/post-install.php b/bin/post-install.php index 7d1f77c..680e95a 100644 --- a/bin/post-install.php +++ b/bin/post-install.php @@ -1,7 +1,7 @@ Repository\RoleRepository::class, ], 'factories' => [ - Installer\Install::class => Factory\Installer\InstallFactory::class, - Installer\Update::class => Factory\Installer\UpdateFactory::class, - Installer\Remove::class => Factory\Installer\RemoveFactory::class, - Repository\AccountRepository::class => Factory\Repository\AccountRepositoryFactory::class, - Repository\PermissionRepository::class => Factory\Repository\PermissionRepositoryFactory::class, - Repository\ProfileRepository::class => Factory\Repository\ProfileRepositoryFactory::class, - Repository\RoleRepository::class => Factory\Repository\RoleRepositoryFactory::class, - Middleware\AuthenticationMiddleware::class => Factory\Middleware\AuthenticationMiddlewareFactory::class, - Middleware\AuthorizationMiddleware::class => Factory\Middleware\AuthorizationMiddlewareFactory::class, - Middleware\AvatarUploadMiddleware::class => Factory\Middleware\AvatarUploadMiddlewareFactory::class, - Middleware\ValidationMiddleware::class => Factory\Middleware\ValidationMiddlewareFactory::class, - Middleware\RequestPreparationMiddleware::class => Factory\Middleware\RequestPreparationMiddlewareFactory::class, - Middleware\InstallerMiddleware::class => Factory\Middleware\InstallerMiddlewareFactory::class, - Middleware\ErrorMiddleware::class => Factory\Middleware\ErrorMiddlewareFactory::class, - Validator\EmailValidator::class => Factory\Validator\EmailValidatorFactory::class, - Validator\IdentityValidator::class => Factory\Validator\IdentityValidatorFactory::class, - Validator\NameValidator::class => Factory\Validator\NameValidatorFactory::class, - Validator\MobileValidator::class => Factory\Validator\MobileValidatorFactory::class, - Validator\OtpValidator::class => Factory\Validator\OtpValidatorFactory::class, - Validator\PasswordValidator::class => Factory\Validator\PasswordValidatorFactory::class, - Service\AccountService::class => Factory\Service\AccountServiceFactory::class, - Service\AvatarService::class => Factory\Service\AvatarServiceFactory::class, - Service\TokenService::class => Factory\Service\TokenServiceFactory::class, - Service\CacheService::class => Factory\Service\CacheServiceFactory::class, - Service\RoleService::class => Factory\Service\RoleServiceFactory::class, + Repository\AccountRepository::class => Factory\Repository\AccountRepositoryFactory::class, + Repository\PermissionRepository::class => Factory\Repository\PermissionRepositoryFactory::class, + Repository\ProfileRepository::class => Factory\Repository\ProfileRepositoryFactory::class, + Repository\RoleRepository::class => Factory\Repository\RoleRepositoryFactory::class, + Middleware\AuthenticationMiddleware::class => Factory\Middleware\AuthenticationMiddlewareFactory::class, + Middleware\AuthorizationMiddleware::class => Factory\Middleware\AuthorizationMiddlewareFactory::class, + Middleware\AvatarUploadMiddleware::class => Factory\Middleware\AvatarUploadMiddlewareFactory::class, + Middleware\ValidationMiddleware::class => Factory\Middleware\ValidationMiddlewareFactory::class, + Validator\EmailValidator::class => Factory\Validator\EmailValidatorFactory::class, + Validator\IdentityValidator::class => Factory\Validator\IdentityValidatorFactory::class, + Validator\NameValidator::class => Factory\Validator\NameValidatorFactory::class, + Validator\MobileValidator::class => Factory\Validator\MobileValidatorFactory::class, + Validator\OtpValidator::class => Factory\Validator\OtpValidatorFactory::class, + Validator\PasswordValidator::class => Factory\Validator\PasswordValidatorFactory::class, + Service\AccountService::class => Factory\Service\AccountServiceFactory::class, + Service\AvatarService::class => Factory\Service\AvatarServiceFactory::class, + Service\TokenService::class => Factory\Service\TokenServiceFactory::class, + Service\RoleService::class => Factory\Service\RoleServiceFactory::class, Service\PermissionService::class => Factory\Service\PermissionServiceFactory::class, - Service\UtilityService::class => Factory\Service\UtilityServiceFactory::class, Service\HistoryService::class => Factory\Service\HistoryServiceFactory::class, Service\ExportService::class => Factory\Service\ExportServiceFactory::class, - Service\TranslatorService::class => Factory\Service\TranslatorServiceFactory::class, - Service\InstallerService::class => Factory\Service\InstallerServiceFactory::class, Handler\Admin\Profile\AddHandler::class => Factory\Handler\Admin\Profile\AddHandlerFactory::class, Handler\Admin\Profile\EditHandler::class => Factory\Handler\Admin\Profile\EditHandlerFactory::class, Handler\Admin\Profile\ListHandler::class => Factory\Handler\Admin\Profile\ListHandlerFactory::class, @@ -89,7 +81,6 @@ Handler\Api\Authentication\Oauth\SettingHandler::class => Factory\Handler\Api\Authentication\Oauth\SettingHandlerFactory::class, Handler\Api\Captcha\ReCaptcha\VerifyHandler::class => Factory\Handler\Api\Captcha\ReCaptcha\VerifyHandlerFactory::class, Handler\Api\Avatar\UploadHandler::class => Factory\Handler\Api\Avatar\UploadHandlerFactory::class, - Handler\ErrorHandler::class => Factory\Handler\ErrorHandlerFactory::class, Handler\InstallerHandler::class => Factory\Handler\InstallerHandlerFactory::class, ], ], @@ -124,12 +115,12 @@ 'permissions' => 'user-view', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Profile\ViewHandler::class ), ], @@ -149,13 +140,13 @@ 'validator' => 'edit', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, Middleware\ValidationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Profile\UpdateHandler::class ), ], @@ -175,12 +166,12 @@ 'validator' => 'device-token', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\ValidationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Profile\DeviceTokenHandler::class ), ], @@ -199,11 +190,11 @@ 'permissions' => 'user-view', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Profile\HistoryHandler::class ), ], @@ -232,13 +223,13 @@ 'permissions' => 'user-avatar-upload', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, Middleware\AvatarUploadMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Avatar\UploadHandler::class ), ], @@ -268,13 +259,13 @@ 'validator' => 'password-add', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, Middleware\ValidationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Password\AddHandler::class ), ], @@ -294,13 +285,13 @@ 'validator' => 'password-update', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, Middleware\ValidationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Password\UpdateHandler::class ), ], @@ -329,10 +320,10 @@ 'validator' => 'login', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\ValidationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\LoginHandler::class ), ], @@ -351,11 +342,11 @@ 'permissions' => 'user-logout', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, //Middleware\AuthorizationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\LogoutHandler::class ), ], @@ -373,10 +364,10 @@ 'validator' => 'add', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\ValidationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\RegisterHandler::class ), ], @@ -401,10 +392,10 @@ 'validator' => 'email-request', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\ValidationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Email\RequestHandler::class ), ], @@ -422,10 +413,10 @@ 'validator' => 'email-verify', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\ValidationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Email\VerifyHandler::class ), ], @@ -452,10 +443,10 @@ 'validator' => 'mobile-request', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\ValidationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Mobile\RequestHandler::class ), ], @@ -473,10 +464,10 @@ 'validator' => 'mobile-verify', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\ValidationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Mobile\VerifyHandler::class ), ], @@ -502,10 +493,10 @@ 'handler' => 'request', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Mfa\RequestHandler::class ), ], @@ -522,10 +513,10 @@ 'handler' => 'verify', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Mfa\VerifyHandler::class ), ], @@ -551,9 +542,9 @@ 'handler' => 'google', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Oauth\GoogleHandler::class ), ], @@ -570,9 +561,9 @@ 'handler' => 'microsoft', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Oauth\MicrosoftHandler::class ), ], @@ -589,9 +580,9 @@ 'handler' => 'oauth2', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Oauth\Oauth2Handler::class ), ], @@ -608,9 +599,9 @@ 'handler' => 'oauth', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Authentication\Oauth\SettingHandler::class ), ], @@ -646,9 +637,9 @@ 'handler' => 'verify', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Api\Captcha\ReCaptcha\VerifyHandler::class ), ], @@ -688,12 +679,12 @@ 'permissions' => 'user-profile-list', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\ListHandler::class ), ], @@ -712,13 +703,13 @@ 'validator' => 'add', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, Middleware\ValidationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\AddHandler::class ), ], @@ -737,13 +728,13 @@ 'validator' => 'edit', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, Middleware\ValidationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\EditHandler::class ), ], @@ -762,13 +753,13 @@ 'validator' => 'edit', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, Middleware\ValidationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\StatusHandler::class ), ], @@ -787,13 +778,13 @@ 'validator' => 'password-admin', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, Middleware\ValidationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\PasswordHandler::class ), ], @@ -812,12 +803,12 @@ 'validator' => 'password-admin', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\DeleteHandler::class ), ], @@ -835,12 +826,12 @@ 'permissions' => 'user-profile-view', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\ViewHandler::class ), ], @@ -858,12 +849,12 @@ 'permissions' => 'user-profile-export', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\ExportHandler::class ), ], @@ -881,12 +872,12 @@ 'permissions' => 'user-profile-clean', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Profile\CleanHandler::class ), ], @@ -914,12 +905,12 @@ 'permissions' => 'user-role-list', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Role\ListHandler::class ), ], @@ -937,12 +928,12 @@ 'permissions' => 'user-role-add', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Role\AddHandler::class ), ], @@ -960,12 +951,12 @@ 'permissions' => 'user-role-edit', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Role\EditHandler::class ), ], @@ -983,12 +974,12 @@ 'permissions' => 'user-role-delete', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Role\DeleteHandler::class ), ], @@ -1023,12 +1014,12 @@ 'permissions' => 'user-permission-resource-list', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Permission\Resource\ListHandler::class ), ], @@ -1055,12 +1046,12 @@ 'permissions' => 'user-permission-page-list', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Permission\Page\ListHandler::class ), ], @@ -1087,12 +1078,12 @@ 'permissions' => 'user-permission-role-list', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Permission\Role\ListHandler::class ), ], @@ -1122,12 +1113,12 @@ 'permissions' => 'user-cache-list', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Cache\ListHandler::class ), ], @@ -1145,12 +1136,12 @@ 'permissions' => 'user-cache-view', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Cache\ViewHandler::class ), ], @@ -1168,12 +1159,12 @@ 'permissions' => 'user-cache-persist', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Cache\PersistHandler::class ), ], @@ -1191,12 +1182,12 @@ 'permissions' => 'user-cache-delete', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, Middleware\AuthorizationMiddleware::class, LoggerRequestResponseMiddleware::class, - Middleware\ErrorMiddleware::class, + ErrorMiddleware::class, Handler\Admin\Cache\DeleteHandler::class ), ], @@ -1216,11 +1207,11 @@ 'handler' => 'installer', 'controller' => PipeSpec::class, 'middleware' => new PipeSpec( - Middleware\RequestPreparationMiddleware::class, + RequestPreparationMiddleware::class, SecurityMiddleware::class, Middleware\AuthenticationMiddleware::class, - Middleware\InstallerMiddleware::class, - Middleware\ErrorMiddleware::class, + InstallerMiddleware::class, + ErrorMiddleware::class, Handler\InstallerHandler::class ), ], diff --git a/src/Factory/Handler/Admin/Cache/DeleteHandlerFactory.php b/src/Factory/Handler/Admin/Cache/DeleteHandlerFactory.php index e30315f..cda2515 100644 --- a/src/Factory/Handler/Admin/Cache/DeleteHandlerFactory.php +++ b/src/Factory/Handler/Admin/Cache/DeleteHandlerFactory.php @@ -3,13 +3,13 @@ namespace User\Factory\Handler\Admin\Cache; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use User\Handler\Admin\Cache\DeleteHandler; -use User\Service\CacheService; class DeleteHandlerFactory implements FactoryInterface { diff --git a/src/Factory/Handler/Admin/Cache/ListHandlerFactory.php b/src/Factory/Handler/Admin/Cache/ListHandlerFactory.php index 4670057..61a8b50 100644 --- a/src/Factory/Handler/Admin/Cache/ListHandlerFactory.php +++ b/src/Factory/Handler/Admin/Cache/ListHandlerFactory.php @@ -3,13 +3,13 @@ namespace User\Factory\Handler\Admin\Cache; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use User\Handler\Admin\Cache\ListHandler; -use User\Service\CacheService; class ListHandlerFactory implements FactoryInterface { diff --git a/src/Factory/Handler/Admin/Cache/PersistHandlerFactory.php b/src/Factory/Handler/Admin/Cache/PersistHandlerFactory.php index 87f2237..98c5517 100644 --- a/src/Factory/Handler/Admin/Cache/PersistHandlerFactory.php +++ b/src/Factory/Handler/Admin/Cache/PersistHandlerFactory.php @@ -3,13 +3,13 @@ namespace User\Factory\Handler\Admin\Cache; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use User\Handler\Admin\Cache\PersistHandler; -use User\Service\CacheService; class PersistHandlerFactory implements FactoryInterface { diff --git a/src/Factory/Handler/Admin/Cache/ViewHandlerFactory.php b/src/Factory/Handler/Admin/Cache/ViewHandlerFactory.php index 10ba770..c029a52 100644 --- a/src/Factory/Handler/Admin/Cache/ViewHandlerFactory.php +++ b/src/Factory/Handler/Admin/Cache/ViewHandlerFactory.php @@ -3,13 +3,13 @@ namespace User\Factory\Handler\Admin\Cache; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use User\Handler\Admin\Cache\ViewHandler; -use User\Service\CacheService; class ViewHandlerFactory implements FactoryInterface { diff --git a/src/Factory/Handler/ErrorHandlerFactory.php b/src/Factory/Handler/ErrorHandlerFactory.php deleted file mode 100644 index 7524f35..0000000 --- a/src/Factory/Handler/ErrorHandlerFactory.php +++ /dev/null @@ -1,31 +0,0 @@ -get(ResponseFactoryInterface::class), - $container->get(StreamFactoryInterface::class) - ); - } -} \ No newline at end of file diff --git a/src/Factory/Handler/InstallerHandlerFactory.php b/src/Factory/Handler/InstallerHandlerFactory.php index 562e558..7c0a5e1 100644 --- a/src/Factory/Handler/InstallerHandlerFactory.php +++ b/src/Factory/Handler/InstallerHandlerFactory.php @@ -3,13 +3,13 @@ namespace User\Factory\Handler; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\InstallerService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use User\Handler\InstallerHandler; -use User\Service\InstallerService; class InstallerHandlerFactory implements FactoryInterface { diff --git a/src/Factory/Installer/InstallFactory.php b/src/Factory/Installer/InstallFactory.php deleted file mode 100644 index f09cd6c..0000000 --- a/src/Factory/Installer/InstallFactory.php +++ /dev/null @@ -1,25 +0,0 @@ -get(InstallerService::class) - ); - } -} \ No newline at end of file diff --git a/src/Factory/Installer/RemoveFactory.php b/src/Factory/Installer/RemoveFactory.php deleted file mode 100644 index 45d91db..0000000 --- a/src/Factory/Installer/RemoveFactory.php +++ /dev/null @@ -1,25 +0,0 @@ -get(InstallerService::class) - ); - } -} \ No newline at end of file diff --git a/src/Factory/Installer/UpdateFactory.php b/src/Factory/Installer/UpdateFactory.php deleted file mode 100644 index bc4f3b4..0000000 --- a/src/Factory/Installer/UpdateFactory.php +++ /dev/null @@ -1,25 +0,0 @@ -get(InstallerService::class) - ); - } -} \ No newline at end of file diff --git a/src/Factory/Middleware/AuthenticationMiddlewareFactory.php b/src/Factory/Middleware/AuthenticationMiddlewareFactory.php index 95c89f1..47c2ae0 100644 --- a/src/Factory/Middleware/AuthenticationMiddlewareFactory.php +++ b/src/Factory/Middleware/AuthenticationMiddlewareFactory.php @@ -3,16 +3,16 @@ namespace User\Factory\Middleware; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Handler\ErrorHandler; use Pi\Core\Security\Account\AccountLocked; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; -use User\Handler\ErrorHandler; use User\Middleware\AuthenticationMiddleware; use User\Service\AccountService; -use User\Service\CacheService; use User\Service\TokenService; class AuthenticationMiddlewareFactory implements FactoryInterface diff --git a/src/Factory/Middleware/AuthorizationMiddlewareFactory.php b/src/Factory/Middleware/AuthorizationMiddlewareFactory.php index 5002ef8..8ebcef5 100644 --- a/src/Factory/Middleware/AuthorizationMiddlewareFactory.php +++ b/src/Factory/Middleware/AuthorizationMiddlewareFactory.php @@ -3,12 +3,12 @@ namespace User\Factory\Middleware; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Handler\ErrorHandler; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; -use User\Handler\ErrorHandler; use User\Middleware\AuthorizationMiddleware; use User\Service\PermissionService; use User\Service\RoleService; diff --git a/src/Factory/Middleware/AvatarUploadMiddlewareFactory.php b/src/Factory/Middleware/AvatarUploadMiddlewareFactory.php index 88ce1dc..5b44dce 100644 --- a/src/Factory/Middleware/AvatarUploadMiddlewareFactory.php +++ b/src/Factory/Middleware/AvatarUploadMiddlewareFactory.php @@ -3,13 +3,13 @@ namespace User\Factory\Middleware; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Handler\ErrorHandler; use Pi\Core\Middleware\SecurityMiddleware; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; -use User\Handler\ErrorHandler; use User\Middleware\AvatarUploadMiddleware; use User\Service\AccountService; use User\Service\AvatarService; diff --git a/src/Factory/Middleware/ErrorMiddlewareFactory.php b/src/Factory/Middleware/ErrorMiddlewareFactory.php deleted file mode 100644 index 3f63f2f..0000000 --- a/src/Factory/Middleware/ErrorMiddlewareFactory.php +++ /dev/null @@ -1,33 +0,0 @@ -get(ResponseFactoryInterface::class), - $container->get(StreamFactoryInterface::class), - $container->get(ErrorHandler::class) - ); - } -} \ No newline at end of file diff --git a/src/Factory/Middleware/InstallerMiddlewareFactory.php b/src/Factory/Middleware/InstallerMiddlewareFactory.php deleted file mode 100644 index d915a13..0000000 --- a/src/Factory/Middleware/InstallerMiddlewareFactory.php +++ /dev/null @@ -1,37 +0,0 @@ -get(ResponseFactoryInterface::class), - $container->get(StreamFactoryInterface::class), - $container->get(RoleService::class), - $container->get(PermissionService::class), - $container->get(ErrorHandler::class) - ); - } -} \ No newline at end of file diff --git a/src/Factory/Middleware/RawDataValidationMiddlewareFactory.php b/src/Factory/Middleware/RawDataValidationMiddlewareFactory.php deleted file mode 100644 index ca41199..0000000 --- a/src/Factory/Middleware/RawDataValidationMiddlewareFactory.php +++ /dev/null @@ -1,39 +0,0 @@ -get(ResponseFactoryInterface::class), - $container->get(StreamFactoryInterface::class), - $container->get(AccountService::class), - $container->get(UtilityService::class), - $container->get(CacheService::class), - $container->get(ErrorHandler::class) - ); - } -} \ No newline at end of file diff --git a/src/Factory/Middleware/RequestPreparationMiddlewareFactory.php b/src/Factory/Middleware/RequestPreparationMiddlewareFactory.php deleted file mode 100644 index b79e8ec..0000000 --- a/src/Factory/Middleware/RequestPreparationMiddlewareFactory.php +++ /dev/null @@ -1,27 +0,0 @@ -get('config'); - $config = $config['security'] ?? []; - - return new RequestPreparationMiddleware( - $container->get(ResponseFactoryInterface::class), - $container->get(StreamFactoryInterface::class), - $container->get(ErrorHandler::class), - $config - ); - } -} \ No newline at end of file diff --git a/src/Factory/Middleware/ValidationMiddlewareFactory.php b/src/Factory/Middleware/ValidationMiddlewareFactory.php index 568e8ef..c90de64 100644 --- a/src/Factory/Middleware/ValidationMiddlewareFactory.php +++ b/src/Factory/Middleware/ValidationMiddlewareFactory.php @@ -3,16 +3,16 @@ namespace User\Factory\Middleware; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Handler\ErrorHandler; +use Pi\Core\Service\CacheService; +use Pi\Core\Service\UtilityService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; -use User\Handler\ErrorHandler; use User\Middleware\ValidationMiddleware; use User\Service\AccountService; -use User\Service\CacheService; -use User\Service\UtilityService; class ValidationMiddlewareFactory implements FactoryInterface { diff --git a/src/Factory/Service/AccountServiceFactory.php b/src/Factory/Service/AccountServiceFactory.php index 08e0199..4effdb0 100644 --- a/src/Factory/Service/AccountServiceFactory.php +++ b/src/Factory/Service/AccountServiceFactory.php @@ -6,19 +6,19 @@ use Notification\Service\NotificationService; use Pi\Core\Security\Account\AccountLocked; use Pi\Core\Security\Account\AccountLoginAttempts; +use Pi\Core\Service\CacheService; +use Pi\Core\Service\TranslatorService; +use Pi\Core\Service\UtilityService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use User\Repository\AccountRepositoryInterface; use User\Service\AccountService; use User\Service\AvatarService; -use User\Service\CacheService; use User\Service\HistoryService; use User\Service\PermissionService; use User\Service\RoleService; use User\Service\TokenService; -use User\Service\TranslatorService; -use User\Service\UtilityService; class AccountServiceFactory implements FactoryInterface { diff --git a/src/Factory/Service/CacheServiceFactory.php b/src/Factory/Service/CacheServiceFactory.php deleted file mode 100644 index 5a4eaff..0000000 --- a/src/Factory/Service/CacheServiceFactory.php +++ /dev/null @@ -1,29 +0,0 @@ -get('config'); - - return new CacheService( - $container->get(StorageAdapterFactoryInterface::class), - $config['cache'] - ); - } -} \ No newline at end of file diff --git a/src/Factory/Service/InstallerServiceFactory.php b/src/Factory/Service/InstallerServiceFactory.php deleted file mode 100644 index 50bab14..0000000 --- a/src/Factory/Service/InstallerServiceFactory.php +++ /dev/null @@ -1,25 +0,0 @@ -get(PermissionService::class) - ); - } -} \ No newline at end of file diff --git a/src/Factory/Service/PermissionServiceFactory.php b/src/Factory/Service/PermissionServiceFactory.php index 125ba69..b8c0abb 100644 --- a/src/Factory/Service/PermissionServiceFactory.php +++ b/src/Factory/Service/PermissionServiceFactory.php @@ -3,11 +3,11 @@ namespace User\Factory\Service; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use User\Repository\PermissionRepositoryInterface; -use User\Service\CacheService; use User\Service\PermissionService; class PermissionServiceFactory implements FactoryInterface diff --git a/src/Factory/Service/RoleServiceFactory.php b/src/Factory/Service/RoleServiceFactory.php index 398d857..d3d6478 100644 --- a/src/Factory/Service/RoleServiceFactory.php +++ b/src/Factory/Service/RoleServiceFactory.php @@ -3,11 +3,11 @@ namespace User\Factory\Service; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use User\Repository\RoleRepositoryInterface; -use User\Service\CacheService; use User\Service\HistoryService; use User\Service\RoleService; diff --git a/src/Factory/Service/TokenServiceFactory.php b/src/Factory/Service/TokenServiceFactory.php index d9455c1..86c5176 100644 --- a/src/Factory/Service/TokenServiceFactory.php +++ b/src/Factory/Service/TokenServiceFactory.php @@ -3,8 +3,8 @@ namespace User\Factory\Service; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerInterface; -use User\Service\CacheService; use User\Service\TokenService; class TokenServiceFactory implements FactoryInterface diff --git a/src/Factory/Service/TranslatorServiceFactory.php b/src/Factory/Service/TranslatorServiceFactory.php deleted file mode 100644 index 5111f03..0000000 --- a/src/Factory/Service/TranslatorServiceFactory.php +++ /dev/null @@ -1,20 +0,0 @@ -get('config'); - - return new TranslatorService( - $config['translator'] - ); - } -} \ No newline at end of file diff --git a/src/Factory/Service/UtilityServiceFactory.php b/src/Factory/Service/UtilityServiceFactory.php deleted file mode 100644 index 66e9bb4..0000000 --- a/src/Factory/Service/UtilityServiceFactory.php +++ /dev/null @@ -1,30 +0,0 @@ -get('config'); - $config = $config['utility'] ?? []; - - return new UtilityService($config); - } -} \ No newline at end of file diff --git a/src/Factory/Validator/OtpValidatorFactory.php b/src/Factory/Validator/OtpValidatorFactory.php index 7fe9d77..b1acf6c 100644 --- a/src/Factory/Validator/OtpValidatorFactory.php +++ b/src/Factory/Validator/OtpValidatorFactory.php @@ -3,11 +3,11 @@ namespace User\Factory\Validator; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\CacheService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use User\Service\AccountService; -use User\Service\CacheService; use User\Validator\OtpValidator; class OtpValidatorFactory implements FactoryInterface diff --git a/src/Factory/Validator/PasswordValidatorFactory.php b/src/Factory/Validator/PasswordValidatorFactory.php index f87035e..2f0897f 100644 --- a/src/Factory/Validator/PasswordValidatorFactory.php +++ b/src/Factory/Validator/PasswordValidatorFactory.php @@ -3,11 +3,11 @@ namespace User\Factory\Validator; use Laminas\ServiceManager\Factory\FactoryInterface; +use Pi\Core\Service\UtilityService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use User\Service\AccountService; -use User\Service\UtilityService; use User\Validator\PasswordValidator; class PasswordValidatorFactory implements FactoryInterface diff --git a/src/Handler/Admin/Cache/DeleteHandler.php b/src/Handler/Admin/Cache/DeleteHandler.php index 73a5238..becc900 100644 --- a/src/Handler/Admin/Cache/DeleteHandler.php +++ b/src/Handler/Admin/Cache/DeleteHandler.php @@ -3,12 +3,12 @@ namespace User\Handler\Admin\Cache; use Laminas\Diactoros\Response\JsonResponse; +use Pi\Core\Service\CacheService; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\RequestHandlerInterface; -use User\Service\CacheService; class DeleteHandler implements RequestHandlerInterface { diff --git a/src/Handler/Admin/Cache/ListHandler.php b/src/Handler/Admin/Cache/ListHandler.php index 35b8241..d4e67dd 100644 --- a/src/Handler/Admin/Cache/ListHandler.php +++ b/src/Handler/Admin/Cache/ListHandler.php @@ -3,12 +3,12 @@ namespace User\Handler\Admin\Cache; use Laminas\Diactoros\Response\JsonResponse; +use Pi\Core\Service\CacheService; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\RequestHandlerInterface; -use User\Service\CacheService; class ListHandler implements RequestHandlerInterface { diff --git a/src/Handler/Admin/Cache/PersistHandler.php b/src/Handler/Admin/Cache/PersistHandler.php index 2d7e330..d1f2334 100644 --- a/src/Handler/Admin/Cache/PersistHandler.php +++ b/src/Handler/Admin/Cache/PersistHandler.php @@ -3,12 +3,12 @@ namespace User\Handler\Admin\Cache; use Laminas\Diactoros\Response\JsonResponse; +use Pi\Core\Service\CacheService; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\RequestHandlerInterface; -use User\Service\CacheService; class PersistHandler implements RequestHandlerInterface { diff --git a/src/Handler/Admin/Cache/ViewHandler.php b/src/Handler/Admin/Cache/ViewHandler.php index 7428991..2294d50 100644 --- a/src/Handler/Admin/Cache/ViewHandler.php +++ b/src/Handler/Admin/Cache/ViewHandler.php @@ -3,12 +3,12 @@ namespace User\Handler\Admin\Cache; use Laminas\Diactoros\Response\JsonResponse; +use Pi\Core\Service\CacheService; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\RequestHandlerInterface; -use User\Service\CacheService; class ViewHandler implements RequestHandlerInterface { diff --git a/src/Handler/ErrorHandler.php b/src/Handler/ErrorHandler.php deleted file mode 100644 index 9c37a8a..0000000 --- a/src/Handler/ErrorHandler.php +++ /dev/null @@ -1,45 +0,0 @@ -responseFactory = $responseFactory; - $this->streamFactory = $streamFactory; - } - - public function handle(ServerRequestInterface $request): ResponseInterface - { - $error = $request->getAttribute('error'); - $status = $request->getAttribute('status'); - - // Set result - return new JsonResponse( - [ - 'result' => false, - 'data' => new stdClass, - 'error' => $error, - 'status' => $status, - ], - $status - ); - } -} diff --git a/src/Handler/InstallerHandler.php b/src/Handler/InstallerHandler.php index 35967c9..61b06bb 100644 --- a/src/Handler/InstallerHandler.php +++ b/src/Handler/InstallerHandler.php @@ -3,13 +3,13 @@ namespace User\Handler; use Laminas\Diactoros\Response\JsonResponse; +use Pi\Core\Service\InstallerService; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\RequestHandlerInterface; use stdClass; -use User\Service\InstallerService; class InstallerHandler implements RequestHandlerInterface { diff --git a/src/Installer/Install.php b/src/Installer/Install.php deleted file mode 100644 index 99885be..0000000 --- a/src/Installer/Install.php +++ /dev/null @@ -1,53 +0,0 @@ -installerService = $installerService; - } - - public function database($sqlFile): void - { - // Set and check - if (!file_exists($sqlFile)) { - echo 'Error to find or read sql file'; - exit(); - } - - echo 'Module database install successfully !'; - } - - public function config($configFile): void - { - // Set and check - if (!file_exists($configFile)) { - echo 'Error to find or read config file'; - exit(); - } - - echo 'Module config install successfully !'; - } - - public function permission($permissionFile): void - { - // Set and check - if (!file_exists($permissionFile)) { - echo 'Error to find or read permission file'; - exit(); - } - - $permissionConfig = include $permissionFile; - - $this->installerService->installPermission($permissionConfig); - - echo 'Module permission install successfully !'; - } -} \ No newline at end of file diff --git a/src/Installer/InstallerInterface.php b/src/Installer/InstallerInterface.php deleted file mode 100644 index 339156a..0000000 --- a/src/Installer/InstallerInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -installerService = $installerService; - } - - public function database($sqlFile): void - { - } - - public function config($configFile): void - { - } - - public function permission($permissionFile): void - { - } -} \ No newline at end of file diff --git a/src/Installer/Update.php b/src/Installer/Update.php deleted file mode 100644 index c6437fe..0000000 --- a/src/Installer/Update.php +++ /dev/null @@ -1,28 +0,0 @@ -installerService = $installerService; - } - - public function database($sqlFile): void - { - } - - public function config($configFile): void - { - } - - public function permission($permissionFile): void - { - } -} \ No newline at end of file diff --git a/src/Middleware/AuthenticationMiddleware.php b/src/Middleware/AuthenticationMiddleware.php index 89f3444..19e9ab7 100644 --- a/src/Middleware/AuthenticationMiddleware.php +++ b/src/Middleware/AuthenticationMiddleware.php @@ -3,16 +3,16 @@ namespace User\Middleware; use Fig\Http\Message\StatusCodeInterface; +use Pi\Core\Handler\ErrorHandler; use Pi\Core\Security\Account\AccountLocked; +use Pi\Core\Service\CacheService; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use User\Handler\ErrorHandler; use User\Service\AccountService; -use User\Service\CacheService; use User\Service\TokenService; class AuthenticationMiddleware implements MiddlewareInterface diff --git a/src/Middleware/AuthorizationMiddleware.php b/src/Middleware/AuthorizationMiddleware.php index 348002b..105cd40 100644 --- a/src/Middleware/AuthorizationMiddleware.php +++ b/src/Middleware/AuthorizationMiddleware.php @@ -3,13 +3,13 @@ namespace User\Middleware; use Fig\Http\Message\StatusCodeInterface; +use Pi\Core\Handler\ErrorHandler; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use User\Handler\ErrorHandler; use User\Service\PermissionService; use User\Service\RoleService; diff --git a/src/Middleware/AvatarUploadMiddleware.php b/src/Middleware/AvatarUploadMiddleware.php index 8993245..f2390db 100644 --- a/src/Middleware/AvatarUploadMiddleware.php +++ b/src/Middleware/AvatarUploadMiddleware.php @@ -7,13 +7,13 @@ use Laminas\Validator\File\MimeType; use Laminas\Validator\File\Size; use Laminas\Validator\File\UploadFile; +use Pi\Core\Handler\ErrorHandler; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use User\Handler\ErrorHandler; use User\Service\AccountService; use User\Service\AvatarService; diff --git a/src/Middleware/ErrorMiddleware.php b/src/Middleware/ErrorMiddleware.php deleted file mode 100644 index e896ffe..0000000 --- a/src/Middleware/ErrorMiddleware.php +++ /dev/null @@ -1,65 +0,0 @@ -responseFactory = $responseFactory; - $this->streamFactory = $streamFactory; - $this->errorHandler = $errorHandler; - } - - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface - { - try { - return $handler->handle($request); - } catch (RuntimeException $e) { - $request = $request->withAttribute('status', StatusCodeInterface::STATUS_NOT_FOUND); - $request = $request->withAttribute( - 'error', - [ - 'message' => $e->getMessage(), - //'trace' => $e->getTraceAsString(), - 'code' => StatusCodeInterface::STATUS_NOT_FOUND, - ] - ); - return $this->errorHandler->handle($request); - } catch (Throwable $e) { - $request = $request->withAttribute('status', StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); - $request = $request->withAttribute( - 'error', - [ - 'message' => $e->getMessage(), - //'trace' => $e->getTraceAsString(), - 'code' => StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR, - ] - ); - return $this->errorHandler->handle($request); - } - } -} \ No newline at end of file diff --git a/src/Middleware/InstallerMiddleware.php b/src/Middleware/InstallerMiddleware.php deleted file mode 100644 index d640301..0000000 --- a/src/Middleware/InstallerMiddleware.php +++ /dev/null @@ -1,66 +0,0 @@ -responseFactory = $responseFactory; - $this->streamFactory = $streamFactory; - $this->roleService = $roleService; - $this->permissionService = $permissionService; - $this->errorHandler = $errorHandler; - } - - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface - { - $userRoles = $request->getAttribute('roles'); - $userRoles = array_combine($userRoles, $userRoles); - - if (!in_array('admin', $userRoles)) { - $request = $request->withAttribute('status', StatusCodeInterface::STATUS_FORBIDDEN); - $request = $request->withAttribute( - 'error', - [ - 'message' => 'You dont have access to this area !', - 'code' => StatusCodeInterface::STATUS_FORBIDDEN, - ] - ); - return $this->errorHandler->handle($request); - } - - return $handler->handle($request); - } -} \ No newline at end of file diff --git a/src/Middleware/RawDataValidationMiddleware.php b/src/Middleware/RawDataValidationMiddleware.php deleted file mode 100644 index 9a36b9d..0000000 --- a/src/Middleware/RawDataValidationMiddleware.php +++ /dev/null @@ -1,528 +0,0 @@ - true, - 'code' => StatusCodeInterface::STATUS_OK, - 'message' => '', - ]; - /** @var ResponseFactoryInterface */ - protected ResponseFactoryInterface $responseFactory; - - /** @var StreamFactoryInterface */ - protected StreamFactoryInterface $streamFactory; - - /** @var AccountService */ - protected AccountService $accountService; - - /** @var UtilityService */ - protected UtilityService $utilityService; - - /* @var CacheService */ - protected CacheService $cacheService; - - /** @var ErrorHandler */ - protected ErrorHandler $errorHandler; - - public function __construct( - ResponseFactoryInterface $responseFactory, - StreamFactoryInterface $streamFactory, - AccountService $accountService, - UtilityService $utilityService, - CacheService $cacheService, - ErrorHandler $errorHandler - ) { - $this->responseFactory = $responseFactory; - $this->streamFactory = $streamFactory; - $this->accountService = $accountService; - $this->utilityService = $utilityService; - $this->cacheService = $cacheService; - $this->errorHandler = $errorHandler; - } - - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface - { - // Get information from request - $routeMatch = $request->getAttribute('Laminas\Router\RouteMatch'); - $stream = $this->streamFactory->createStreamFromFile('php://input'); - $rawData = $stream->getContents(); - - // Decode the raw JSON data into an associative array - $parsedBody = json_decode($rawData, true); - - // Check if decoding was successful - if (json_last_error() !== JSON_ERROR_NONE) { - // JSON decoding failed - $errorMessage = 'Invalid JSON data'; - $request = $request->withAttribute('status', StatusCodeInterface::STATUS_FORBIDDEN); - $request = $request->withAttribute( - 'error', - [ - 'message' => 'Invalid JSON data !', - 'code' => StatusCodeInterface::STATUS_BAD_REQUEST, - ] - ); - return $this->errorHandler->handle($request); - } - - $account = $request->getAttribute('account'); - $routeParams = $routeMatch->getParams(); - - // Check parsedBody - switch ($routeParams['validator']) { - //when need only check request type is raw data - case 'global': - break; - - case 'login': - $this->loginIsValid($parsedBody); - break; - - case 'add': - $this->registerIsValid($parsedBody); - break; - - case 'edit': - $this->editIsValid($parsedBody, $account); - break; - - case 'device-token': - $this->deviceTokenIsValid($parsedBody, $account); - break; - - case 'password-add': - $this->passwordAddIsValid($parsedBody, $account); - break; - - case 'password-update': - $this->passwordEditIsValid($parsedBody); - break; - - case 'password-admin': - $this->passwordAdminIsValid($parsedBody); - break; - - case 'email-request': - $this->emailRequestIsValid($parsedBody); - break; - - case 'email-verify': - $this->emailVerifyIsValid($parsedBody); - break; - - case 'mobile-request': - $this->mobileRequestIsValid($parsedBody); - break; - - case 'mobile-verify': - $this->mobileVerifyIsValid($parsedBody); - break; - - default: - $request = $request->withAttribute('status', StatusCodeInterface::STATUS_FORBIDDEN); - $request = $request->withAttribute( - 'error', - [ - 'message' => 'Validator not set !', - 'code' => StatusCodeInterface::STATUS_FORBIDDEN, - ] - ); - return $this->errorHandler->handle($request); - break; - } - - // Check if validator result is not true - if (!$this->validationResult['status']) { - $request = $request->withAttribute('status', $this->validationResult['code']); - $request = $request->withAttribute( - 'error', - [ - 'message' => $this->validationResult['message'], - 'code' => $this->validationResult['code'], - ] - ); - return $this->errorHandler->handle($request); - } - - return $handler->handle($request); - } - - protected function setErrorHandler($inputFilter): array - { - $message = []; - foreach ($inputFilter->getInvalidInput() as $error) { - $message[$error->getName()] = $error->getName() . ': ' . implode(', ', $error->getMessages()); - } - - return $this->validationResult = [ - 'status' => false, - 'code' => StatusCodeInterface::STATUS_FORBIDDEN, - 'message' => implode(', ', $message), - ]; - } - - protected function loginIsValid($params) - { - $inputFilter = new InputFilter(); - - // Check email or identity or mobile - if (isset($params['email']) && !empty($params['email'])) { - // Set input filter - $email = new Input('email'); - $email->getValidatorChain()->attach(new EmailValidator($this->accountService, ['check_duplication' => false])); - $inputFilter->add($email); - - // Set check params - $checkParams = ['email' => $params['email']]; - } elseif (isset($params['identity']) && !empty($params['identity'])) { - // Set input filter - $identity = new Input('identity'); - $identity->getValidatorChain()->attach(new IdentityValidator($this->accountService, ['check_duplication' => false])); - $inputFilter->add($identity); - - // Set check params - $checkParams = ['identity' => $params['identity']]; - } elseif (isset($params['mobile']) && !empty($params['mobile'])) { - // Set input filter - $option = [ - 'check_duplication' => false, - 'country' => $option['country'] ?? 'IR', - ]; - $mobile = new Input('mobile'); - $mobile->getValidatorChain()->attach(new MobileValidator($this->accountService, $option)); - $inputFilter->add($mobile); - - // Set check params - $checkParams = ['mobile' => $params['mobile']]; - } else { - return $this->validationResult = [ - 'status' => false, - 'code' => StatusCodeInterface::STATUS_FORBIDDEN, - 'message' => 'Login fields not set !', - ]; - } - - // Check credential - $credential = new Input('credential'); - $credential->getValidatorChain()->attach(new PasswordValidator($this->accountService, $this->utilityService)); - $inputFilter->add($credential); - - // Set data and check - $inputFilter->setData($params); - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function registerIsValid($params) - { - // Set name - if ( - isset($params['first_name']) - && !empty($params['first_name']) - && isset($params['last_name']) - && !empty($params['last_name']) - ) { - $params['name'] = sprintf('%s %s', $params['first_name'], $params['last_name']); - } - - $inputFilter = new InputFilter(); - - // Check name - if (isset($params['name']) && !empty($params['name'])) { - $name = new Input('name'); - $name->getValidatorChain()->attach(new NameValidator($this->accountService)); - $inputFilter->add($name); - } - - // Check email - if (isset($params['email']) && !empty($params['email'])) { - $email = new Input('email'); - $email->getValidatorChain()->attach(new EmailValidator($this->accountService)); - $inputFilter->add($email); - } - - // Check mobile - if (isset($params['mobile']) && !empty($params['mobile'])) { - $option = [ - 'check_duplication' => true, - 'country' => 'IR', - ]; - if (isset($params['country']) && !empty($params['country'])) { - $option['country'] = $params['country']; - } - - $mobile = new Input('mobile'); - $mobile->getValidatorChain()->attach(new MobileValidator($this->accountService, $option)); - $inputFilter->add($mobile); - } - - // Check credential - if (isset($params['identity']) && !empty($params['identity'])) { - $identity = new Input('identity'); - $identity->getValidatorChain()->attach(new IdentityValidator($this->accountService)); - $inputFilter->add($identity); - } - - // Check identity - if (isset($params['credential']) && !empty($params['credential'])) { - $credential = new Input('credential'); - $credential->getValidatorChain()->attach(new PasswordValidator($this->accountService, $this->utilityService)); - $inputFilter->add($credential); - } - - // Check mobile - if (isset($params['mobile']) && !empty($params['mobile'])) { - $option = [ - 'check_duplication' => false, - 'country' => 'IR', - ]; - if (isset($params['country']) && !empty($params['country'])) { - $option['country'] = $params['country']; - } - - $mobile = new Input('mobile'); - $mobile->getValidatorChain()->attach(new MobileValidator($this->accountService, $option)); - $inputFilter->add($mobile); - } - - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function editIsValid($params, $account) - { - // Set name - if ( - isset($params['first_name']) - && !empty($params['first_name']) - && isset($params['last_name']) - && !empty($params['last_name']) - ) { - $params['name'] = sprintf('%s %s', $params['first_name'], $params['last_name']); - } - - $inputFilter = new InputFilter(); - - if (isset($params['email']) && !empty($params['email'])) { - $email = new Input('email'); - $email->getValidatorChain()->attach(new EmailValidator($this->accountService, ['user_id' => $account['id']])); - $inputFilter->add($email); - } - - if (isset($params['name']) && !empty($params['name'])) { - $name = new Input('name'); - $name->getValidatorChain()->attach(new NameValidator($this->accountService, ['user_id' => $account['id']])); - $inputFilter->add($name); - } - - if (isset($params['identity']) && !empty($params['identity'])) { - $identity = new Input('identity'); - $identity->getValidatorChain()->attach(new IdentityValidator($this->accountService, ['user_id' => $account['id']])); - $inputFilter->add($identity); - } - - if (isset($params['mobile']) && !empty($params['mobile'])) { - $mobile = new Input('mobile'); - $mobile->getValidatorChain()->attach(new MobileValidator($this->accountService, ['user_id' => $account['id']])); - $inputFilter->add($mobile); - } - - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function deviceTokenIsValid($params, $account) - { - if (!isset($params['device_token']) || empty($params['device_token']) || !is_string($params['device_token'])) { - return $this->validationResult = [ - 'status' => false, - 'code' => StatusCodeInterface::STATUS_FORBIDDEN, - 'message' => 'Device token was not set or its wrong !', - ]; - } - } - - protected function passwordAddIsValid($params, $account) - { - // Set option - $option = [ - 'user_id' => $params['user_id'] ?? $account['id'], - 'check_has_password' => 1, - ]; - - $credential = new Input('credential'); - $credential->getValidatorChain()->attach(new PasswordValidator($this->accountService, $this->utilityService, $option)); - - $inputFilter = new InputFilter(); - $inputFilter->add($credential); - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function passwordEditIsValid($params) - { - $currentCredential = new Input('current_credential'); - $currentCredential->getValidatorChain()->attach(new PasswordValidator($this->accountService, $this->utilityService)); - - $newCredential = new Input('new_credential'); - $newCredential->getValidatorChain()->attach(new PasswordValidator($this->accountService, $this->utilityService)); - - $inputFilter = new InputFilter(); - $inputFilter->add($currentCredential); - $inputFilter->add($newCredential); - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function passwordAdminIsValid($params) - { - $credential = new Input('credential'); - $credential->getValidatorChain()->attach(new PasswordValidator($this->accountService, $this->utilityService)); - - $inputFilter = new InputFilter(); - $inputFilter->add($credential); - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function emailRequestIsValid($params) - { - $option = [ - 'check_duplication' => false, - ]; - - $email = new Input('email'); - $email->getValidatorChain()->attach(new EmailValidator($this->accountService, $option)); - - $inputFilter = new InputFilter(); - $inputFilter->add($email); - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function emailVerifyIsValid($params) - { - $option = [ - 'check_duplication' => false, - ]; - - // Check email - $email = new Input('email'); - $email->getValidatorChain()->attach(new EmailValidator($this->accountService, $option)); - - $option = [ - 'email' => $params['email'], - ]; - - // Check otp - $otp = new Input('otp'); - $otp->getValidatorChain()->attach(new OtpValidator($this->accountService, $this->cacheService, $option)); - - $inputFilter = new InputFilter(); - $inputFilter->add($email); - $inputFilter->add($otp); - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function mobileRequestIsValid($params) - { - $option = [ - 'check_duplication' => false, - 'country' => 'IR', - ]; - if (isset($params['country']) && !empty($params['country'])) { - $option['country'] = $params['country']; - } - - $mobile = new Input('mobile'); - $mobile->getValidatorChain()->attach(new MobileValidator($this->accountService, $option)); - - $inputFilter = new InputFilter(); - $inputFilter->add($mobile); - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } - - protected function mobileVerifyIsValid($params) - { - $inputFilter = new InputFilter(); - - $option = [ - 'check_duplication' => false, - 'country' => 'IR', - ]; - if (isset($params['country']) && !empty($params['country'])) { - $option['country'] = $params['country']; - } - - $mobile = new Input('mobile'); - $mobile->getValidatorChain()->attach(new MobileValidator($this->accountService, $option)); - $inputFilter->add($mobile); - - $option = [ - 'mobile' => $params['mobile'], - ]; - - // Check otp - $otp = new Input('otp'); - $otp->getValidatorChain()->attach(new OtpValidator($this->accountService, $this->cacheService, $option)); - $inputFilter->add($otp); - - $inputFilter->setData($params); - - if (!$inputFilter->isValid()) { - return $this->setErrorHandler($inputFilter); - } - } -} \ No newline at end of file diff --git a/src/Middleware/RequestPreparationMiddleware.php b/src/Middleware/RequestPreparationMiddleware.php deleted file mode 100644 index dc8535c..0000000 --- a/src/Middleware/RequestPreparationMiddleware.php +++ /dev/null @@ -1,100 +0,0 @@ -responseFactory = $responseFactory; - $this->streamFactory = $streamFactory; - $this->errorHandler = $errorHandler; - $this->config = $config; - } - - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface - { - $contentType = $request->getHeaderLine('Content-Type'); - - // Check for JSON or form data content types - if ($this->isJson($contentType)) { - $response = $this->processJsonRequest($request, $handler); - } elseif ($this->isFormData($contentType)) { - // Handle form data, if necessary - $response = $handler->handle($request); - } else { - // Todo: Fix it - // Unsupported content type - //return $this->createErrorResponse($request, 'Unsupported content type', StatusCodeInterface::STATUS_BAD_REQUEST); - $response = $handler->handle($request); - } - - // Check if the response can be compressed and compressed it - if (isset($this->config['compress']['is_active']) && $this->config['compress']['is_active']) { - - } - - return $response; - } - - private function createErrorResponse(ServerRequestInterface $request, string $message): ResponseInterface - { - $request = $request->withAttribute('status', StatusCodeInterface::STATUS_BAD_REQUEST); - $request = $request->withAttribute('error', ['message' => $message, 'code' => StatusCodeInterface::STATUS_BAD_REQUEST]); - return $this->errorHandler->handle($request); - } - - private function isJson(string $contentType): bool - { - return stripos($contentType, 'application/json') !== false - || stripos($contentType, 'text/plain') !== false; - } - - private function isFormData(string $contentType): bool - { - return stripos($contentType, 'application/x-www-form-urlencoded') !== false - || stripos($contentType, 'multipart/form-data') !== false; - } - - private function processJsonRequest(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface - { - $stream = $this->streamFactory->createStreamFromFile('php://input'); - $rawData = $stream->getContents(); - - if (!empty($rawData)) { - $parsedBody = json_decode($rawData, true); - if (json_last_error() !== JSON_ERROR_NONE) { - return $this->createErrorResponse($request, 'Invalid JSON data', StatusCodeInterface::STATUS_BAD_REQUEST); - } - - $request = $request->withParsedBody($parsedBody); - } - - return $handler->handle($request); - } -} \ No newline at end of file diff --git a/src/Middleware/ValidationMiddleware.php b/src/Middleware/ValidationMiddleware.php index 6c3a2c0..ea6a91f 100644 --- a/src/Middleware/ValidationMiddleware.php +++ b/src/Middleware/ValidationMiddleware.php @@ -5,16 +5,16 @@ use Fig\Http\Message\StatusCodeInterface; use Laminas\InputFilter\Input; use Laminas\InputFilter\InputFilter; +use Pi\Core\Handler\ErrorHandler; +use Pi\Core\Service\CacheService; +use Pi\Core\Service\UtilityService; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use User\Handler\ErrorHandler; use User\Service\AccountService; -use User\Service\CacheService; -use User\Service\UtilityService; use User\Validator\EmailValidator; use User\Validator\IdentityValidator; use User\Validator\MobileValidator; diff --git a/src/Service/AccountService.php b/src/Service/AccountService.php index 653ff1d..a23495c 100644 --- a/src/Service/AccountService.php +++ b/src/Service/AccountService.php @@ -7,6 +7,9 @@ use Notification\Service\NotificationService; use Pi\Core\Security\Account\AccountLocked; use Pi\Core\Security\Account\AccountLoginAttempts; +use Pi\Core\Service\CacheService; +use Pi\Core\Service\TranslatorService; +use Pi\Core\Service\UtilityService; use RobThree\Auth\Algorithm; use RobThree\Auth\Providers\Qr\EndroidQrCodeProvider; use RobThree\Auth\TwoFactorAuth; diff --git a/src/Service/CacheService.php b/src/Service/CacheService.php deleted file mode 100644 index b73b009..0000000 --- a/src/Service/CacheService.php +++ /dev/null @@ -1,341 +0,0 @@ - [], - 'roles' => [], - 'access_keys' => [], - 'refresh_keys' => [], - 'otp' => [], - 'device_tokens' => [], - 'multi_factor' => [], - 'authorization' => [], - ]; - - /* @var array */ - public array $userAccountValuePattern - = [ - 'id' => 0, - 'name' => null, - 'email' => null, - 'identity' => null, - 'mobile' => null, - 'first_name' => null, - 'last_name' => null, - 'avatar' => null, - 'last_login' => 0, - 'status' => 0, - 'time_created' => 0, - 'has_password' => 0, - 'multi_factor_global' => 0, - 'multi_factor_status' => 0, - 'multi_factor_verify' => 0, - 'is_company_setup' => 0, - ]; - - /* @var SimpleCacheDecorator */ - protected SimpleCacheDecorator $cache; - - /* @var string */ - protected string $userKeyPattern = 'user-%s'; - - /* @var array */ - protected array $config; - - public function __construct(StorageAdapterFactoryInterface $storageFactory, $config) - { - // Set cache - $cache = $storageFactory->create($config['storage'], $config['options'], $config['plugins']); - $cache->addPlugin(new Serializer()); - $this->cache = new SimpleCacheDecorator($cache); - $this->config = $config; - } - - public function hasItem($key): bool - { - return $this->cache->has($key); - } - - public function getItem($key): array - { - $item = []; - if ($this->cache->has($key)) { - $item = $this->cache->get($key); - } - - return $item; - } - - public function setItem(string $key, array $value = [], $ttl = null): array - { - $this->cache->set($key, $value, $ttl); - - return $this->getItem($key); - } - - public function deleteItem(string $key): void - { - $this->cache->delete($key); - } - - public function deleteItems(array $array): void - { - foreach ($array as $key) { - $this->cache->delete($key); - } - } - - public function setUser(int $userId, array $params): array - { - $key = sprintf($this->userKeyPattern, $userId); - - // Get and check user - $user = $this->getUser($userId); - if (empty($user)) { - $user = $this->userValuePattern; - } - - // Set params - if (isset($params['account']) && !empty($params['account'])) { - // Set user - $user['account'] = $params['account']; - $user['account']['id'] = (int)$user['account']['id']; - - // Set user account template - foreach ($this->userAccountValuePattern as $accountKey => $accountValue) { - if (!isset($user['account'][$accountKey])) { - $user['account'][$accountKey] = $accountValue; - } - } - } - if (isset($params['access_keys'])/* && !empty($params['access_keys'])*/) { - $user['access_keys'] = $params['access_keys']; - } - if (isset($params['refresh_keys'])/* && !empty($params['refresh_keys'])*/) { - $user['refresh_keys'] = $params['refresh_keys']; - } - if (isset($params['roles']) && !empty($params['roles'])) { - $user['roles'] = $params['roles']; - } - if (isset($params['otp']) && !empty($params['otp'])) { - $user['otp'] = $params['otp']; - } - if (isset($params['device_tokens']) && !empty($params['device_tokens'])) { - $user['device_tokens'] = $params['device_tokens']; - } - if (isset($params['multi_factor']) && !empty($params['multi_factor'])) { - $user['multi_factor'] = $params['multi_factor']; - } - if (isset($params['permission']) && !empty($params['permission'])) { - $user['permission'] = $params['permission']; - } - if (isset($params['authorization']) && !empty($params['authorization'])) { - $user['authorization'] = $params['authorization']; - } - - // Set/Reset cache - return $this->setItem($key, $user); - } - - public function getUser(int $userId): array - { - $key = sprintf($this->userKeyPattern, $userId); - $user = $this->getItem($key); - if (!empty($user)) { - $user['account']['id'] = (int)$user['account']['id']; - } - - return $user; - } - - public function deleteUser($userId): void - { - $key = sprintf($this->userKeyPattern, $userId); - $this->deleteItem($key); - } - - public function setUserItem(int $userId, string $key, string $value): void - { - $user = $this->getUser($userId); - if (!empty($user) && !empty($value)) { - switch ($key) { - case 'access_keys': - $user['access_keys'] = array_unique(array_merge($user['access_keys'], [$value])); - $this->setUser($userId, ['access_keys' => $user['access_keys']]); - break; - - case 'refresh_keys': - $user['refresh_keys'] = array_unique(array_merge($user['refresh_keys'], [$value])); - $this->setUser($userId, ['refresh_keys' => $user['refresh_keys']]); - break; - - case 'roles': - $user['roles'] = array_unique(array_merge($user['roles'], [$value])); - $this->setUser($userId, ['roles' => $user['roles']]); - break; - - case 'multi_factor': - $user['multi_factor'] = array_unique(array_merge($user['multi_factor'], [$value])); - $this->setUser($userId, ['multi_factor' => $user['multi_factor']]); - break; - - // TODO: review this solution - case 'device_tokens': - $user['device_tokens'] = $value;// array_unique(array_merge($user['device_tokens'], [$value])); - $this->setUser($userId, ['device_tokens' => $user['device_tokens']]); - break; - } - } - } - - public function deleteUserItem(int $userId, string $key, string $value): void - { - $user = $this->getUser($userId); - if (!empty($user)) { - switch ($key) { - case 'all_keys': - $this->setUser($userId, ['access_keys' => [], 'refresh_keys' => []]); - break; - - case 'access_keys': - $user['access_keys'] = array_combine($user['access_keys'], $user['access_keys']); - if (isset($user['access_keys'][$value])) { - unset($user['access_keys'][$value]); - } - $this->setUser($userId, ['access_keys' => array_values($user['access_keys'])]); - break; - - case 'refresh_keys': - $user['refresh_keys'] = array_combine($user['refresh_keys'], $user['refresh_keys']); - if (isset($user['refresh_keys'][$value])) { - unset($user['refresh_keys'][$value]); - } - $this->setUser($userId, ['refresh_keys' => array_values($user['refresh_keys'])]); - break; - - case 'roles': - $user['roles'] = array_combine($user['roles'], $user['roles']); - if (isset($user['roles'][$value])) { - unset($user['roles'][$value]); - } - $this->setUser($userId, ['roles' => array_values($user['roles'])]); - break; - - case 'multi_factor': - $user['multi_factor'] = array_combine($user['multi_factor'], $user['multi_factor']); - if (isset($user['multi_factor'][$value])) { - unset($user['multi_factor'][$value]); - } - $this->setUser($userId, ['multi_factor' => array_values($user['multi_factor'])]); - break; - - // TODO: review this solution - case 'device_tokens': - $user['device_tokens'] = $value;// array_unique(array_merge($user['device_tokens'], [$value])); - $this->setUser($userId, ['device_tokens' => $user['device_tokens']]); - break; - } - } - } - - public function updateUserRoles(int $userId, array $roles, string $section = 'api'): array - { - // Get and check user - $key = sprintf($this->userKeyPattern, $userId); - $user = $this->getUser($userId); - - if (!empty($user)) { - // Update roles - switch ($section) { - case 'api': - $user['roles'] = array_unique(array_merge($user['roles'], $roles)); - break; - - case 'admin': - // Todo - break; - } - - // Set/Reset cache - $this->setItem($key, $user); - } - - return $user; - } - - public function getCacheList(): array - { - // Setup redis - $redis = new Redis(); - $redis->connect($this->config['options']['server']['host'], $this->config['options']['server']['port']); - - // Get keys - $keys = $redis->keys(sprintf('%s:*', $this->config['options']['namespace'])); - - // Set list - $list = []; - foreach ($keys as $key) { - // Set new key name - $simpleKey = str_replace(sprintf('%s:', $this->config['options']['namespace']), '', $key); - - // Get ttl - $ttl = $redis->ttl($key); - - // Set date - $currentTime = new DateTime(); - $expirationTime = new DateTime(); - $expirationTime->setTimestamp(time() + $ttl); - - // Set date - $expirationDate = $expirationTime->format('Y-m-d H:i:s'); - $interval = $currentTime->diff($expirationTime); - - // Status - $status = 'Active'; - if ($ttl === -1) { - $status = 'Perpetual (No Expiration)'; - } elseif ($ttl === -2) { - $status = 'Deleted'; - } - - // Add to list - $list[] = [ - 'key' => $simpleKey, - 'ttl' => $ttl, - 'status' => $status, - 'expiration' => [ - 'date' => $expirationDate, - 'interval' => [ - 'days' => $interval->days, - 'hours' => $interval->h, - 'minutes' => $interval->i, - ], - ], - ]; - } - - return $list; - } - - public function setPersist(string $key): void - { - // Set key - $key = sprintf('%s:%s', $this->config['options']['namespace'], $key); - - // Setup redis - $redis = new Redis(); - $redis->connect($this->config['options']['server']['host'], $this->config['options']['server']['port']); - $redis->persist($key); - } -} \ No newline at end of file diff --git a/src/Service/InstallerService.php b/src/Service/InstallerService.php deleted file mode 100644 index 5e33a4f..0000000 --- a/src/Service/InstallerService.php +++ /dev/null @@ -1,133 +0,0 @@ -permissionService = $permissionService; - } - - public function installPermission($module, array $permissionConfig): void - { - // Canonize - $permissionConfig = $this->canonizePermission($permissionConfig); - - // Get list of exist pages and permission - $installerList = $this->permissionService->getInstallerList(['module' => $module]); - - // Set list - $insertList = [ - 'permission' => [], - 'page' => [], - 'role' => [], - ]; - - // inset - foreach ($permissionConfig as $permissionList) { - foreach ($permissionList as $permissionSingle) { - if ( - !isset($installerList['page_list'][$permissionSingle['page']]) - && !isset($installerList['resource_list'][$permissionSingle['permissions']]) - ) { - // Check for duplicate - if (!in_array($permissionSingle['permissions'], $insertList['permission'])) { - // Set resource params - $resourceParams = array_merge( - $permissionSingle, - [ - 'key' => $permissionSingle['permissions'], - ] - ); - - // Add resource - $resource = $this->permissionService->addPermissionResource($resourceParams); - } else { - $resource = [ - 'key' => $permissionSingle['permissions'], - ]; - } - - // Check for duplicate - if (!in_array($permissionSingle['page'], $insertList['page'])) { - // Set page params - $pageParams = array_merge( - $permissionSingle, - [ - 'key' => $permissionSingle['page'], - 'resource' => $resource['key'], - ] - ); - - // Add page - $this->permissionService->addPermissionPage($pageParams); - } - - // Check roles - foreach ($permissionSingle['role'] as $role) { - // Set key - $key = sprintf('%s-%s', $role, $permissionSingle['permissions']); - - // Check for duplicate - if (!in_array($key, $insertList['role'])) { - // Set role params - $roleParams = array_merge( - $permissionSingle, - [ - 'key' => $key, - 'resource' => $resource['key'], - 'role' => $role, - ] - ); - - // Add role - $this->permissionService->addPermissionRole($roleParams); - - // Add to list - $insertList['role'][$key] = $key; - } - } - - // Add to list - $insertList['permission'][$permissionSingle['permissions']] = $permissionSingle['permissions']; - $insertList['page'][$permissionSingle['page']] = $permissionSingle['page']; - } - } - } - } - - public function canonizePermission(array $permissionConfig): array - { - foreach ($permissionConfig as $permissionSection => $permissionList) { - foreach ($permissionList as $permissionSingleKey => $permissionSingle) { - if (!isset($permissionSingle['page']) || empty($permissionSingle['page'])) { - $permissionSingle['page'] = sprintf( - '%s-%s-%s-%s', - $permissionSingle['section'], - $permissionSingle['module'], - $permissionSingle['package'], - $permissionSingle['handler'] - ); - } - - if (!isset($permissionSingle['permissions']) || empty($permissionSingle['permissions'])) { - $permissionSingle['permissions'] = sprintf( - '%s-%s-%s-%s', - $permissionSingle['section'], - $permissionSingle['module'], - $permissionSingle['package'], - $permissionSingle['handler'] - ); - } - - $permissionConfig[$permissionSection][$permissionSingleKey] = $permissionSingle; - } - } - - return $permissionConfig; - } -} \ No newline at end of file diff --git a/src/Service/PermissionService.php b/src/Service/PermissionService.php index 573a635..e8e5d46 100644 --- a/src/Service/PermissionService.php +++ b/src/Service/PermissionService.php @@ -4,6 +4,7 @@ use Laminas\Permissions\Rbac\Rbac; use Laminas\Permissions\Rbac\Role; +use Pi\Core\Service\CacheService; use User\Model\Permission\AssertRolesMatches; use User\Repository\PermissionRepositoryInterface; diff --git a/src/Service/RoleService.php b/src/Service/RoleService.php index 8e7679c..510cdb3 100644 --- a/src/Service/RoleService.php +++ b/src/Service/RoleService.php @@ -2,6 +2,7 @@ namespace User\Service; +use Pi\Core\Service\CacheService; use User\Repository\RoleRepositoryInterface; use function in_array; diff --git a/src/Service/TokenService.php b/src/Service/TokenService.php index 21704b6..6601be1 100644 --- a/src/Service/TokenService.php +++ b/src/Service/TokenService.php @@ -6,6 +6,7 @@ use Firebase\JWT\JWT; use Firebase\JWT\Key; use Laminas\Math\Rand; +use Pi\Core\Service\CacheService; class TokenService implements ServiceInterface { diff --git a/src/Service/TranslatorService.php b/src/Service/TranslatorService.php deleted file mode 100644 index d5e6277..0000000 --- a/src/Service/TranslatorService.php +++ /dev/null @@ -1,48 +0,0 @@ -translatorService->translator()->translate($originalText); - * - * Example of php format for translation file - * return [ - * 'test_message' => 'Welcome to our project!', - * ]; - */ -class TranslatorService implements ServiceInterface -{ - /* @var array */ - protected array $config; - - public function __construct($config) - { - $this->config = $config; - } - - public function translator(): Translator - { - $translator = new Translator(); - $translator->setLocale($this->config['locale']); - - foreach ($this->config['translation_file_patterns'] as $pattern) { - $translator->addTranslationFilePattern( - $pattern['type'], - $pattern['base_dir'], - $pattern['pattern'] - ); - } - - return $translator; - } - - public function translate($message): string - { - $translator = $this->translator(); - return $translator->translate($message); - } -} \ No newline at end of file diff --git a/src/Service/UtilityService.php b/src/Service/UtilityService.php deleted file mode 100644 index 9986646..0000000 --- a/src/Service/UtilityService.php +++ /dev/null @@ -1,359 +0,0 @@ - true, - // Force normalize chars - 'normalize_chars' => true, - ]; - - public function __construct($config) - { - $this->config = $config; - } - - /** - * Load date formatter - * - * @param string $date - * @param array $params - * - * @return string - * @see IntlDateFormatter - * Valid values: 'NULL', 'FULL', 'LONG', 'MEDIUM', 'SHORT' - * - */ - public function date(string $date = '', array $params = []): string - { - $date = empty($date) ? time() : $date; - - if (!class_exists('IntlDateFormatter')) { - return date('Y-m-d H:i:s', $date); - } - - // Set params - $local = $params['local'] ?? $this->config['date_local']; - $datetype = $params['datetype'] ?? $this->config['date_type']; - $timetype = $params['timetype'] ?? $this->config['time_type']; - $timezone = $params['timezone'] ?? $this->config['timezone']; - $calendar = $params['calendar'] ?? $this->config['date_calendar']; - $pattern = $params['pattern'] ?? $this->config['date_pattern']; - - $formatter = new IntlDateFormatter($local, $datetype, $timetype, $timezone, $calendar, $pattern); - return $formatter->format($date); - } - - /** - * Escape a string for corresponding context - * - * @param string|array $value - * @param string $context - * String context, valid value: html, htmlAttr, js, url, css - * - * @return string|array - * @see \Laminas\Escaper\Escaper - */ - public function escape(string|array $data, string $context = 'html'): string|array - { - $context = $context ? ucfirst($context) : 'Html'; - $method = 'escape' . $context; - $escaper = new Escaper('utf-8'); - - if (is_array($data)) { - $data = $this->escapeArray($escaper, $data, $method); - } elseif (method_exists($escaper, $method)) { - $data = $escaper->{$method}($data); - } - - return $data; - } - - /** - * Escape a string for corresponding context - * - * @param Escaper $escaper - * @param array $data - * @param string $method - * - * @return array - * @see \Laminas\Escaper\Escaper - */ - public function escapeArray(Escaper $escaper, array $data, string $method): array - { - foreach ($data as $key => $value) { - if (is_array($value)) { - $data[$key] = $this->escapeArray($escaper, $value, $method); - } elseif (is_string($data)) { - $data = $escaper->{$method}($data); - } - } - - return $data; - } - - /** - * Clean a string by stripping HTML tags and removing unrecognizable characters - * - * @param string $text Text to be cleaned - * @param string|null $replacement Replacement for stripped characters - * @param array $pattern Custom pattern array - * - * @return string - */ - public function strip(string $text, string|null $replacement = null, array $pattern = []): string - { - if (empty($pattern)) { - $pattern = [ - "\t", - "\r\n", - "\r", - "\n", - "'", - "\\", - ' ', - ',', - '.', - ';', - ':', - ')', - '(', - '"', - '?', - '!', - '{', - '}', - '[', - ']', - '<', - '>', - '/', - '+', - '-', - '_', - '*', - '=', - '@', - '#', - '$', - '%', - '^', - '&', - ]; - } - $replacement = (null === $replacement) ? ' ' : $replacement; - - // Strip HTML tags - $text = $text ? strip_tags($text) : ''; - // Sanitize - $text = $text ? $this->escape($text) : ''; - - // Clean up - $text = $text ? preg_replace('`\[.*\]`U', '', $text) : ''; - $text = $text ? preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '', $text) : ''; - $text = $text - ? preg_replace( - '/&([a-z])' - . '(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);/i', - '\\1', - $text - ) - : ''; - return $text ? str_replace($pattern, $replacement, $text) : ''; - } - - /** - * @param string $text Text to be cleaned - * @param array $options - * @param array $pattern Custom pattern array - * - * @return string - */ - public function slug(string $text, array $options = [], array $pattern = []): string - { - $options = empty($options) ? $this->slugOptions : $options; - - // List of normalize chars - if (empty($pattern)) { - $pattern = [ - 'Š' => 'S', - 'š' => 's', - 'Ð' => 'Dj', - 'Ž' => 'Z', - 'ž' => 'z', - 'À' => 'A', - 'Á' => 'A', - 'Â' => 'A', - 'Ã' => 'A', - 'Ä' => 'A', - 'Å' => 'A', - 'Æ' => 'A', - 'Ç' => 'C', - 'È' => 'E', - 'É' => 'E', - 'Ê' => 'E', - 'Ë' => 'E', - 'Ì' => 'I', - 'Í' => 'I', - 'Î' => 'I', - 'Ï' => 'I', - 'Ñ' => 'N', - 'Ń' => 'N', - 'Ò' => 'O', - 'Ó' => 'O', - 'Ô' => 'O', - 'Õ' => 'O', - 'Ö' => 'O', - 'Ø' => 'O', - 'Ù' => 'U', - 'Ú' => 'U', - 'Û' => 'U', - 'Ü' => 'U', - 'Ý' => 'Y', - 'Þ' => 'B', - 'ß' => 'Ss', - 'à' => 'a', - 'á' => 'a', - 'â' => 'a', - 'ã' => 'a', - 'ä' => 'a', - 'å' => 'a', - 'æ' => 'a', - 'ç' => 'c', - 'è' => 'e', - 'é' => 'e', - 'ê' => 'e', - 'ë' => 'e', - 'ì' => 'i', - 'í' => 'i', - 'î' => 'i', - 'ï' => 'i', - 'ð' => 'o', - 'ñ' => 'n', - 'ń' => 'n', - 'ò' => 'o', - 'ó' => 'o', - 'ô' => 'o', - 'õ' => 'o', - 'ö' => 'o', - 'ø' => 'o', - 'ù' => 'u', - 'ú' => 'u', - 'û' => 'u', - 'ü' => 'u', - 'ý' => 'y', - 'ý' => 'y', - 'þ' => 'b', - 'ÿ' => 'y', - 'ƒ' => 'f', - 'ă' => 'a', - 'î' => 'i', - 'â' => 'a', - 'ș' => 's', - 'ț' => 't', - 'Ă' => 'A', - 'Î' => 'I', - 'Â' => 'A', - 'Ș' => 'S', - 'Ț' => 'T', - ]; - } - - // Strip HTML tags and remove unrecognizable characters - $text = trim($this->strip($text)); - - // Normalize chars - if (!empty($options['normalize_chars'])) { - $text = strtr($text, $pattern); - } - - // Transform to lower case - if (!empty($options['force_lower'])) { - $text = strtolower($text); - } - - // Transform multi-spaces to slash - return preg_replace('/[\s]+/', '-', $text); - } - - /** - * Locale-dependent formatting/parsing of number - * using pattern strings and/or canned patterns - * - * @param float|int $value - * @param string|null $currency - * @param string|null $locale - * - * @return float|int|string - */ - public function setCurrency(float|int $value, string $currency = null, string $locale = null): float|int|string - { - $result = $value; - $currency = (null === $currency) ? $this->config['currency'] : $currency; - if ($currency) { - $style = 'CURRENCY'; - $formatter = $this->getNumberFormatter($style, $locale); - $result = $formatter->formatCurrency((int)$value, $currency); - } - - return $result; - } - - /** - * Load number formatter - * - * @param string|null $style - * @param string|null $pattern - * @param string|null $locale - * - * @return NumberFormatter|null - * @see NumberFormatter - * - */ - public function getNumberFormatter(string $style = null, string $pattern = null, string $locale = null): ?NumberFormatter - { - if (!class_exists('NumberFormatter')) { - return null; - } - - $locale = $locale ?: $this->config['local']; - $formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY); - - if ($pattern) { - $formatter->setPattern($pattern); - } - - return $formatter; - } - - /** - * Check password is strong - * - * @param $password - * - * @return bool - */ - public function isPasswordStrong($password): bool - { - $pattern = '/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[^a-zA-Z0-9\s]).+$/'; - - return preg_match($pattern, $password) === 1; - } -} \ No newline at end of file diff --git a/src/Validator/OtpValidator.php b/src/Validator/OtpValidator.php index a5d9685..6541d0f 100644 --- a/src/Validator/OtpValidator.php +++ b/src/Validator/OtpValidator.php @@ -3,8 +3,8 @@ namespace User\Validator; use Laminas\Validator\AbstractValidator; +use Pi\Core\Service\CacheService; use User\Service\AccountService; -use User\Service\CacheService; use function array_merge; class OtpValidator extends AbstractValidator diff --git a/src/Validator/PasswordValidator.php b/src/Validator/PasswordValidator.php index 9570020..66cffa6 100644 --- a/src/Validator/PasswordValidator.php +++ b/src/Validator/PasswordValidator.php @@ -3,8 +3,8 @@ namespace User\Validator; use Laminas\Validator\AbstractValidator; +use Pi\Core\Service\UtilityService; use User\Service\AccountService; -use User\Service\UtilityService; use function sprintf; class PasswordValidator extends AbstractValidator