diff --git a/Export/Exporter.php b/Export/Exporter.php index ec38026..c13f2e6 100644 --- a/Export/Exporter.php +++ b/Export/Exporter.php @@ -13,6 +13,7 @@ namespace Superbrave\GdprBundle\Export; use InvalidArgumentException; +use ReflectionException; use ReflectionClass; use Symfony\Component\Serializer\SerializerInterface; @@ -30,23 +31,14 @@ class Exporter */ private $serializer; - /** - * The format an object is serialized to. - * - * @var string - */ - private $format; - /** * Constructs a new Export instance. * * @param SerializerInterface $serializer The Serializer instance - * @param string $format The format an object is serialized to */ - public function __construct(SerializerInterface $serializer, $format = 'xml') + public function __construct(SerializerInterface $serializer) { $this->serializer = $serializer; - $this->format = $format; } /** @@ -54,12 +46,14 @@ public function __construct(SerializerInterface $serializer, $format = 'xml') * * @param object $object The object to be exported * @param string|null $objectName The name of the object used in the export (eg. the root node in XML) + * @param string $format The format an object is serialized to * * @return string * * @throws InvalidArgumentException + * @throws ReflectionException */ - public function exportObject(/*object */$object, $objectName = null) + public function exportObject(/*object */$object, $objectName = null, $format = 'xml') { if (is_object($object) === false) { throw new InvalidArgumentException( @@ -75,6 +69,6 @@ public function exportObject(/*object */$object, $objectName = null) $context['xml_root_node_name'] = (new ReflectionClass($object))->getShortName(); } - return $this->serializer->serialize($object, $this->format, $context); + return $this->serializer->serialize($object, $format, $context); } } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index b2742ed..29e64eb 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -9,7 +9,6 @@ services: class: Superbrave\GdprBundle\Export\Exporter arguments: - "@superbrave_gdpr.exporter.serializer" - - "xml" public: true superbrave_gdpr.anonymizer: diff --git a/Tests/Export/ExporterTest.php b/Tests/Export/ExporterTest.php index 3d79a73..ccf22d9 100644 --- a/Tests/Export/ExporterTest.php +++ b/Tests/Export/ExporterTest.php @@ -50,7 +50,7 @@ public function setUp() $this->serializerMock = $this->getMockBuilder(SerializerInterface::class) ->getMock(); - $this->exporter = new Exporter($this->serializerMock, 'xml'); + $this->exporter = new Exporter($this->serializerMock); } /** @@ -61,7 +61,6 @@ public function setUp() public function testConstruct() { $this->assertAttributeSame($this->serializerMock, 'serializer', $this->exporter); - $this->assertAttributeSame('xml', 'format', $this->exporter); } /**