Skip to content

Commit

Permalink
Merge pull request #124 from bearsunday/interface
Browse files Browse the repository at this point in the history
Inject through interface
  • Loading branch information
koriym authored Dec 6, 2022
2 parents e489b23 + 1fd5b17 commit 0529578
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/DonutCacheModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected function configure(): void
private function installAopClassModule(): void
{
$this->bind(DonutRepository::class)->in(Scope::SINGLETON);
$this->bind(DonutRendererInterface::class)->to(DonutRenderer::class);
$this->bindPriorityInterceptor(
$this->matcher->annotatedWith(CacheableResponse::class),
$this->matcher->startsWith('onGet'),
Expand Down
2 changes: 1 addition & 1 deletion src/DonutRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use function sprintf;
use function str_replace;

final class DonutRenderer
final class DonutRenderer implements DonutRendererInterface
{
/** @var list<string> */
private array $searches = [];
Expand Down
12 changes: 12 additions & 0 deletions src/DonutRendererInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace BEAR\QueryRepository;

interface DonutRendererInterface
{
public function setView(string $uri, string $view): void;

public function render(string $template): string;
}
4 changes: 2 additions & 2 deletions src/DonutRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
final class DonutRepository implements DonutRepositoryInterface
{
public function __construct(
private QueryRepository $queryRepository,
private QueryRepositoryInterface $queryRepository,
private HeaderSetter $headerSetter,
private ResourceStorageInterface $resourceStorage,
private ResourceInterface $resource,
private CdnCacheControlHeaderSetterInterface $cdnCacheControlHeaderSetter,
private RepositoryLoggerInterface $logger,
private DonutRenderer $renderer,
private DonutRendererInterface $renderer,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/DonutRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class DonutRequest implements Stringable
{
public function __construct(
private AbstractRequest $request,
private DonutRenderer $donutStorage,
private DonutRendererInterface $donutStorage,
private SurrogateKeys $etags,
) {
}
Expand Down
1 change: 1 addition & 0 deletions src/QueryRepositoryModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected function configure(): void
$this->bind(ResourceStorageInterface::class)->to(ResourceStorage::class);
$this->bind(MatchQueryInterface::class)->to(MatchQuery::class)->in(Scope::SINGLETON);
$this->bind(UriTag::class)->in(Scope::SINGLETON);
$this->bind(RefreshAnnotatedCommand::class);
// #[Cacheable]
$this->install(new CacheableModule());
// #[CacheableResponse]
Expand Down
4 changes: 2 additions & 2 deletions src/ResourceDonut.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public function refresh(ResourceInterface $resource, ResourceObject $ro): Resour
return $ro;
}

public function render(ResourceObject $ro, DonutRenderer $storage): ResourceObject
public function render(ResourceObject $ro, DonutRendererInterface $storage): ResourceObject
{
$view = $storage->render($this->template);
$ro->view = $view;

return $ro;
}

public static function create(ResourceObject $ro, DonutRenderer $storage, SurrogateKeys $etags, int|null $ttl, bool $isCacheble): self
public static function create(ResourceObject $ro, DonutRendererInterface $storage, SurrogateKeys $etags, int|null $ttl, bool $isCacheble): self
{
assert(is_iterable($ro->body));
/** @var mixed $maybeRequest */
Expand Down

0 comments on commit 0529578

Please sign in to comment.