for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Gendoria\CommandQueue\Serializer;
use Gendoria\CommandQueue\Command\CommandInterface;
use Gendoria\CommandQueue\Serializer\Exception\UnserializeErrorException;
use InvalidArgumentException;
/**
* This class creates command data with no serialization at all.
*
* @author Tomasz Struczyński <[email protected]>
*/
class NullSerializer implements SerializerInterface
{
* {@inheritdoc}
public function serialize(CommandInterface $command)
return new SerializedCommandData($command, get_class($command));
}
* @throws InvalidArgumentException Thrown, when "serialized" data is not an instance of correct command class.
public function unserialize(SerializedCommandData $serializedCommandData)
$commandClass = $serializedCommandData->getCommandClass();
if (!is_object($serializedCommandData->getSerializedCommand()) || !$serializedCommandData->getSerializedCommand() instanceof $commandClass) {
throw new UnserializeErrorException($serializedCommandData, "Null serializer accepts only commands as serialized command data.");
return $serializedCommandData->getSerializedCommand();