Skip to content

Commit

Permalink
提交
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjincheng committed May 17, 2019
1 parent a5474f2 commit 68c5ae7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Validate/Annotation/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
class Filter extends Annotation
{
protected static $cache = [];
/**
* 默认值
* @var mixed
Expand Down Expand Up @@ -185,6 +186,9 @@ public static function filter(ReflectionClass $reflectionClass, $values)
*/
public static function buildRole(ReflectionClass $reflectionClass)
{
if (array_key_exists($reflectionClass->name, self::$cache)) {
return self::$cache[$reflectionClass->name];
}
$filterRole = [];
foreach ($reflectionClass->getProperties() as $property) {
$filter = Server::$instance->getContainer()->get(CachedReader::class)->getPropertyAnnotation($property, Filter::class);
Expand All @@ -195,6 +199,7 @@ public static function buildRole(ReflectionClass $reflectionClass)
}
}
}
self::$cache[$reflectionClass->name] = $filterRole;
return $filterRole;
}
}
5 changes: 5 additions & 0 deletions src/Validate/Annotation/Validated.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
class Validated extends Annotation
{
protected static $cache = [];
/**
* 要求此字段/属性是必须的(不为空的)。
* @var bool
Expand Down Expand Up @@ -338,6 +339,9 @@ public static function valid(ReflectionClass $reflectionClass, $values)
*/
public static function buildRole(ReflectionClass $reflectionClass)
{
if (array_key_exists($reflectionClass->name, self::$cache)) {
return self::$cache[$reflectionClass->name];
}
$validRole = [];
foreach ($reflectionClass->getProperties() as $property) {
$validated = Server::$instance->getContainer()->get(CachedReader::class)->getPropertyAnnotation($property, Validated::class);
Expand All @@ -347,6 +351,7 @@ public static function buildRole(ReflectionClass $reflectionClass)
}
}
}
self::$cache[$reflectionClass->name] = $validRole;
return $validRole;
}
}

0 comments on commit 68c5ae7

Please sign in to comment.