-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from ngmy/support-readonly-class
Add support for readonly class in PHP 8.2
- Loading branch information
Showing
13 changed files
with
170 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\Aop; | ||
|
||
use Ray\Aop\ReflectiveMethodInvocation as Invocation; | ||
|
||
use function call_user_func_array; | ||
|
||
/** | ||
* @psalm-import-type MethodBindings from Types | ||
* @psalm-import-type Arguments from Types | ||
*/ | ||
trait Php82InterceptTrait | ||
{ | ||
private readonly InterceptTraitState $_state; | ||
|
||
/** | ||
* @param MethodBindings $bindings | ||
* | ||
* @see WeavedInterface::_initState() | ||
*/ | ||
public function _initState(array $bindings): void | ||
{ | ||
$this->_state = new InterceptTraitState($bindings); | ||
} | ||
|
||
/** | ||
* @param Arguments $args | ||
* | ||
* @return mixed | ||
* | ||
* @SuppressWarnings(PHPMD.CamelCaseMethodName) | ||
*/ | ||
private function _intercept(string $func, array $args) // phpcs:ignore | ||
{ | ||
if (! $this->_state->isAspect) { | ||
$this->_state->isAspect = true; | ||
|
||
return call_user_func_array([parent::class, $func], $args); | ||
} | ||
|
||
$this->_state->isAspect = false; | ||
$result = (new Invocation($this, $func, $args, $this->_state->bindings[$func]))->proceed(); | ||
$this->_state->isAspect = true; | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\Aop; | ||
|
||
/** @psalm-import-type MethodBindings from Types */ | ||
final class InterceptTraitState | ||
{ | ||
/** | ||
* @var MethodBindings | ||
* @readonly | ||
*/ | ||
public $bindings; | ||
|
||
/** @var bool */ | ||
public $isAspect = true; | ||
|
||
/** @param MethodBindings $bindings */ | ||
public function __construct(array $bindings) | ||
{ | ||
$this->bindings = $bindings; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ | |
|
||
class FakeMockChild extends FakeMock | ||
{ | ||
public $state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\Aop; | ||
|
||
readonly class FakePhp82ReadOnlyClass {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\Aop; | ||
|
||
/** doc comment of FakeMock */ | ||
class FakeWeaverMock_523567342 extends FakeWeaverMock implements \Ray\Aop\WeavedInterface | ||
{ | ||
use \Ray\Aop\Php82InterceptTrait; | ||
/** | ||
* doc comment of returnSame | ||
*/ | ||
public function returnSame($a) | ||
{ | ||
return $this->_intercept(__FUNCTION__, func_get_args()); | ||
} | ||
|
||
/** | ||
* doc comment of getSub | ||
*/ | ||
public function getSub($a, $b) | ||
{ | ||
return $this->_intercept(__FUNCTION__, func_get_args()); | ||
} | ||
|
||
public function returnValue(null|\Ray\Aop\FakeNum $num = NULL) | ||
{ | ||
return $this->_intercept(__FUNCTION__, func_get_args()); | ||
} | ||
|
||
public function getPrivateVal() | ||
{ | ||
return $this->_intercept(__FUNCTION__, func_get_args()); | ||
} | ||
} |