EmailJsonSerializer
extends AbstractJsonSerializer
in package
Class EmailsJsonSerializer
This class will serialize and deserialize an email entity. It can be used into many places where PHP interacts with external requests such as AJAX or API communication.
Tags
Table of Contents
- $languageProvider : LanguageProviderInterface
- Used for the resources that require multiple languages.
- __construct() : mixed
- AbstractJsonSerializer Constructor
- deserialize() : EmailInterface
- Deserialize email JSON string.
- jsonEncode() : string
- JSON Encode Wrapper
- serialize() : string|array<string|int, mixed>
- Serialize email object (from Email instance to json string)
- _deserializeAddonValues() : array<string|int, mixed>
- Deserialize Addon Values
- _deserializeAttachment() : EmailAttachment
- Deserialize EmailAttachment
- _deserializeContact() : EmailContact
- Deserialize EmailContact
- _deserializeLanguageSpecificProperty() : mixed
- Deserialize Language Specific Property
- _serializeAddonValues() : array<string|int, mixed>
- Serialize Addon Values
- _serializeAttachment() : array<string|int, mixed>
- Serialize EmailAttachment
- _serializeContact() : array<string|int, mixed>
- Serialize EmailContact
- _serializeLanguageSpecificProperty() : array<string|int, mixed>
- Serialize Language Specific Property
Properties
$languageProvider
Used for the resources that require multiple languages.
protected
LanguageProviderInterface
$languageProvider
Methods
__construct()
AbstractJsonSerializer Constructor
public
__construct() : mixed
If you override this constructor do not forget to call it from the child class.
Return values
mixed —deserialize()
Deserialize email JSON string.
public
deserialize(string $string[, object $baseObject = null ]) : EmailInterface
Parameters
- $string : string
-
JSON string that contains the data of the email.
- $baseObject : object = null
-
(optional) If provided, this will be the base object to be updated and no new instance will be created.
Tags
Return values
EmailInterface —Returns the deserialized Email object.
jsonEncode()
JSON Encode Wrapper
public
jsonEncode(array<string|int, mixed> $data) : string
This function provides PHP v5.3 compatibility and it should be used when serialized objects need to be encoded directly from the serializer instance.
Parameters
- $data : array<string|int, mixed>
-
Contains the data to be JSON encoded.
Return values
string —Returns the encoded JSON string that represents the data.
serialize()
Serialize email object (from Email instance to json string)
public
serialize(EmailInterface $object[, bool $encode = true ]) : string|array<string|int, mixed>
Parameters
- $object : EmailInterface
-
Contains the email data.
- $encode : bool = true
-
(optional) Whether to json_encode the result of the method (default true). Sometimes it might be required to encode an array of multiple email records together and not one by one.
Return values
string|array<string|int, mixed> —_deserializeAddonValues()
Deserialize Addon Values
protected
_deserializeAddonValues( $json) : array<string|int, mixed>
Common method for deserializing addon values in various resource serializer classes.
Parameters
Return values
array<string|int, mixed> —_deserializeAttachment()
Deserialize EmailAttachment
protected
_deserializeAttachment(stdClass $attachment) : EmailAttachment
Parameters
- $attachment : stdClass
Return values
EmailAttachment —_deserializeContact()
Deserialize EmailContact
protected
_deserializeContact(stdClass $contact, $type) : EmailContact
Parameters
Return values
EmailContact —_deserializeLanguageSpecificProperty()
Deserialize Language Specific Property
protected
_deserializeLanguageSpecificProperty(mixed $object, stdobject $json, string $property[, mixed $type = 'StringType' ]) : mixed
This method will deserialize the value of a JSON property and set the value to the object by using the corresponding setter method.
Parameters
- $object : mixed
-
The object being deserialized.
- $json : stdobject
-
The JSON object containing the property value.
- $property : string
-
The property name to be deserialized.
- $type : mixed = 'StringType'
Tags
Return values
mixed —_serializeAddonValues()
Serialize Addon Values
protected
_serializeAddonValues(KeyValueCollection $addonValues) : array<string|int, mixed>
Common method for serializing addon values in various resource serializer classes.
Parameters
- $addonValues : KeyValueCollection
Return values
array<string|int, mixed> —_serializeAttachment()
Serialize EmailAttachment
protected
_serializeAttachment(EmailAttachmentInterface $attachment) : array<string|int, mixed>
Parameters
- $attachment : EmailAttachmentInterface
Return values
array<string|int, mixed> —_serializeContact()
Serialize EmailContact
protected
_serializeContact(EmailContactInterface $contact) : array<string|int, mixed>
Parameters
- $contact : EmailContactInterface
Return values
array<string|int, mixed> —_serializeLanguageSpecificProperty()
Serialize Language Specific Property
protected
_serializeLanguageSpecificProperty(mixed $object, string $property) : array<string|int, mixed>
In order for this method to work there has to be a proper getter method in the object instance. Otherwise a RuntimeException will be thrown.
Parameters
- $object : mixed
-
The object instance containing the property.
- $property : string
-
The property name to be serialized.