Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit f825056

Browse files
Replace content handlers with events (#37)
* Replace content handlers with events * Final * Remove namespace registration * Don't replace titles
1 parent ace28ce commit f825056

36 files changed

+713
-696
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ To run a website reading from two content services (`blog-articles` and `scholar
1616
content_page:
1717
pages:
1818
blog_article:
19-
handler: 'libero'
2019
path: '/blog/{id}'
2120
service: 'blog-articles'
2221
scholarly_article:
23-
handler: 'libero'
2422
path: '/articles/{id}'
2523
service: 'scholarly-articles'
2624
```

composer.lock

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/packages/dev/content_page.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
content_page:
22
pages:
33
blog_article:
4-
handler: 'libero'
54
path: '/blog/{id}'
65
service: 'blog-articles'
76
scholarly_article:
8-
handler: 'jats'
97
path: '/articles/{id}'
108
service: 'scholarly-articles'
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
content_page:
22
pages:
33
blog_article:
4-
handler: 'libero'
54
path: '/blog/{id}'
65
service: 'blog-articles'
76
scholarly_article:
8-
handler: 'libero'
97
path: '/articles/{id}'
108
service: 'scholarly-articles'

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
parameters:
22
ignoreErrors:
3+
- '~^Access to an undefined property FluentDOM\\DOM\\Xpath::\$registerNodeNamespaces\.$~'
34
- '~^Call to an undefined method FluentDOM\\DOM\\Node\\.+?::getNodePath\(\)\.$~'
45
- '~^Cannot cast FluentDOM\\DOM\\Node\\.+? to string\.$~'
56
- '~^Cannot call method ([a-z]+)Node\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.$~'
7+
- '~^Method [^\s]+? should return FluentDOM\\DOM\\Element but returns DOMElement\.$~'
68
- '~^Service "csa_guzzle\.mock\.storage" is not registered in the container\.$~'
79
level: max
810
paths:

templates/page.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<meta charset="utf-8">
88

9-
<title>{{ include('@LiberoPatterns/text.html.twig', {nodes: title})|striptags }}</title>
9+
<title>{{ title }}</title>
1010

1111
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
1212

vendor-extra/ContentPageBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"punic/punic": "^3.3",
2222
"symfony/config": "^4.1",
2323
"symfony/dependency-injection": "^4.1",
24+
"symfony/event-dispatcher": "^4.1",
2425
"symfony/http-foundation": "^4.1",
2526
"symfony/http-kernel": "^4.1",
2627
"symfony/routing": "^4.1",

vendor-extra/ContentPageBundle/src/ContentPageBundle.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
namespace Libero\ContentPageBundle;
66

7-
use Libero\ContentPageBundle\DependencyInjection\Compiler\ContentHandlerPass;
8-
use Symfony\Component\DependencyInjection\ContainerBuilder;
97
use Symfony\Component\HttpKernel\Bundle\Bundle;
108

119
final class ContentPageBundle extends Bundle
1210
{
13-
public function build(ContainerBuilder $container) : void
14-
{
15-
$container->addCompilerPass(new ContentHandlerPass());
16-
}
1711
}

vendor-extra/ContentPageBundle/src/Controller/ContentController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
use FluentDOM;
88
use GuzzleHttp\ClientInterface;
9-
use Libero\ContentPageBundle\Handler\ContentHandler;
9+
use Libero\ContentPageBundle\Event\CreateContentPageEvent;
1010
use Psr\Http\Message\ResponseInterface;
11+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1112
use Symfony\Component\HttpFoundation\Request;
1213
use Symfony\Component\HttpFoundation\Response;
1314
use Twig\Environment;
@@ -16,7 +17,7 @@
1617
final class ContentController
1718
{
1819
private $client;
19-
private $contentHandler;
20+
private $dispatcher;
2021
private $service;
2122
private $template;
2223
private $twig;
@@ -26,13 +27,13 @@ public function __construct(
2627
string $service,
2728
Environment $twig,
2829
string $template,
29-
ContentHandler $contentHandler
30+
EventDispatcherInterface $dispatcher
3031
) {
3132
$this->client = $client;
3233
$this->service = $service;
3334
$this->twig = $twig;
3435
$this->template = $template;
35-
$this->contentHandler = $contentHandler;
36+
$this->dispatcher = $dispatcher;
3637
}
3738

3839
public function __invoke(Request $request, string $id) : Response
@@ -48,17 +49,20 @@ public function __invoke(Request $request, string $id) : Response
4849
)
4950
->then(
5051
function (ResponseInterface $response) use ($request) : Response {
51-
$dom = FluentDOM::load((string) $response->getBody());
52+
$document = FluentDOM::load((string) $response->getBody());
5253

5354
$context = [
5455
'lang' => $request->getLocale(),
5556
'dir' => text_direction($request->getLocale()),
5657
];
5758

59+
$event = new CreateContentPageEvent($document, $context);
60+
$this->dispatcher->dispatch($event::NAME, $event);
61+
5862
return new Response(
5963
$this->twig->render(
6064
$this->template,
61-
$this->contentHandler->handle($dom->documentElement, $context)
65+
$event->getContext() + ['title' => $event->getTitle(), 'content' => $event->getContent()]
6266
)
6367
);
6468
}

vendor-extra/ContentPageBundle/src/DependencyInjection/Compiler/ContentHandlerPass.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)