for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace BEAR\QueryRepository;
use BEAR\RepositoryModule\Annotation\AbstractCacheControl;
use BEAR\Resource\ResourceObject;
use Override;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
use function assert;
final class HttpCacheInterceptor implements MethodInterceptor
{
/**
* {@inheritDoc}
*/
#[Override]
public function invoke(MethodInvocation $invocation)
$cacheControl = $invocation->getMethod()->getDeclaringClass()->getAnnotation(AbstractCacheControl::class);
$ro = $invocation->proceed();
assert($ro instanceof ResourceObject);
if ($ro->code === 200 && $cacheControl instanceof AbstractCacheControl) {
$ro->headers[Header::CACHE_CONTROL] = (string) $cacheControl;
}
return $ro;