Skip to content

Commit

Permalink
デバッグ用出力の除去、インターセプター束縛設定のmatcherを最適化
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimita committed Sep 18, 2022
1 parent 8cc9871 commit 150614d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
13 changes: 5 additions & 8 deletions src/Interceptor/AuthCheckInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
use Ray\Di\Di\Named;
use RuntimeException;

use function assert;

class AuthCheckInterceptor implements MethodInterceptor
{
Expand All @@ -26,22 +27,18 @@ public function __construct(
*/
public function invoke(MethodInvocation $invocation)
{
$resourceObject = $invocation->getThis();
if (! $resourceObject instanceof AuthBaseResourceObject) {
// TODO: 後で消す(インターセプタ束縛を matcher->any() で設定してるところを直すときに)
throw new RuntimeException('AuthBaseResourceObject にだけ使用できるインターセプターです');
}

// メソッド実行前の処理
if ($this->cwSession->isNotAuthorized()) {
$resourceObject = $invocation->getThis();
assert($resourceObject instanceof AuthBaseResourceObject);

return $this->makeError($resourceObject);
}

// メソッド実行
$result = $invocation->proceed();

// メソッド実行後の処理
// TODO: 後で消す
if ($result instanceof AuthBaseResourceObject) {
$result->setDebugMessage('認証済み確認後の処理を通過');
}
Expand Down
7 changes: 4 additions & 3 deletions src/Module/CwAuthModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Cw\LearnBear\Infrastructure\Authentication\CwSession;
use Cw\LearnBear\Infrastructure\Authentication\IdentityRepository;
use Cw\LearnBear\Interceptor\AuthCheckInterceptor;
use Cw\LearnBear\Resource\AuthBaseResourceObject;
use Ray\Di\AbstractModule;

class CwAuthModule extends AbstractModule
Expand All @@ -23,9 +24,9 @@ protected function configure()
$this->bind(IdentityRepositoryInterface::class)->to(IdentityRepository::class);

$this->bindInterceptor(
$this->matcher->any(),
$this->matcher->annotatedWith(CheckAuth::class),
[AuthCheckInterceptor::class],
$this->matcher->subclassesOf(AuthBaseResourceObject::class), // AuthBaseResourceObjectの継承または実装クラスの
$this->matcher->annotatedWith(CheckAuth::class), // @CheckAuthアノテーションがアノテートされているメソッドには
[AuthCheckInterceptor::class], // AuthCheckInterceptorインターセプターを束縛
);
}
}
4 changes: 0 additions & 4 deletions var/templates/Page/Next.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
{% block title %}Weekday{% endblock %}
{% block content %}

{% if debug is defined %}
<pre>{{ debug }}</pre>
{% endif %}

<h1>next</h1>
<div>The weekday of {{ year }}/{{ month }}/{{ day }} is {{ weekday.weekday }}.</div>
<div>
Expand Down

0 comments on commit 150614d

Please sign in to comment.