Skip to content

Commit

Permalink
Visitor interfaces in handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
derzkiy committed Sep 30, 2019
1 parent 4c1e429 commit bd81634
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
11 changes: 5 additions & 6 deletions src/Handler/ConstraintViolationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
namespace JMS\Serializer\Handler;

use JMS\Serializer\GraphNavigatorInterface;
use JMS\Serializer\JsonSerializationVisitor;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\XmlSerializationVisitor;
use JMS\Serializer\Visitor\SerializationVisitorInterface;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;

Expand Down Expand Up @@ -36,7 +35,7 @@ public static function getSubscribingMethods()
return $methods;
}

public function serializeListToXml(XmlSerializationVisitor $visitor, ConstraintViolationList $list, array $type): void
public function serializeListToXml(SerializationVisitorInterface $visitor, ConstraintViolationList $list, array $type): void
{
$currentNode = $visitor->getCurrentNode();
if (!$currentNode) {
Expand All @@ -51,12 +50,12 @@ public function serializeListToXml(XmlSerializationVisitor $visitor, ConstraintV
/**
* @return array|\ArrayObject
*/
public function serializeListToJson(JsonSerializationVisitor $visitor, ConstraintViolationList $list, array $type, SerializationContext $context)
public function serializeListToJson(SerializationVisitorInterface $visitor, ConstraintViolationList $list, array $type, SerializationContext $context)
{
return $visitor->visitArray(iterator_to_array($list), $type);
}

public function serializeViolationToXml(XmlSerializationVisitor $visitor, ConstraintViolation $violation, ?array $type = null): void
public function serializeViolationToXml(SerializationVisitorInterface $visitor, ConstraintViolation $violation, ?array $type = null): void
{
$violationNode = $visitor->getDocument()->createElement('violation');

Expand All @@ -73,7 +72,7 @@ public function serializeViolationToXml(XmlSerializationVisitor $visitor, Constr
$messageNode->appendChild($visitor->getDocument()->createCDATASection($violation->getMessage()));
}

public function serializeViolationToJson(JsonSerializationVisitor $visitor, ConstraintViolation $violation, ?array $type = null): array
public function serializeViolationToJson(SerializationVisitorInterface $visitor, ConstraintViolation $violation, ?array $type = null): array
{
return [
'property_path' => $violation->getPropertyPath(),
Expand Down
15 changes: 7 additions & 8 deletions src/Handler/DateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

use JMS\Serializer\Exception\RuntimeException;
use JMS\Serializer\GraphNavigatorInterface;
use JMS\Serializer\JsonDeserializationVisitor;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\Visitor\DeserializationVisitorInterface;
use JMS\Serializer\Visitor\SerializationVisitorInterface;
use JMS\Serializer\XmlDeserializationVisitor;
use JMS\Serializer\XmlSerializationVisitor;

final class DateHandler implements SubscribingHandlerInterface
Expand Down Expand Up @@ -141,7 +140,7 @@ private function isDataXmlNull($data): bool
* @param mixed $data
* @param array $type
*/
public function deserializeDateTimeFromXml(XmlDeserializationVisitor $visitor, $data, array $type): ?\DateTimeInterface
public function deserializeDateTimeFromXml(DeserializationVisitorInterface $visitor, $data, array $type): ?\DateTimeInterface
{
if ($this->isDataXmlNull($data)) {
return null;
Expand All @@ -154,7 +153,7 @@ public function deserializeDateTimeFromXml(XmlDeserializationVisitor $visitor, $
* @param mixed $data
* @param array $type
*/
public function deserializeDateTimeImmutableFromXml(XmlDeserializationVisitor $visitor, $data, array $type): ?\DateTimeInterface
public function deserializeDateTimeImmutableFromXml(DeserializationVisitorInterface $visitor, $data, array $type): ?\DateTimeInterface
{
if ($this->isDataXmlNull($data)) {
return null;
Expand All @@ -167,7 +166,7 @@ public function deserializeDateTimeImmutableFromXml(XmlDeserializationVisitor $v
* @param mixed $data
* @param array $type
*/
public function deserializeDateIntervalFromXml(XmlDeserializationVisitor $visitor, $data, array $type): ?\DateInterval
public function deserializeDateIntervalFromXml(DeserializationVisitorInterface $visitor, $data, array $type): ?\DateInterval
{
if ($this->isDataXmlNull($data)) {
return null;
Expand All @@ -180,7 +179,7 @@ public function deserializeDateIntervalFromXml(XmlDeserializationVisitor $visito
* @param mixed $data
* @param array $type
*/
public function deserializeDateTimeFromJson(JsonDeserializationVisitor $visitor, $data, array $type): ?\DateTimeInterface
public function deserializeDateTimeFromJson(DeserializationVisitorInterface $visitor, $data, array $type): ?\DateTimeInterface
{
if (null === $data) {
return null;
Expand All @@ -193,7 +192,7 @@ public function deserializeDateTimeFromJson(JsonDeserializationVisitor $visitor,
* @param mixed $data
* @param array $type
*/
public function deserializeDateTimeImmutableFromJson(JsonDeserializationVisitor $visitor, $data, array $type): ?\DateTimeInterface
public function deserializeDateTimeImmutableFromJson(DeserializationVisitorInterface $visitor, $data, array $type): ?\DateTimeInterface
{
if (null === $data) {
return null;
Expand All @@ -206,7 +205,7 @@ public function deserializeDateTimeImmutableFromJson(JsonDeserializationVisitor
* @param mixed $data
* @param array $type
*/
public function deserializeDateIntervalFromJson(JsonDeserializationVisitor $visitor, $data, array $type): ?\DateInterval
public function deserializeDateIntervalFromJson(DeserializationVisitorInterface $visitor, $data, array $type): ?\DateInterval
{
if (null === $data) {
return null;
Expand Down
10 changes: 4 additions & 6 deletions src/Handler/FormErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
namespace JMS\Serializer\Handler;

use JMS\Serializer\GraphNavigatorInterface;
use JMS\Serializer\JsonSerializationVisitor;
use JMS\Serializer\Visitor\SerializationVisitorInterface;
use JMS\Serializer\XmlSerializationVisitor;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormError;
use Symfony\Component\Translation\TranslatorInterface;
Expand Down Expand Up @@ -56,7 +54,7 @@ public function __construct(?TranslatorInterface $translator = null, string $tra
/**
* @param array $type
*/
public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form, array $type): \DOMElement
public function serializeFormToXml(SerializationVisitorInterface $visitor, Form $form, array $type): \DOMElement
{
$formNode = $visitor->getDocument()->createElement('form');

Expand All @@ -83,23 +81,23 @@ public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form,
/**
* @param array $type
*/
public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $form, array $type): \ArrayObject
public function serializeFormToJson(SerializationVisitorInterface $visitor, Form $form, array $type): \ArrayObject
{
return $this->convertFormToArray($visitor, $form);
}

/**
* @param array $type
*/
public function serializeFormErrorToXml(XmlSerializationVisitor $visitor, FormError $formError, array $type): \DOMCdataSection
public function serializeFormErrorToXml(SerializationVisitorInterface $visitor, FormError $formError, array $type): \DOMCdataSection
{
return $visitor->getDocument()->createCDATASection($this->getErrorMessage($formError));
}

/**
* @param array $type
*/
public function serializeFormErrorToJson(JsonSerializationVisitor $visitor, FormError $formError, array $type): string
public function serializeFormErrorToJson(SerializationVisitorInterface $visitor, FormError $formError, array $type): string
{
return $this->getErrorMessage($formError);
}
Expand Down

0 comments on commit bd81634

Please sign in to comment.