From 0318372641ce791fab7c4942d17d0f027bdb554c Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 14 Feb 2022 13:26:11 +1300 Subject: [PATCH] API Implement updated Serializable API --- .travis.yml | 16 +++++----- composer.json | 3 +- src/Core/Manifest/Module.php | 31 +++++++++++++++++++ src/ORM/ValidationResult.php | 24 ++++++++++++-- .../Symfony/FlushInvalidatedResource.php | 24 ++++++++++++++ 5 files changed, 87 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index a45cf8011..5b46a2a76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ import: jobs: fast_finish: true include: - - php: 7.3 + - php: 7.4 env: - DB=MYSQL - REQUIRE_INSTALLER="$REQUIRE_RECIPE" @@ -28,15 +28,17 @@ jobs: - REQUIRE_INSTALLER="$REQUIRE_RECIPE" - PHPUNIT_TEST=1 - PHPUNIT_SUITE="cms" - - php: 7.4 - env: - - DB=MYSQL - - REQUIRE_INSTALLER="$REQUIRE_RECIPE" - - PHPUNIT_TEST=1 - - PHPUNIT_SUITE="framework" - php: 8.0 env: - DB=MYSQL - REQUIRE_INSTALLER="$REQUIRE_RECIPE" - PHPUNIT_TEST=1 - PHPUNIT_SUITE="framework" + - php: 8.1.0 + env: + - DB=MYSQL + - REQUIRE_INSTALLER="$REQUIRE_RECIPE" + - PHPUNIT_TEST=1 + - PHPUNIT_SUITE="framework" + allow_failures: + - php: 8.1.0 diff --git a/composer.json b/composer.json index 465c5b6e8..573b7bcb8 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "symfony/config": "^3.4 || ^4.0", "symfony/translation": "^3.4 || ^4.0", "symfony/yaml": "^3.4 || ^4.0", - "php": "^7.3 || ^8.0", + "php": "^7.4 || ^8.0", "ext-ctype": "*", "ext-dom": "*", "ext-hash": "*", @@ -58,6 +58,7 @@ "squizlabs/php_codesniffer": "^3.5" }, "conflict": { + "egulias/email-validator": "^2", "phpunit/phpunit": "^6 || ^7 || ^8" }, "provide": { diff --git a/src/Core/Manifest/Module.php b/src/Core/Manifest/Module.php index 23a974fb3..8a408fa13 100644 --- a/src/Core/Manifest/Module.php +++ b/src/Core/Manifest/Module.php @@ -185,11 +185,42 @@ class Module implements Serializable return substr($this->path, strlen($this->basePath) + 1); } + public function __serialize(): array + { + return [ + 'path' => $this->path, + 'basePath' => $this->basePath, + 'composerData' => $this->composerData + ]; + } + + public function __unserialize(array $data): void + { + $this->path = $data['path']; + $this->basePath = $data['basePath']; + $this->composerData = $data['composerData']; + $this->resources = []; + } + + /** + * The __serialize() magic method will be automatically used instead of this + * + * @return string + * @deprecated will be removed in 5.0 + */ public function serialize() { return json_encode([$this->path, $this->basePath, $this->composerData]); } + /** + * The __unserialize() magic method will be automatically used instead of this almost all the time + * This method will be automatically used if existing serialized data was not saved as an associative array + * and the PHP version used in less than PHP 9.0 + * + * @param string $serialized + * @deprecated will be removed in 5.0 + */ public function unserialize($serialized) { list($this->path, $this->basePath, $this->composerData) = json_decode($serialized, true); diff --git a/src/ORM/ValidationResult.php b/src/ORM/ValidationResult.php index e839387d1..5f852131d 100644 --- a/src/ORM/ValidationResult.php +++ b/src/ORM/ValidationResult.php @@ -214,10 +214,25 @@ class ValidationResult implements Serializable return $this; } + public function __serialize(): array + { + return [ + 'messages' => $this->messages, + 'isValid' => $this->isValid() + ]; + } + + public function __unserialize(array $data): void + { + $this->messages = $data['messages']; + $this->isValid = $data['isValid']; + } + /** - * String representation of object + * The __serialize() magic method will be automatically used instead of this * - * @return string the string representation of the object or null + * @return string + * @deprecated will be removed in 5.0 */ public function serialize() { @@ -225,9 +240,12 @@ class ValidationResult implements Serializable } /** - * Constructs the object + * The __unserialize() magic method will be automatically used instead of this almost all the time + * This method will be automatically used if existing serialized data was not saved as an associative array + * and the PHP version used in less than PHP 9.0 * * @param string $serialized + * @deprecated will be removed in 5.0 */ public function unserialize($serialized) { diff --git a/src/i18n/Messages/Symfony/FlushInvalidatedResource.php b/src/i18n/Messages/Symfony/FlushInvalidatedResource.php index 0e01f45f1..72b4487a1 100644 --- a/src/i18n/Messages/Symfony/FlushInvalidatedResource.php +++ b/src/i18n/Messages/Symfony/FlushInvalidatedResource.php @@ -40,11 +40,35 @@ class FlushInvalidatedResource implements SelfCheckingResourceInterface, \Serial return false; } + public function __serialize(): array + { + return []; + } + + public function __unserialize(array $data): void + { + // no-op + } + + /** + * The __serialize() magic method will be automatically used instead of this + * + * @return string + * @deprecated will be removed in 5.0 + */ public function serialize() { return ''; } + /** + * The __unserialize() magic method will be automatically used instead of this almost all the time + * This method will be automatically used if existing serialized data was not saved as an associative array + * and the PHP version used in less than PHP 9.0 + * + * @param string $serialized + * @deprecated will be removed in 5.0 + */ public function unserialize($serialized) { // no-op