Skip to content

Commit

Permalink
fix: swoft-cloud/swoft/issues/1297 rpc client version invalid error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Sep 13, 2020
1 parent a7059bf commit 603fee6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
3 changes: 0 additions & 3 deletions src/aop/test/unit/AopTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php declare(strict_types=1);


namespace SwoftTest\Aop\Unit;


use PHPUnit\Framework\TestCase;
use Swoft\Aop\Ast\Visitor\ProxyVisitor;
use Swoft\Aop\Proxy;
Expand All @@ -15,7 +13,6 @@
use function sprintf;
use const PHP_EOL;


/**
* Class AopTest
*
Expand Down
10 changes: 6 additions & 4 deletions src/proxy/src/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ class Proxy
*
* @param string $className
* @param Visitor $visitor
* @param string $suffix useful for RPC client proxy version
*
* @return string
* @throws ProxyException
*/
public static function newClassName(string $className, Visitor $visitor): string
public static function newClassName(string $className, Visitor $visitor, string $suffix = ''): string
{
if (isset(self::$caches[$className])) {
return self::$caches[$className];
$cacheKey = $className . $suffix;
if (isset(self::$caches[$cacheKey])) {
return self::$caches[$cacheKey];
}

$parser = new Parser();
Expand Down Expand Up @@ -75,7 +77,7 @@ public static function newClassName(string $className, Visitor $visitor): string
}

// Add cache, mark has been required.
self::$caches[$className] = $newClassName;
self::$caches[$cacheKey] = $newClassName;
return $newClassName;
}

Expand Down
9 changes: 5 additions & 4 deletions src/rpc-client/src/Annotation/Parser/ReferenceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class ReferenceParser extends Parser
{
/**
* @param int $type
* @param Reference $annotationObject
* @param Reference $refObject
*
* @return array
* @throws RpcClientException
* @throws AnnotationException
* @throws ReflectionException
* @throws ProxyException
*/
public function parse(int $type, $annotationObject): array
public function parse(int $type, $refObject): array
{
// Parse php document
$phpReader = new PhpDocReader();
Expand All @@ -56,13 +56,14 @@ public function parse(int $type, $annotationObject): array
));
}

$className = Proxy::newClassName($propClassType);
$refVersion = $refObject->getVersion();
$className = Proxy::newClassName($propClassType, $refVersion);

$this->definitions[$className] = [
'class' => $className,
];

ReferenceRegister::register($className, $annotationObject->getPool(), $annotationObject->getVersion());
ReferenceRegister::register($className, $refObject->getPool(), $refVersion);
return [$className, true];
}
}
4 changes: 2 additions & 2 deletions src/rpc-client/src/Exception/RpcClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace Swoft\Rpc\Client\Exception;

use Exception;
use RuntimeException;

/**
* Class RpcClientException
*
* @since 2.0
*/
class RpcClientException extends Exception
class RpcClientException extends RuntimeException
{
}
7 changes: 4 additions & 3 deletions src/rpc-client/src/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ class Proxy
{
/**
* @param string $className
* @param string $version Rpc version. For resolve https://github.com/swoft-cloud/swoft/issues/1297
*
* @return string
* @throws RpcClientException
* @throws ProxyException
* @throws RpcClientException
*/
public static function newClassName(string $className): string
public static function newClassName(string $className, string $version): string
{
if (!interface_exists($className)) {
throw new RpcClientException('`@var` for `@Reference` must be exist interface!');
Expand All @@ -41,6 +42,6 @@ public static function newClassName(string $className): string
$proxyId = sprintf('IGNORE_%s', Str::getUniqid());
$visitor = new ProxyVisitor($proxyId);

return BaseProxy::newClassName($className, $visitor);
return BaseProxy::newClassName($className, $visitor, $version);
}
}

0 comments on commit 603fee6

Please sign in to comment.