PluginProbe
Media Cloud Sync / 1.0.3
Media Cloud Sync v1.0.3
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / google / ramsey / uuid / src / Fields / SerializableFieldsTrait.php

SerializableFieldsTrait.php in Media Cloud Sync 1.0.3, at includes/sdk/google/ramsey/uuid/src/Fields/SerializableFieldsTrait.php

77 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the ramsey/uuid library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12 declare (strict_types=1);
13 namespace Dudlewebs\WPMCS\Ramsey\Uuid\Fields;
14
15 use ValueError;
16 use function base64_decode;
17 use function sprintf;
18 use function strlen;
19 /**
20 * Provides common serialization functionality to fields
21 *
22 * @psalm-immutable
23 */
24 trait SerializableFieldsTrait
25 {
26 /**
27 * @param string $bytes The bytes that comprise the fields
28 */
29 abstract public function __construct(string $bytes);
30 /**
31 * Returns the bytes that comprise the fields
32 */
33 abstract public function getBytes(): string;
34 /**
35 * Returns a string representation of object
36 */
37 public function serialize(): string
38 {
39 return $this->getBytes();
40 }
41 /**
42 * @return array{bytes: string}
43 */
44 public function __serialize(): array
45 {
46 return ['bytes' => $this->getBytes()];
47 }
48 /**
49 * Constructs the object from a serialized string representation
50 *
51 * @param string $serialized The serialized string representation of the object
52 *
53 * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
54 * @psalm-suppress UnusedMethodCall
55 */
56 public function unserialize($serialized): void
57 {
58 if (strlen($serialized) === 16) {
59 $this->__construct($serialized);
60 } else {
61 $this->__construct(base64_decode($serialized));
62 }
63 }
64 /**
65 * @param array{bytes: string} $data
66 */
67 public function __unserialize(array $data): void
68 {
69 // @codeCoverageIgnoreStart
70 if (!isset($data['bytes'])) {
71 throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
72 }
73 // @codeCoverageIgnoreEnd
74 $this->unserialize($data['bytes']);
75 }
76 }
77