| Server IP : 85.158.181.41 / Your IP : 216.73.217.12 Web Server : Apache System : Linux cloud9-vm129 6.1.178+1-ph #ph SMP PREEMPT_DYNAMIC Wed Jul 29 09:00:54 UTC 2026 x86_64 User : moncbefd ( 1024) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/moncbefd/www.moneta.at/vendor/gambio-hub/hubpublic/src/Serializers/ |
Upload File : |
<?php
namespace HubPublic\Serializers;
use HubPublic\Exceptions\BadSerializerValueException;
/**
* Class AbstractSerializer
*
* Serializers should extend from this.
*
* @package HubPublic\Serializers
*/
abstract class AbstractSerializer
{
/**
* Verifies the integrity of the given associative array.
*
* @param array $decodedJson Associative array which was converted from JSON.
*
* @throws \HubPublic\Exceptions\BadSerializerValueException If the array is malformed or does not contain
* valid data.
*/
protected function verifyArray(array $decodedJson)
{
if (empty($decodedJson)) {
throw new BadSerializerValueException('Given object is empty.');
}
}
/**
* Verifies that a set of keys is found in the given array.
*
* @param array $decodedJson The decoded JSON array that is to be verified.
* @param array $expectedKeys Array of keys that are expected to be found in the array.
*
* @throws BadSerializerValueException if the array does not contain expected data.
*/
protected function verifyArrayKeys(array $decodedJson, array $expectedKeys)
{
foreach ($expectedKeys as $key) {
if (!array_key_exists($key, $decodedJson)) {
throw new BadSerializerValueException('Key ' . $key . ' not found in given array.');
}
}
}
/**
* Deserializes an associative array.
*
* @param array $decodedJson Associative array that contains the data.
*/
public abstract function deserialize(array $decodedJson);
/**
* Serializes an object to a JSON string or array.
*
* @param \HubPublic\ValueObjects\CartContent $cartContent Content to be serialized.
* @param bool $encode Serialize to string?
*
* @return array|string Serialized JSON string or array of given content.
*/
public abstract function serialize($cartContent, $encode = true);
}