MAKS\AmqpAgent\Helper\Serializer
A flexible serializer to be used in conjunction with the workers.
Synopsis
- // constants
- const TYPE_JSON = 'JSON';
- const TYPE_PHP = 'PHP';
- const DEFAULT_DATA = NULL;
- const DEFAULT_TYPE = self::TYPE_JSON;
- const DEFAULT_STRICT = true;
- const SUPPORTED_TYPES = ;
- // methods
- public void __construct()
- public mixed __invoke()
- public string serialize()
- public mixed unserialize()
- public mixed deserialize()
- public Serializer setData()
- public mixed getData()
- public Serializer setType()
- public string getType()
- public Serializer setStrict()
- public bool isStrict()
- public string getSerialized()
- public mixed getUnserialized()
- protected void assertNoPhpSerializationError()
- protected void assertNoJsonSerializationError()
Coverage
| Methods | 93.33% | 14 / 15 | 
| Lines | 98.75% | 79 / 80 | 
Constants
| Name | Value | 
|---|---|
| TYPE_JSON | 'JSON' | 
| TYPE_PHP | 'PHP' | 
| DEFAULT_DATA | NULL | 
| DEFAULT_TYPE | self::TYPE_JSON | 
| DEFAULT_STRICT | true | 
| SUPPORTED_TYPES | 
Members
protected
- $data
                —
                mixed
 The current data the serializer has.
- $result
                —
                mixed
 The result of the last (un)serialization operation.
- $strict
                —
                MAKS\AmqpAgent\Helper\bool
 The current strict value the serializer works with.
- $type
                —
                string
 The current type the serializer uses.
Methods
protected
- assertNoJsonSerializationError() — Asserts that `json_encode()` and/or `json_decode()` was executed successfully depending on strictness of the Serializer.
- assertNoPhpSerializationError() — Asserts that `serialize()` and/or `unserialize()` was executed successfully depending on strictness of the Serializer.
public
- __construct() — Serializer object constructor.
- __invoke() — Executes when calling the class like a function.
- deserialize() — Deserializes the passed or registered data. When no parameters are passed, it uses the registered ones.
- getData() — Returns the currently registered data.
- getSerialized() — Alias for `self::serialize()` that does not accept any parameters (works with currently registered parameters).
- getType() — Returns the currently registered type.
- getUnserialized() — Alias for `self::unserialize()` that does not accept any parameters (works with currently registered parameters).
- isStrict() — Returns the currently registered strict value.
- serialize() — Serializes the passed or registered data. When no parameters are passed, it uses the registered ones.
- setData() — Registers the passed data in the object.
- setStrict() — Registers the passed strict value in the object.
- setType() — Registers the passed type in the object.
- unserialize() — Unserializes the passed or registered data. When no parameters are passed, it uses the registered ones.
History
- 
            2021-01-12T21:10:22+00:00 (commit #80561d6)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Update serilaizer class * Remove return value type hint "self" from methods signature due to unexpected behavior with different PHP versions 
- 
            2021-01-12T21:10:22+00:00 (commit #0eb997a)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Update serializer class * Fix typos * Update DocBlocks 
- 
            2021-01-12T21:10:21+00:00 (commit #d09424b)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Add strict types declaration * Add declare(strict_types=1) to all files * Fix file header DocBlock spacing of all files 
- 
            2020-11-29T12:23:23+00:00 (commit #d0f45ac)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Update serializer class * Remove the check for PHP version in assertNoJsonSerializationError() method * Remove catch block contents in assertNoJsonSerializationError() method * Fix some typos in DocBlocks 
- 
            2020-11-29T10:36:58+00:00 (commit #dca6593)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Update serializer class * TLDR: almost a complete rewrite * Add serializations types as class constants * Add methods to assert for PHP und JSON (un)serializations errors * Add a new $strict property to determine serialization strictness * Add a isStrict() and setStrict() methods * Add $strict parameter to serialize() and unserialize() methods 
- 
            2020-09-30T14:28:06+00:00 (commit #1986938)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Update serializer class * Fix mistake of writing [optional] before variable name in DocBlocks 
- 
            2020-09-23T18:47:06+00:00 (commit #1a3f203)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Fix typos and update DocBlocks * Fix some typos in DockBlocks and other parts of the codebase * Add examples to classes DocBlocks 
- 
            2020-06-15T00:00:38+00:00 (commit #c153401)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Fix typos in docblocks * Fix typo in Example class * Fix typos in Serializer class 
- 
            2020-06-13T05:55:10+00:00 (commit #2dd737e)Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) Add serializer class * Add Serilaizer.php * Add SerializerViolationException.php