API Implement updated Serializable API

This commit is contained in:
Steve Boyd 2022-02-14 13:26:11 +13:00
parent bccbeedfdc
commit 0318372641
5 changed files with 87 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import:
jobs: jobs:
fast_finish: true fast_finish: true
include: include:
- php: 7.3 - php: 7.4
env: env:
- DB=MYSQL - DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE" - REQUIRE_INSTALLER="$REQUIRE_RECIPE"
@ -28,15 +28,17 @@ jobs:
- REQUIRE_INSTALLER="$REQUIRE_RECIPE" - REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPUNIT_TEST=1 - PHPUNIT_TEST=1
- PHPUNIT_SUITE="cms" - PHPUNIT_SUITE="cms"
- php: 7.4
env:
- DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPUNIT_TEST=1
- PHPUNIT_SUITE="framework"
- php: 8.0 - php: 8.0
env: env:
- DB=MYSQL - DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE" - REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPUNIT_TEST=1 - PHPUNIT_TEST=1
- PHPUNIT_SUITE="framework" - 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

View File

@ -40,7 +40,7 @@
"symfony/config": "^3.4 || ^4.0", "symfony/config": "^3.4 || ^4.0",
"symfony/translation": "^3.4 || ^4.0", "symfony/translation": "^3.4 || ^4.0",
"symfony/yaml": "^3.4 || ^4.0", "symfony/yaml": "^3.4 || ^4.0",
"php": "^7.3 || ^8.0", "php": "^7.4 || ^8.0",
"ext-ctype": "*", "ext-ctype": "*",
"ext-dom": "*", "ext-dom": "*",
"ext-hash": "*", "ext-hash": "*",
@ -58,6 +58,7 @@
"squizlabs/php_codesniffer": "^3.5" "squizlabs/php_codesniffer": "^3.5"
}, },
"conflict": { "conflict": {
"egulias/email-validator": "^2",
"phpunit/phpunit": "^6 || ^7 || ^8" "phpunit/phpunit": "^6 || ^7 || ^8"
}, },
"provide": { "provide": {

View File

@ -185,11 +185,42 @@ class Module implements Serializable
return substr($this->path, strlen($this->basePath) + 1); 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() public function serialize()
{ {
return json_encode([$this->path, $this->basePath, $this->composerData]); 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) public function unserialize($serialized)
{ {
list($this->path, $this->basePath, $this->composerData) = json_decode($serialized, true); list($this->path, $this->basePath, $this->composerData) = json_decode($serialized, true);

View File

@ -214,10 +214,25 @@ class ValidationResult implements Serializable
return $this; 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() 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 * @param string $serialized
* @deprecated will be removed in 5.0
*/ */
public function unserialize($serialized) public function unserialize($serialized)
{ {

View File

@ -40,11 +40,35 @@ class FlushInvalidatedResource implements SelfCheckingResourceInterface, \Serial
return false; 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() public function serialize()
{ {
return ''; 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) public function unserialize($serialized)
{ {
// no-op // no-op