Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ef029a5

Browse files
committed
如果指定了装饰器,单未实现DecoratorInterface接口则报错
1 parent a9d7d82 commit ef029a5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

‎src/PropertyDocParser.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static function getProperties(string $className): array
7878
continue;
7979
}
8080

81-
//如果注释没有命名空间, 则查看是否再当前命名空间下存在该类
81+
//如果注释没有命名空间, 则查看是否在当前命名空间下存在该类
8282
if (strpos($matchType, "\\") !== 0) {
8383
$matchType = $reflection->getNamespaceName() . "\\" . $matchType;
8484
}
@@ -105,10 +105,14 @@ protected static function getDecoratorByDoc(string $doc): ?string
105105
//解析类似@return DecoratorInterface 的文档对象
106106
preg_match("/@return[ ]+([\w\\\]+)/", $doc, $matches);
107107
$decorator = $matches[1] ?? '';
108-
if (!$decorator || !class_exists($decorator)) {
108+
if (!$decorator) {
109109
return null;
110110
}
111111

112+
if (!is_subclass_of($decorator, \Xbyter\PhpObjectMapping\Interfaces\DecoratorInterface::class)) {
113+
throw new \ErrorException('The decorator does not implement DecoratorInterface');
114+
}
115+
112116
return $decorator;
113117
}
114118
}

‎src/PropertySetter.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,18 @@ public function fill($data, \Closure $newInstanceCallback, array $parentProperti
8484
* @param string $propertyName
8585
* @param $value
8686
* @param string|null $decoratorName
87+
* @throws \ErrorException
8788
*/
8889
protected function setPropertyValue(string $propertyName, $value, ?string $decoratorName = null): void
8990
{
9091
if ($decoratorName) {
92+
if (!is_subclass_of($decoratorName, \Xbyter\PhpObjectMapping\Interfaces\DecoratorInterface::class)) {
93+
throw new \ErrorException('The decorator does not implement DecoratorInterface');
94+
}
95+
9196
//如果有装饰器, 则转为最新的值再赋值
9297
$decorator = new $decoratorName();
93-
if ($decorator instanceof \Xbyter\PhpObjectMapping\Interfaces\DecoratorInterface) {
94-
$value = $decorator->decorate($value);
95-
}
98+
$value = $decorator->decorate($value);
9699
}
97100
$this->class->{$propertyName} = $value;
98101
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /