Skip to content

Commit 04c51c7

Browse files
authored
Merge pull request #25 from kdambekalns/feature/neos-5-compatibility
Neos 5.0 compatibility
2 parents 7780d7e + 6a5434b commit 04c51c7

File tree

13 files changed

+181
-93
lines changed

13 files changed

+181
-93
lines changed

Classes/Command/AtomImportCommandController.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace RobertLemke\Plugin\Blog\Command;
35

46
/*
@@ -11,14 +13,18 @@
1113
* source code.
1214
*/
1315

14-
use Neos\Eel\FlowQuery\FlowQuery;
15-
use Neos\Flow\Annotations as Flow;
16-
use Neos\Flow\Cli\CommandController;
17-
use Neos\Neos\Domain\Service\ContentContextFactory;
1816
use Neos\ContentRepository\Domain\Model\NodeInterface;
1917
use Neos\ContentRepository\Domain\Model\NodeTemplate;
2018
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
19+
use Neos\ContentRepository\Exception\NodeException;
20+
use Neos\ContentRepository\Exception\NodeExistsException;
21+
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
2122
use Neos\ContentRepository\Utility;
23+
use Neos\Eel\Exception;
24+
use Neos\Eel\FlowQuery\FlowQuery;
25+
use Neos\Flow\Annotations as Flow;
26+
use Neos\Flow\Cli\CommandController;
27+
use Neos\Neos\Domain\Service\ContentContextFactory;
2228

2329
/**
2430
* BlogCommand command controller for the RobertLemke.Plugin.Blog package
@@ -56,8 +62,12 @@ class AtomImportCommandController extends CommandController
5662
* @param string $targetNode The target node (expressed as a FlowQuery find condition)
5763
* @param string $atomFile The atom file to import
5864
* @return void
65+
* @throws NodeException
66+
* @throws NodeExistsException
67+
* @throws NodeTypeNotFoundException
68+
* @throws Exception
5969
*/
60-
public function migrateCommand($workspace, $targetNode, $atomFile)
70+
public function migrateCommand(string $workspace, string $targetNode, string $atomFile): void
6171
{
6272
if (!class_exists(\SimplePie::class)) {
6373
$this->outputLine('The Atom import needs simplepie/simplepie, which you can install using composer.');
@@ -138,13 +148,13 @@ public function migrateCommand($workspace, $targetNode, $atomFile)
138148
$postNode = $this->blogNode->createNodeFromTemplate($nodeTemplate, $slug);
139149
$postNode->getNode('main')->createNode(uniqid('node'), $textNodeType)->setProperty('text', $item->get_content());
140150

141-
$postComments = isset($comments[$item->get_id()]) ? $comments[$item->get_id()] : [];
151+
$postComments = $comments[$item->get_id()] ?? [];
142152
if ($postComments !== []) {
143153
/** @var NodeInterface $commentsNode */
144154
$commentsNode = $postNode->getNode('comments');
145155
/** @var $postComment \SimplePie_Item */
146156
foreach ($postComments as $postComment) {
147-
$commentNode = $commentsNode->createNode(uniqid('comment-'), $commentNodeType);
157+
$commentNode = $commentsNode->createNode(uniqid('comment-', true), $commentNodeType);
148158
$commentNode->setProperty('author', html_entity_decode($postComment->get_author()->get_name(), ENT_QUOTES, 'utf-8'));
149159
$commentNode->setProperty('emailAddress', $postComment->get_author()->get_email());
150160
$commentNode->setProperty('uri', $postComment->get_author()->get_link());
@@ -170,8 +180,10 @@ public function migrateCommand($workspace, $targetNode, $atomFile)
170180
/**
171181
* @param array $tags
172182
* @return array<NodeInterface>
183+
* @throws NodeExistsException
184+
* @throws NodeTypeNotFoundException
173185
*/
174-
protected function getTagNodes(array $tags)
186+
protected function getTagNodes(array $tags): array
175187
{
176188
$tagNodes = [];
177189

Classes/Controller/CommentController.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace RobertLemke\Plugin\Blog\Controller;
35

46
/*
@@ -11,11 +13,13 @@
1113
* source code.
1214
*/
1315

14-
use RobertLemke\Akismet\Service;
15-
use Neos\Flow\Annotations as Flow;
16-
use Neos\Flow\Mvc\Controller\ActionController;
1716
use Neos\ContentRepository\Domain\Model\NodeInterface;
1817
use Neos\ContentRepository\Domain\Model\NodeTemplate;
18+
use Neos\ContentRepository\Exception\NodeException;
19+
use Neos\Flow\Annotations as Flow;
20+
use Neos\Flow\Mvc\Controller\ActionController;
21+
use RobertLemke\Akismet\Exception\ConnectionException;
22+
use RobertLemke\Akismet\Service;
1923

2024
/**
2125
* Comments controller for the Blog package
@@ -44,8 +48,10 @@ protected function initializeAction()
4448
* @param NodeInterface $postNode The post node which will contain the new comment
4549
* @param NodeTemplate<RobertLemke.Plugin.Blog:Comment> $newComment
4650
* @return string
51+
* @throws NodeException
52+
* @throws ConnectionException
4753
*/
48-
public function createAction(NodeInterface $postNode, NodeTemplate $newComment)
54+
public function createAction(NodeInterface $postNode, NodeTemplate $newComment): string
4955
{
5056
# Workaround until we can validate node templates properly:
5157
if (strlen($newComment->getProperty('author')) < 2) {
@@ -64,7 +70,7 @@ public function createAction(NodeInterface $postNode, NodeTemplate $newComment)
6470
$newComment->setProperty('author', filter_var($newComment->getProperty('author'), FILTER_SANITIZE_STRIPPED));
6571
$newComment->setProperty('emailAddress', filter_var($newComment->getProperty('emailAddress'), FILTER_SANITIZE_STRIPPED));
6672

67-
$commentNode = $postNode->getNode('comments')->createNodeFromTemplate($newComment, uniqid('comment-'));
73+
$commentNode = $postNode->getNode('comments')->createNodeFromTemplate($newComment, uniqid('comment-', true));
6874
$commentNode->setProperty('spam', false);
6975
$commentNode->setProperty('datePublished', new \DateTime());
7076

@@ -73,7 +79,7 @@ public function createAction(NodeInterface $postNode, NodeTemplate $newComment)
7379
}
7480

7581
$this->emitCommentCreated($commentNode, $postNode);
76-
$this->response->setStatus(201);
82+
$this->response->setStatusCode(201);
7783

7884
return 'Thank you for your comment!';
7985
}
@@ -86,7 +92,7 @@ public function createAction(NodeInterface $postNode, NodeTemplate $newComment)
8692
* @return void
8793
* @Flow\Signal
8894
*/
89-
protected function emitCommentCreated(NodeInterface $commentNode, NodeInterface $postNode)
95+
protected function emitCommentCreated(NodeInterface $commentNode, NodeInterface $postNode): void
9096
{
9197
}
9298
}

Classes/Controller/PostController.php

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace RobertLemke\Plugin\Blog\Controller;
35

46
/*
@@ -11,16 +13,20 @@
1113
* source code.
1214
*/
1315

14-
use RobertLemke\Plugin\Blog\Service\ContentService;
15-
use RobertLemke\Rss\Channel;
16-
use RobertLemke\Rss\Feed;
17-
use RobertLemke\Rss\Item;
16+
use Neos\ContentRepository\Domain\Model\NodeInterface;
17+
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
18+
use Neos\ContentRepository\Exception\NodeException;
1819
use Neos\Flow\Annotations as Flow;
20+
use Neos\Flow\Http\Component\SetHeaderComponent;
21+
use Neos\Flow\Http\Helper\RequestInformationHelper;
1922
use Neos\Flow\I18n\Service;
2023
use Neos\Flow\Mvc\Controller\ActionController;
24+
use Neos\Flow\Mvc\Routing\Exception\MissingActionNameException;
2125
use Neos\Flow\Mvc\Routing\UriBuilder;
22-
use Neos\ContentRepository\Domain\Model\NodeInterface;
23-
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
26+
use RobertLemke\Plugin\Blog\Service\ContentService;
27+
use RobertLemke\Rss\Channel;
28+
use RobertLemke\Rss\Feed;
29+
use RobertLemke\Rss\Item;
2430

2531
/**
2632
* The posts controller for the Blog package
@@ -51,8 +57,10 @@ class PostController extends ActionController
5157
* Renders an RSS feed
5258
*
5359
* @return string
60+
* @throws NodeException
61+
* @throws MissingActionNameException
5462
*/
55-
public function rssAction()
63+
public function rssAction(): string
5664
{
5765
$rssDocumentNode = $this->request->getInternalArgument('__documentNode');
5866
if ($rssDocumentNode === null) {
@@ -65,6 +73,7 @@ public function rssAction()
6573
$uriBuilder = new UriBuilder();
6674
$uriBuilder->setRequest($this->request->getMainRequest());
6775
$uriBuilder->setCreateAbsoluteUri(true);
76+
$uriBuilder->setFormat('html');
6877

6978
$feedTitle = $this->request->getInternalArgument('__feedTitle');
7079
$feedDescription = $this->request->getInternalArgument('__feedDescription');
@@ -78,24 +87,22 @@ public function rssAction()
7887
}
7988

8089
$channel = new Channel();
81-
$channel->setTitle($feedTitle);
82-
$channel->setDescription($feedDescription);
83-
$channel->setFeedUri($feedUri);
84-
$channel->setWebsiteUri($this->request->getHttpRequest()->getBaseUri());
85-
$channel->setLanguage((string)$this->i18nService->getConfiguration()->getCurrentLocale());
90+
$channel->setTitle($feedTitle)
91+
->setDescription($feedDescription)
92+
->setFeedUri($feedUri)
93+
->setWebsiteUri((string)RequestInformationHelper::generateBaseUri($this->request->getHttpRequest()))
94+
->setLanguage((string)$this->i18nService->getConfiguration()->getCurrentLocale());
8695

8796
/* @var $postNode NodeInterface */
8897
foreach ($postsNode->getChildNodes('RobertLemke.Plugin.Blog:Post') as $postNode) {
89-
90-
$uriBuilder->setFormat('html');
9198
$postUri = $uriBuilder->uriFor('show', ['node' => $postNode], 'Frontend\Node', 'Neos.Neos');
9299

93100
$item = new Item();
94-
$item->setTitle($postNode->getProperty('title'));
95-
$item->setGuid($postNode->getIdentifier());
96-
$item->setPublicationDate($postNode->getProperty('datePublished'));
97-
$item->setItemLink((string)$postUri);
98-
$item->setCommentsLink((string)$postUri . '#comments');
101+
$item->setTitle($postNode->getProperty('title'))
102+
->setGuid($postNode->getIdentifier())
103+
->setPublicationDate($postNode->getProperty('datePublished'))
104+
->setItemLink((string)$postUri)
105+
->setCommentsLink((string)$postUri . '#comments');
99106

100107
$author = $postNode->getProperty('author');
101108
if ($author instanceof NodeInterface) {
@@ -125,9 +132,8 @@ public function rssAction()
125132
$channel->addItem($item);
126133
}
127134

128-
$headers = $this->response->getHeaders();
129-
$headers->setCacheControlDirective('s-max-age', 3600);
130-
$headers->set('Content-Type', 'application/rss+xml');
135+
$this->response->setComponentParameter(SetHeaderComponent::class, 'Cache-Control', ['s-max-age=3600']);
136+
$this->response->setContentType('application/rss+xml');
131137

132138
$feed = new Feed();
133139
$feed->addChannel($channel);

Classes/Eel/FilterByReferenceOperation.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
declare(strict_types=1);
43

54
namespace RobertLemke\Plugin\Blog\Eel;
@@ -12,8 +11,8 @@
1211
/**
1312
* FlowQuery operation to filter by properties of type reference or references
1413
*/
15-
class FilterByReferenceOperation extends AbstractOperation {
16-
14+
class FilterByReferenceOperation extends AbstractOperation
15+
{
1716
/**
1817
* {@inheritdoc}
1918
*/
@@ -30,7 +29,8 @@ class FilterByReferenceOperation extends AbstractOperation {
3029
* @param $context
3130
* @return bool
3231
*/
33-
public function canEvaluate($context) {
32+
public function canEvaluate($context)
33+
{
3434
return (!isset($context[0]) || ($context[0] instanceof NodeInterface));
3535
}
3636

@@ -44,7 +44,8 @@ public function canEvaluate($context) {
4444
* @throws FlowQueryException
4545
* @throws \Neos\ContentRepository\Exception\NodeException
4646
*/
47-
public function evaluate(FlowQuery $flowQuery, array $arguments) {
47+
public function evaluate(FlowQuery $flowQuery, array $arguments)
48+
{
4849
if (empty($arguments[0])) {
4950
throw new FlowQueryException('filterByReference() needs reference property name by which nodes should be filtered', 1545778273);
5051
}
@@ -53,13 +54,13 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) {
5354
}
5455

5556
/** @var NodeInterface $nodeReference */
56-
list($filterByPropertyPath, $nodeReference) = $arguments;
57+
[$filterByPropertyPath, $nodeReference] = $arguments;
5758

5859
$filteredNodes = [];
5960
foreach ($flowQuery->getContext() as $node) {
6061
/** @var NodeInterface $node */
6162
$propertyValue = $node->getProperty($filterByPropertyPath);
62-
if ($nodeReference === $propertyValue || (is_array($propertyValue) && in_array($nodeReference, $propertyValue, TRUE))) {
63+
if ($nodeReference === $propertyValue || (is_array($propertyValue) && in_array($nodeReference, $propertyValue, true))) {
6364
$filteredNodes[] = $node;
6465
}
6566
}

Classes/Package.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace RobertLemke\Plugin\Blog;
35

46
/*
@@ -13,6 +15,8 @@
1315

1416
use Neos\Flow\Core\Bootstrap;
1517
use Neos\Flow\Package\Package as BasePackage;
18+
use RobertLemke\Plugin\Blog\Controller\CommentController;
19+
use RobertLemke\Plugin\Blog\Service\NotificationService;
1620

1721
/**
1822
* The Blog Package
@@ -29,6 +33,6 @@ class Package extends BasePackage
2933
public function boot(Bootstrap $bootstrap)
3034
{
3135
$dispatcher = $bootstrap->getSignalSlotDispatcher();
32-
$dispatcher->connect('RobertLemke\Plugin\Blog\Controller\CommentController', 'commentCreated', 'RobertLemke\Plugin\Blog\Service\NotificationService', 'sendNewCommentNotification');
36+
$dispatcher->connect(CommentController::class, 'commentCreated', NotificationService::class, 'sendNewCommentNotification');
3337
}
3438
}

Classes/RenderingFixingAspect.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace RobertLemke\Plugin\Blog;
35

46
/*
@@ -29,10 +31,10 @@ class RenderingFixingAspect
2931
* @return string
3032
* @Flow\Around("method(Neos\Neos\Service\ContentElementWrappingService->wrapContentObject())")
3133
*/
32-
public function preventContentElementWraps(JoinPointInterface $joinPoint)
34+
public function preventContentElementWraps(JoinPointInterface $joinPoint): string
3335
{
3436
$content = $joinPoint->getMethodArgument('content');
35-
if (substr($content, 0, 5) === '<?xml') {
37+
if (strpos($content, '<?xml') === 0) {
3638
return $content;
3739
}
3840

0 commit comments

Comments
 (0)