diff --git a/composer.json b/composer.json index c332983..c325e50 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "daycry/restful", "description": "Rest Server for Codeigniter 4", - "homepage": "https://github.com/daycry/restfull", + "homepage": "https://github.com/daycry/restful", "authors": [ { @@ -19,7 +19,8 @@ "daycry/jwt": "^1.0", "daycry/class-finder": "^2.0", "daycry/cronjob": "^2.0", - "daycry/settings": "^1" + "daycry/settings": "^1", + "daycry/exceptions": "*" }, "require-dev": { @@ -79,6 +80,9 @@ ] }, "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true, "allow-plugins": { "phpstan/extension-installer": true } diff --git a/src/Auth.php b/src/Auth.php index 55c3d75..2c2e16e 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -4,12 +4,12 @@ namespace Daycry\RestFul; +use Daycry\Exceptions\Interfaces\BaseExceptionInterface; use Daycry\RestFul\Libraries\Authentication; use Daycry\RestFul\Exceptions\AuthenticationException; use Daycry\RestFul\Interfaces\AuthenticatorInterface; use Daycry\RestFul\Entities\User; use Daycry\RestFul\Models\UserModel; -use Daycry\RestFul\Interfaces\BaseException; /** * @method Result attempt(array $credentials) @@ -144,7 +144,7 @@ public function __call(string $method, array $args) if ($authenticate && method_exists($authenticate, $method)) { return $authenticate->{$method}(...$args); } - } catch(BaseException $ex) { + } catch(BaseExceptionInterface $ex) { return false; } } diff --git a/src/Authenticators/AccessToken.php b/src/Authenticators/AccessToken.php index 7a048c1..d904132 100644 --- a/src/Authenticators/AccessToken.php +++ b/src/Authenticators/AccessToken.php @@ -8,7 +8,6 @@ use Daycry\RestFul\Exceptions\AuthenticationException; use Daycry\RestFul\Models\UserModel; use Daycry\RestFul\Models\UserIdentityModel; -use CodeIgniter\Config\Services; use Daycry\RestFul\Entities\User; class AccessToken extends Base implements AuthenticatorInterface diff --git a/src/Exceptions/AuthenticationException.php b/src/Exceptions/AuthenticationException.php index d1529d3..b198fc0 100644 --- a/src/Exceptions/AuthenticationException.php +++ b/src/Exceptions/AuthenticationException.php @@ -4,7 +4,7 @@ namespace Daycry\RestFul\Exceptions; -use Daycry\RestFul\Exceptions\RuntimeException; +use Daycry\Exceptions\Exceptions\RuntimeException; class AuthenticationException extends RuntimeException { diff --git a/src/Exceptions/AuthorizationException.php b/src/Exceptions/AuthorizationException.php index d3a92dc..d21c390 100644 --- a/src/Exceptions/AuthorizationException.php +++ b/src/Exceptions/AuthorizationException.php @@ -4,7 +4,7 @@ namespace Daycry\RestFul\Exceptions; -use Daycry\RestFul\Exceptions\RuntimeException; +use Daycry\Exceptions\Exceptions\RuntimeException; class AuthorizationException extends RuntimeException { diff --git a/src/Exceptions/CorsException.php b/src/Exceptions/CorsException.php index 378637a..56f2a8f 100644 --- a/src/Exceptions/CorsException.php +++ b/src/Exceptions/CorsException.php @@ -4,7 +4,7 @@ namespace Daycry\RestFul\Exceptions; -use Daycry\RestFul\Exceptions\RuntimeException; +use Daycry\Exceptions\Exceptions\RuntimeException; class CorsException extends RuntimeException { diff --git a/src/Exceptions/DatabaseException.php b/src/Exceptions/DatabaseException.php index a415fa5..a90948a 100644 --- a/src/Exceptions/DatabaseException.php +++ b/src/Exceptions/DatabaseException.php @@ -4,6 +4,8 @@ namespace Daycry\RestFul\Exceptions; +use Daycry\Exceptions\Exceptions\RuntimeException; + class DatabaseException extends RuntimeException { } diff --git a/src/Exceptions/FailTooManyRequestsException.php b/src/Exceptions/FailTooManyRequestsException.php index 30c19db..6d4ac32 100644 --- a/src/Exceptions/FailTooManyRequestsException.php +++ b/src/Exceptions/FailTooManyRequestsException.php @@ -2,7 +2,7 @@ namespace Daycry\RestFul\Exceptions; -use Daycry\RestFul\Exceptions\RuntimeException; +use Daycry\Exceptions\Exceptions\RuntimeException; class FailTooManyRequestsException extends RuntimeException { diff --git a/src/Exceptions/ForbiddenException.php b/src/Exceptions/ForbiddenException.php index f1ecb0f..711dbca 100644 --- a/src/Exceptions/ForbiddenException.php +++ b/src/Exceptions/ForbiddenException.php @@ -4,7 +4,7 @@ namespace Daycry\RestFul\Exceptions; -use Daycry\RestFul\Exceptions\RuntimeException; +use Daycry\Exceptions\Exceptions\RuntimeException; use Config\Services; class ForbiddenException extends RuntimeException diff --git a/src/Exceptions/LogicException.php b/src/Exceptions/LogicException.php index 9e9c391..c72e1ec 100644 --- a/src/Exceptions/LogicException.php +++ b/src/Exceptions/LogicException.php @@ -4,8 +4,8 @@ namespace Daycry\RestFul\Exceptions; -use Daycry\RestFul\Interfaces\BaseException; +use Daycry\Exceptions\Interfaces\BaseExceptionInterface; -class LogicException extends \LogicException implements BaseException +class LogicException extends \LogicException implements BaseExceptionInterface { } diff --git a/src/Exceptions/RuntimeException.php b/src/Exceptions/RuntimeException.php deleted file mode 100644 index f28c5db..0000000 --- a/src/Exceptions/RuntimeException.php +++ /dev/null @@ -1,11 +0,0 @@ -setAuthorized(false) ->setResponseCode($ex->getCode()) diff --git a/src/Interfaces/BaseException.php b/src/Interfaces/BaseException.php deleted file mode 100644 index f694831..0000000 --- a/src/Interfaces/BaseException.php +++ /dev/null @@ -1,14 +0,0 @@ -id(); - } catch(BaseException $ex) { + } catch(BaseExceptionInterface $ex) { $userId = null; } diff --git a/src/RestFul.php b/src/RestFul.php index 33ed7e3..c231a2a 100644 --- a/src/RestFul.php +++ b/src/RestFul.php @@ -15,10 +15,10 @@ use Daycry\RestFul\Validators\Whitelist; use Daycry\RestFul\Validators\Limit; use Daycry\RestFul\Libraries\Logger; -use Daycry\RestFul\Interfaces\BaseException; use Daycry\RestFul\Exceptions\ForbiddenException; use Daycry\RestFul\Models\AttemptModel; use Config\Mimes; +use Daycry\Exceptions\Interfaces\BaseExceptionInterface; use ReflectionProperty; use stdClass; @@ -152,7 +152,7 @@ public function __destruct() * @param string $method * @param array $params The params passed to the controller method * - * @throws BaseException + * @throws BaseExceptionInterface */ public function _remap($method, ...$params) { @@ -199,7 +199,7 @@ public function _remap($method, ...$params) return call_user_func_array([ $this, $method ], $params); - } catch (BaseException $ex) { + } catch (BaseExceptionInterface $ex) { if(property_exists($ex, 'authorized')) { $this->_isRequestAuthorized = (new ReflectionProperty($ex, 'authorized'))->getValue(); diff --git a/src/Traits/Authenticable.php b/src/Traits/Authenticable.php index 0ace5db..24fcd27 100644 --- a/src/Traits/Authenticable.php +++ b/src/Traits/Authenticable.php @@ -7,7 +7,7 @@ use Daycry\RestFul\Entities\Endpoint; use Daycry\RestFul\Exceptions\AuthenticationException; use Daycry\RestFul\Validators\AccessToken; -use Daycry\RestFul\Interfaces\BaseException; +use Daycry\Exceptions\Interfaces\BaseExceptionInterface; trait Authenticable { @@ -34,7 +34,7 @@ public function doLogin(?Endpoint $endpoint = null) } } - } catch(BaseException $ex) { + } catch(BaseExceptionInterface $ex) { if($strictApiAndAuth || !$alias) { throw $ex; } @@ -46,7 +46,7 @@ public function doLogin(?Endpoint $endpoint = null) $authenticator->authenticate(); } - } catch(BaseException $ex) { + } catch(BaseExceptionInterface $ex) { if($strictApiAndAuth || (!$strictApiAndAuth && !$user)) { throw $ex; } diff --git a/src/Validators/Limit.php b/src/Validators/Limit.php index 1cbfdd0..70c0f67 100644 --- a/src/Validators/Limit.php +++ b/src/Validators/Limit.php @@ -7,7 +7,7 @@ use Daycry\RestFul\Models\LimitModel; use CodeIgniter\I18n\Time; use Daycry\RestFul\Exceptions\FailTooManyRequestsException; -use Daycry\RestFul\Interfaces\BaseException; +use Daycry\Exceptions\Interfaces\BaseExceptionInterface; class Limit {