diff --git a/docs/en/middleware.rst b/docs/en/middleware.rst index f14c503f..771f1840 100644 --- a/docs/en/middleware.rst +++ b/docs/en/middleware.rst @@ -80,33 +80,33 @@ implementing the ``Authorization\IdentityInterface`` and using the class User extends Entity implements IdentityInterface { /** - * Authorization\IdentityInterface method + * @inheritDoc */ - public function can($action, $resource): bool + public function can(string $action, mixed $resource): bool { return $this->authorization->can($this, $action, $resource); } /** - * Authorization\IdentityInterface method + * @inheritDoc */ - public function canResult($action, $resource): ResultInterface + public function canResult(string $action, mixed $resource): ResultInterface { return $this->authorization->canResult($this, $action, $resource); } /** - * Authorization\IdentityInterface method + * @inheritDoc */ - public function applyScope($action, $resource) + public function applyScope(string $action, mixed $resource, mixed ...$optionalArgs): mixed { - return $this->authorization->applyScope($this, $action, $resource); + return $this->authorization->applyScope($this, $action, $resource, ...$optionalArgs); } /** - * Authorization\IdentityInterface method + * @inheritDoc */ - public function getOriginalData() + public function getOriginalData(): \ArrayAccess|array { return $this; } @@ -147,7 +147,7 @@ If you also use the Authentication plugin make sure to implement both interfaces class User extends Entity implements AuthorizationIdentity, AuthenticationIdentity { ... - + /** * Authentication\IdentityInterface method * @@ -157,7 +157,7 @@ If you also use the Authentication plugin make sure to implement both interfaces { return $this->id; } - + ... } @@ -202,7 +202,7 @@ Both redirect handlers share the same configuration options: For example:: use Authorization\Exception\MissingIdentityException; - + $middlewareQueue->add(new AuthorizationMiddleware($this, [ 'unauthorizedHandler' => [ 'className' => 'Authorization.Redirect', @@ -214,14 +214,14 @@ For example:: ], ], ])); - + All handlers get the thrown exception object given as a parameter. This exception will always be an instance of ``Authorization\Exception\Exception``. -In this example the ``Authorization.Redirect`` handler just gives you the option to +In this example the ``Authorization.Redirect`` handler just gives you the option to specify which exceptions you want to listen to. So in this example where we use the ``Authorization.Redirect`` handler we can -add other ``Authorization\Exception\Exception`` based exceptions to the +add other ``Authorization\Exception\Exception`` based exceptions to the ``execeptions`` array if we want to handle them gracefully:: 'exceptions' => [ @@ -239,7 +239,7 @@ Add a flash message after being redirected by an unauthorized request Currently there is no straightforward way to add a flash message to the unauthorized redirect. -Therefore you need to create your own Handler which adds the flash message (or any +Therefore you need to create your own Handler which adds the flash message (or any other logic you want to happen on redirect) How to create a custom UnauthorizedHandler @@ -268,10 +268,10 @@ How to create a custom UnauthorizedHandler #. Tell the AuthorizationMiddleware that it should use your new custom Handler:: // in your src/Application.php - + use Authorization\Exception\MissingIdentityException; use Authorization\Exception\ForbiddenException; - + $middlewareQueue->add(new AuthorizationMiddleware($this, [ 'unauthorizedHandler' => [ 'className' => 'CustomRedirect', // <--- see here @@ -284,12 +284,12 @@ How to create a custom UnauthorizedHandler 'custom_param' => true, ], ])); - + As you can see you still have the same config parameters as if we are using ``Authorization.Redirect`` as a className. This is, because we extend our handler based on the RedirectHandler present in the plugin. Therefore all that functionality is present + our own funtionality in the ``handle()`` function. - + The ``custom_param`` appears in the ``$options`` array given to you in the ``handle()`` function inside your ``CustomRedirectHandler`` if you wish to add some more config parameters to your functionality. -You can look at `CakeRedirectHandler `__ or `RedirectHandler `__ +You can look at `CakeRedirectHandler `__ or `RedirectHandler `__ how such a Handler can/should look like. diff --git a/docs/fr/middleware.rst b/docs/fr/middleware.rst index 66c6293a..b7ea99c9 100644 --- a/docs/fr/middleware.rst +++ b/docs/fr/middleware.rst @@ -84,39 +84,39 @@ utilisant l'option ``identityDecorator`` du middleware. Pour commencer, mettons class User extends Entity implements IdentityInterface { /** - * Méthode Authorization\IdentityInterface + * @inheritDoc */ - public function can($action, $resource): bool + public function can(string $action, mixed $resource): bool { return $this->authorization->can($this, $action, $resource); } /** - * Méthode Authorization\IdentityInterface + * @inheritDoc */ - public function canResult($action, $resource): ResultInterface + public function canResult(string $action, mixed $resource): ResultInterface { return $this->authorization->canResult($this, $action, $resource); } /** - * Méthode Authorization\IdentityInterface + * @inheritDoc */ - public function applyScope($action, $resource) + public function applyScope(string $action, mixed $resource, mixed ...$optionalArgs): mixed { - return $this->authorization->applyScope($this, $action, $resource); + return $this->authorization->applyScope($this, $action, $resource, ...$optionalArgs); } /** - * Méthode Authorization\IdentityInterface + * @inheritDoc */ - public function getOriginalData() + public function getOriginalData(): \ArrayAccess|array { return $this; } /** - * Setter utilisé par le middleware. + * Setter to be used by the middleware. */ public function setAuthorization(AuthorizationServiceInterface $service) { @@ -152,7 +152,7 @@ deux interfaces.:: class User extends Entity implements AuthorizationIdentity, AuthenticationIdentity { ... - + /** * Méthode Authentication\IdentityInterface * @@ -162,7 +162,7 @@ deux interfaces.:: { return $this->id; } - + ... } @@ -209,7 +209,7 @@ configuration: à un paramètre query de l'URL de redirection (par défaut ``redirect``). * ``statusCode`` - le code de statut HTTP d'une redirection, par défaut ``302``. -Par exemple:: +Par exemple:: use Authorization\Exception\MissingIdentityException; @@ -235,7 +235,7 @@ Ainsi, dans cet exemple où nous utilisons le gestionnaire ``Authorization.Redirect``, nous pouvons ajouter au tableau ``exceptions`` d'autres exceptions basées sur ``Authorization\Exception\Exception`` si nous voulons qu'elles soient traitées convenablement:: - + 'exceptions' => [ MissingIdentityException::class, ForbiddenException::class @@ -286,7 +286,7 @@ Comment créer un UnauthorizedHandler personnalisé use Authorization\Exception\MissingIdentityException; use Authorization\Exception\ForbiddenException; - + $middlewareQueue->add(new AuthorizationMiddleware($this, [ 'unauthorizedHandler' => [ 'className' => 'CustomRedirect', // <--- c'est ici ! @@ -312,5 +312,5 @@ dans la fonction ``handle()`` à l'intérieur de votre ``CustomRedirectHandler`` si vous souhaitez ajouter quelques paramètres de configuration supplémentaires à vos fonctionnalités personnalisées. -Vous pouvez consulter les classes `CakeRedirectHandler `__ ou `RedirectHandler `__ +Vous pouvez consulter les classes `CakeRedirectHandler `__ ou `RedirectHandler `__ pour voir à quoi un Handler pourrait/devrait ressembler. diff --git a/docs/ja/middleware.rst b/docs/ja/middleware.rst index 0848fde6..3b9ee954 100644 --- a/docs/ja/middleware.rst +++ b/docs/ja/middleware.rst @@ -67,33 +67,37 @@ Userクラスを識別子として使用する class User extends Entity implements IdentityInterface { /** - * Authorization\IdentityInterface method + * @inheritDoc */ - public function can($action, $resource): bool + public function can(string $action, mixed $resource): bool { return $this->authorization->can($this, $action, $resource); } + /** - * Authorization\IdentityInterface method + * @inheritDoc */ - public function canResult($action, $resource): ResultInterface + public function canResult(string $action, mixed $resource): ResultInterface { return $this->authorization->canResult($this, $action, $resource); } + /** - * Authorization\IdentityInterface method + * @inheritDoc */ - public function applyScope($action, $resource) + public function applyScope(string $action, mixed $resource, mixed ...$optionalArgs): mixed { - return $this->authorization->applyScope($this, $action, $resource); + return $this->authorization->applyScope($this, $action, $resource, ...$optionalArgs); } + /** - * Authorization\IdentityInterface method + * @inheritDoc */ - public function getOriginalData() + public function getOriginalData(): \ArrayAccess|array { return $this; } + /** * Setter to be used by the middleware. */ @@ -123,7 +127,7 @@ Authentication(認証)プラグインを使っているなら、両方のイン class User extends Entity implements AuthorizationIdentity, AuthenticationIdentity { ... - + /** * Authentication\IdentityInterface method * @@ -249,4 +253,4 @@ Authentication(認証)プラグインを使っているなら、両方のイン これは、プラグインに存在する RedirectHandler をベースに私たちのハンドラを拡張しているからです。したがって、すべての機能は ``handle()`` 関数内に存在し、私たち自身の機能は ``handle()`` 内に存在します。 カスタムパラメータを追加したい場合は、 ``CustomRedirectHandler`` 内の ``handle()`` 関数で指定した ``$options`` 配列に ``custom_param`` が含まれます。 -こちらもご覧ください `CakeRedirectHandler `__ or `RedirectHandler `__ +こちらもご覧ください `CakeRedirectHandler `__ or `RedirectHandler `__ diff --git a/src/IdentityDecorator.php b/src/IdentityDecorator.php index 6eb9c79f..f754bcc0 100644 --- a/src/IdentityDecorator.php +++ b/src/IdentityDecorator.php @@ -60,7 +60,7 @@ public function __construct(AuthorizationServiceInterface $service, ArrayAccess| /** * @inheritDoc */ - public function can(string $action, $resource): bool + public function can(string $action, mixed $resource): bool { return $this->authorization->can($this, $action, $resource); } @@ -68,7 +68,7 @@ public function can(string $action, $resource): bool /** * @inheritDoc */ - public function canResult(string $action, $resource): ResultInterface + public function canResult(string $action, mixed $resource): ResultInterface { return $this->authorization->canResult($this, $action, $resource); }