0

休み時間はコントローラー

/**

 * !RespondsWith Layouts

 * !Prefix user/

 */

class UserController extends Controller 

{
......
}

Iwrapper を使用して UserController のすべてのメソッドをラップしたいと考えています。IWrapper を使用して通常のクラスのメソッドをラップする方法を知っています。しかし、コントローラーの場合、UserController がインスタンス化されておらず、そのメソッドがリセス コントローラーによって自動的に呼び出されるため、私はそれを行うことができません。

4

1 に答える 1

1

注釈を使用して、コントローラー クラスにラッパーを追加できます。たとえば、コントローラー「nas」があります

/**
 * !RespondsWith Json,CSV
 * !Prefix nas/
 */
 class NasController extends Controller {

     /** 
      * !Route GET
      * !VerifyPermission Module: data, Permission: read, UnauthorizedAction: noEntry
      */
      function index() {
      }
 }

VerifyPermission アノテーションは、expand メソッドにラッパーを追加します。

Library::import('recess.lang.Annotation');
Library::import('cirrusWorks.wrappers.VerifyPermissionWrapper');

class VerifyPermissionAnnotation extends Annotation {

    protected function expand($class, $reflection, $descriptor) {
        $module = $this->module;
        $permission = $this->permission;
        $unauthorizedAction = $this->unauthorizedaction;

        $descriptor->addWrapper('serve',new VerifyPermissionWrapper($module,$permission,$unauthorizedAction, $reflection->getName()));
        /* ... */
        return $descriptor;
    }
 }

次に、VerifyPermissionWrapper を作成すると、標準メソッドがクラス メソッド (before()、after()、combine()) にラップされます。

class VerifyPermissionWrapper implements IWrapper {
    function __construct($module, $permission, $action, $method) {
        $this->module = $module;
        $this->permission = $permission;
        $this->action = $action;
        $this->method = $method;
    }

    function before($controller, &$args) {
        error_log('Before {$this->action} on {$this->method}');
    }
}
于 2012-03-03T11:30:29.770 に答える