Skip to content

Commit 50ceb94

Browse files
author
Marvin Kuhn
committed
new: comment dto object now inherits from interface for extensibility
1 parent d98f24b commit 50ceb94

File tree

5 files changed

+75
-12
lines changed

5 files changed

+75
-12
lines changed

Classes/Dto/CommentDto.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace Breadlesscode\Commentable\Dto;
33

4-
class CommentDto
4+
class CommentDto implements CommentDtoInterface
55
{
66
/**
77
* @var string
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
namespace Breadlesscode\Commentable\Dto;
3+
4+
interface CommentDtoInterface
5+
{
6+
/**
7+
* @return string
8+
*/
9+
public function getEmail(): string;
10+
11+
/**
12+
* @param string $email
13+
*/
14+
public function setEmail(string $email): void;
15+
16+
/**
17+
* @return string
18+
*/
19+
public function getName(): string;
20+
21+
/**
22+
* @param string $name
23+
*/
24+
public function setName(string $name): void;
25+
26+
/**
27+
* @return string
28+
*/
29+
public function getContent(): string;
30+
31+
/**
32+
* @param string $content
33+
*/
34+
public function setContent(string $content): void;
35+
36+
/**
37+
* @return \DateTime
38+
*/
39+
public function getCreatedAt(): \DateTime;
40+
41+
/**
42+
* @param \DateTime $createdAt
43+
*/
44+
public function setCreatedAt(\DateTime $createdAt): void;
45+
46+
/**
47+
* @return bool
48+
*/
49+
public function isHidden(): bool;
50+
51+
/**
52+
* @param bool $isHidden
53+
*/
54+
public function setIsHidden(bool $isHidden): void;
55+
}

Classes/Form/Finisher/AddCommentFormFinisher.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<?php
22
namespace Breadlesscode\Commentable\Form\Finisher;
33

4-
use Breadlesscode\Commentable\Dto\CommentDto;
4+
use Breadlesscode\Commentable\Dto\CommentDtoInterface;
55
use Breadlesscode\Commentable\Exception\InvalidNodeTypeException;
66
use Breadlesscode\Commentable\Service\CommentService;
77
use Neos\Form\Core\Model\AbstractFinisher;
88
use Neos\Flow\Annotations as Flow;
99

1010
class AddCommentFormFinisher extends AbstractFinisher
1111
{
12+
/**
13+
* @var \Neos\Flow\ObjectManagement\ObjectManagerInterface
14+
* @Flow\Inject()
15+
*/
16+
protected $objectManager;
17+
1218
/**
1319
* @var CommentService
1420
* @Flow\Inject()
@@ -40,24 +46,24 @@ protected function executeInternal()
4046
}
4147

4248
/**
43-
* @return CommentDto
49+
* @return CommentDtoInterface
4450
*/
45-
protected function getCommentDto(): CommentDto
51+
protected function getCommentDto(): CommentDtoInterface
4652
{
47-
$comment = new CommentDto();
53+
$comment = $this->objectManager->get(CommentDtoInterface::class);
4854
$comment->setName($this->parseOption('name'));
4955
$comment->setEmail($this->parseOption('email'));
5056
$comment->setContent($this->parseOption('content'));
5157
$comment->setIsHidden($this->defaultHidden);
5258

5359
return $comment;
5460
}
55-
61+
5662
/**
5763
* @return mixed
5864
*/
5965
public function getOption($optionName)
6066
{
61-
return $this->parseOption($optionName);
67+
return $this->parseOption($optionName);
6268
}
6369
}

Classes/Service/CommentService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace Breadlesscode\Commentable\Service;
33

4-
use Breadlesscode\Commentable\Dto\CommentDto;
4+
use Breadlesscode\Commentable\Dto\CommentDtoInterface;
55
use Breadlesscode\Commentable\Exception\InvalidNodeTypeException;
66
use Neos\ContentRepository\Domain\Model\NodeInterface;
77
use Neos\ContentRepository\Domain\Model\NodeTemplate;
@@ -43,11 +43,11 @@ class CommentService
4343
* creates a comment node from the CommentDto
4444
*
4545
* @param NodeInterface $commentCollection
46-
* @param CommentDto $comment
46+
* @param CommentDtoInterface $comment
4747
* @return NodeInterface
4848
* @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException
4949
*/
50-
protected function createNode(NodeInterface $commentCollection, CommentDto $comment): NodeInterface
50+
protected function createNode(NodeInterface $commentCollection, CommentDtoInterface $comment): NodeInterface
5151
{
5252
$commentNodeType = $this->nodeTypeManager->getNodeType(self::COMMENT_NODE_TYPE);
5353
$commentNodeTemplate = new NodeTemplate();
@@ -72,11 +72,11 @@ protected function createNode(NodeInterface $commentCollection, CommentDto $comm
7272
* adds a comment node to a blog post node
7373
*
7474
* @param NodeInterface $commentableNode
75-
* @param CommentDto $comment
75+
* @param CommentDtoInterface $comment
7676
* @throws InvalidNodeTypeException
7777
* @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException
7878
*/
79-
public function addComment(NodeInterface $commentableNode, CommentDto $comment)
79+
public function addComment(NodeInterface $commentableNode, CommentDtoInterface $comment)
8080
{
8181
if (!$this->isCommentableNode($commentableNode)) {
8282
throw new InvalidNodeTypeException('The commentable node type should implement the mixin '.self::COMMENTABLE_NODE_TYPE, 1536244558);

Configuration/Objects.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Breadlesscode\Commentable\Dto\CommentDtoInterface:
2+
className: 'Breadlesscode\Commentable\Dto\CommentDto'

0 commit comments

Comments
 (0)