Skip to content

Commit

Permalink
Merge pull request #27 from superbrave/exporter-format
Browse files Browse the repository at this point in the history
Moved format argument in Exporter class
  • Loading branch information
Jelle van Oosterbosch authored Sep 18, 2018
2 parents 9378473 + 2c4b0ca commit d208554
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
18 changes: 6 additions & 12 deletions Export/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Superbrave\GdprBundle\Export;

use InvalidArgumentException;
use ReflectionException;
use ReflectionClass;
use Symfony\Component\Serializer\SerializerInterface;

Expand All @@ -30,36 +31,29 @@ 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;
}

/**
* Returns a serialized/exported version of the specified object.
*
* @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(
Expand All @@ -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);
}
}
1 change: 0 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
class: Superbrave\GdprBundle\Export\Exporter
arguments:
- "@superbrave_gdpr.exporter.serializer"
- "xml"
public: true

superbrave_gdpr.anonymizer:
Expand Down
3 changes: 1 addition & 2 deletions Tests/Export/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -61,7 +61,6 @@ public function setUp()
public function testConstruct()
{
$this->assertAttributeSame($this->serializerMock, 'serializer', $this->exporter);
$this->assertAttributeSame('xml', 'format', $this->exporter);
}

/**
Expand Down

0 comments on commit d208554

Please sign in to comment.