Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injected RichText Validator from DIC into RichText Converter #91

Merged
merged 8 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ services:
ezxmltext.richtext_converter:
class: eZ\Publish\Core\FieldType\XmlText\Converter\RichText
arguments:
- "@ezrichtext.validator.docbook"
- "@ezpublish.api.repository"
- "@?logger"
35 changes: 10 additions & 25 deletions lib/FieldType/XmlText/Converter/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Psr\Log\LoggerInterface;
use eZ\Publish\Core\FieldType\RichText\Converter\Aggregate;
use eZ\Publish\Core\FieldType\RichText\Converter\Xslt;
use eZ\Publish\Core\FieldType\RichText\Validator;
use EzSystems\EzPlatformRichText\eZ\RichText\ValidatorInterface;
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
use Psr\Log\NullLogger;
use Psr\Log\LogLevel;
Expand All @@ -36,7 +36,7 @@ class RichText implements Converter
*/
private $imageContentTypes;
/**
* @var \eZ\Publish\Core\FieldType\RichText\Validator
* @var ValidatorInterface
*/
private $validator;

Expand Down Expand Up @@ -64,17 +64,22 @@ class RichText implements Converter

/**
* RichText constructor.
* @param null $validator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I see we omitted type-hinting, it should be rather null|<FQCN of an actual class>
The same goes for Repository, but this is our mistake 😅

* @param null $apiRepository
* @param LoggerInterface|null $logger
*/
public function __construct($apiRepository = null, LoggerInterface $logger = null)
{
public function __construct(
ValidatorInterface $validator = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safer to place new argument as a last one

$apiRepository = null,
LoggerInterface $logger = null
) {
$this->validator = $validator;

$this->logger = $logger instanceof LoggerInterface ? $logger : new NullLogger();
$this->imageContentTypes = [];
$this->apiRepository = $apiRepository;

$this->styleSheets = null;
$this->validator = null;
$this->converter = null;
$this->customTagsLog = [self::INLINE_CUSTOM_TAG => [], self::BLOCK_CUSTOM_TAG => []];
}
Expand Down Expand Up @@ -116,31 +121,11 @@ public function setCustomStylesheets(array $customStylesheets = [])
$this->converter = null;
}

/**
* @param array $customValidators
*/
public function setCustomValidators(array $customValidators = [])
{
$validators = array_merge(
[
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng',
],
$customValidators,
[
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/docbook.iso.sch.xsl',
]
);
$this->validator = new Validator($validators);
}

protected function getConverter()
{
if ($this->styleSheets === null) {
$this->setCustomStylesheets([]);
}
if ($this->validator === null) {
$this->setCustomValidators([]);
}
if ($this->converter === null) {
$this->converter = new Aggregate(
[
Expand Down