Skip to content

Commit

Permalink
Remove deprecated Serializable interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Feb 18, 2024
1 parent a1d357c commit 906890c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
25 changes: 11 additions & 14 deletions src/Aop/Framework/AbstractInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Go\Core\AspectKernel;
use ReflectionFunction;
use ReflectionMethod;
use Serializable;

/**
* Base class for all framework interceptor implementations
Expand All @@ -43,7 +42,7 @@
* return $result;
* }
*/
abstract class AbstractInterceptor implements Interceptor, OrderedAdvice, Serializable
abstract class AbstractInterceptor implements Interceptor, OrderedAdvice
{
/**
* Local cache of advices for faster unserialization on big projects
Expand Down Expand Up @@ -128,28 +127,26 @@ public function getRawAdvice(): Closure
}

/**
* Serializes an interceptor into string representation
* Serializes an interceptor into it's representation
*/
final public function serialize(): string
final public function __serialize(): array
{
$vars = array_filter(get_object_vars($this));
$state = array_filter(get_object_vars($this));

$vars['adviceMethod'] = static::serializeAdvice($this->adviceMethod);
$state['adviceMethod'] = static::serializeAdvice($this->adviceMethod);

return serialize($vars);
return $state;
}

/**
* Unserialize an interceptor from the string
* Un-serializes an interceptor from it's stored state
*
* @param string $serialized The string representation of the object.
* @param array $state The stored representation of the interceptor.
*/
final public function unserialize($serialized): void
final public function __unserialize(array $state): void
{
$vars = unserialize($serialized, ['allowed_classes' => false]);

$vars['adviceMethod'] = static::unserializeAdvice($vars['adviceMethod']);
foreach ($vars as $key => $value) {
$state['adviceMethod'] = static::unserializeAdvice($state['adviceMethod']);
foreach ($state as $key => $value) {
$this->$key = $value;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Go/Aop/Framework/BaseInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testCanSerializeInterceptor()
$mockClass = get_class($mock);
$mockNameLength = strlen($mockClass);
$result = serialize($mock);
$expected = 'C:' . $mockNameLength . ':"' . $mockClass . '":161:{a:1:{s:12:"adviceMethod";a:3:{s:5:"scope";s:6:"aspect";s:6:"method";s:26:"Go\Aop\Framework\{closure}";s:6:"aspect";s:36:"Go\Aop\Framework\BaseInterceptorTest";}}}';
$expected = 'O:' . $mockNameLength . ':"' . $mockClass . '":1:{s:12:"adviceMethod";a:3:{s:5:"scope";s:6:"aspect";s:6:"method";s:26:"Go\Aop\Framework\{closure}";s:6:"aspect";s:36:"Go\Aop\Framework\BaseInterceptorTest";}}';

$this->assertEquals($expected, $result);
}
Expand All @@ -57,7 +57,7 @@ public function testCanUnserializeInterceptor()
$mockClass = get_class($mock);
$mockNameLength = strlen($mockClass);
// Trick to mock unserialization of advice
$serialized = 'C:' . $mockNameLength .':"' . $mockClass . '":161:{a:1:{s:12:"adviceMethod";a:3:{s:5:"scope";s:6:"aspect";s:6:"method";s:26:"Go\Aop\Framework\{closure}";s:6:"aspect";s:36:"Go\Aop\Framework\BaseInterceptorTest";}}}';
$serialized = 'O:' . $mockNameLength .':"' . $mockClass . '":1:{s:12:"adviceMethod";a:3:{s:5:"scope";s:6:"aspect";s:6:"method";s:26:"Go\Aop\Framework\{closure}";s:6:"aspect";s:36:"Go\Aop\Framework\BaseInterceptorTest";}}';
$result = unserialize($serialized);
$this->assertEquals($advice, $result->getRawAdvice());
}
Expand Down

0 comments on commit 906890c

Please sign in to comment.