@@ 13-56 (lines=44) @@ | ||
10 | use PhpBoot\Utils\Logger; |
|
11 | use PhpBoot\Validator\Validator; |
|
12 | ||
13 | class ValidateAnnotationHandler |
|
14 | { |
|
15 | /** |
|
16 | * @param ConsoleContainer $container |
|
17 | * @param AnnotationBlock|AnnotationTag $ann |
|
18 | */ |
|
19 | public function __invoke(ConsoleContainer $container, $ann) |
|
20 | { |
|
21 | if(!$ann->parent || !$ann->parent->parent){ |
|
22 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent parent"); |
|
23 | return; |
|
24 | } |
|
25 | $target = $ann->parent->parent->name; |
|
26 | $command = $container->getCommand($target); |
|
27 | if(!$command){ |
|
28 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent"); |
|
29 | return ; |
|
30 | } |
|
31 | $params = new AnnotationParams($ann->description, 2); |
|
32 | ||
33 | count($params)>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require 1 param, {$params->count()} given")); |
|
34 | ||
35 | if($ann->parent->name == 'param'){ |
|
36 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
|
37 | ||
38 | $paramMeta = $command->getParamMeta($paramName); |
|
39 | if($params->count()>1){ |
|
40 | $paramMeta->validation = [$params[0], $params[1]]; |
|
41 | }else{ |
|
42 | $paramMeta->validation = $params[0]; |
|
43 | if($paramMeta->validation) { |
|
44 | $v = new Validator(); |
|
45 | $v->rule($paramMeta->validation, $paramMeta->name); |
|
46 | if ($v->hasRule('optional', $paramMeta->name)) { |
|
47 | $paramMeta->isOptional = true; |
|
48 | } |
|
49 | } |
|
50 | } |
|
51 | ||
52 | return; |
|
53 | } |
|
54 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent"); |
|
55 | } |
|
56 | } |
@@ 13-56 (lines=44) @@ | ||
10 | use PhpBoot\Utils\Logger; |
|
11 | use PhpBoot\Validator\Validator; |
|
12 | ||
13 | class ValidateAnnotationHandler |
|
14 | { |
|
15 | /** |
|
16 | * @param ControllerContainer $container |
|
17 | * @param AnnotationBlock|AnnotationTag $ann |
|
18 | */ |
|
19 | public function __invoke(ControllerContainer $container, $ann) |
|
20 | { |
|
21 | if(!$ann->parent || !$ann->parent->parent){ |
|
22 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent parent"); |
|
23 | return; |
|
24 | } |
|
25 | $target = $ann->parent->parent->name; |
|
26 | $route = $container->getRoute($target); |
|
27 | if(!$route){ |
|
28 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent"); |
|
29 | return ; |
|
30 | } |
|
31 | $params = new AnnotationParams($ann->description, 2); |
|
32 | ||
33 | count($params)>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require 1 param, {$params->count()} given")); |
|
34 | ||
35 | if($ann->parent->name == 'param'){ |
|
36 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
|
37 | ||
38 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
|
39 | if($params->count()>1){ |
|
40 | $paramMeta->validation = [$params[0], $params[1]]; |
|
41 | }else{ |
|
42 | $paramMeta->validation = $params[0]; |
|
43 | if($paramMeta->validation) { |
|
44 | $v = new Validator(); |
|
45 | $v->rule($paramMeta->validation, $paramMeta->name); |
|
46 | if ($v->hasRule('optional', $paramMeta->name)) { |
|
47 | $paramMeta->isOptional = true; |
|
48 | } |
|
49 | } |
|
50 | } |
|
51 | ||
52 | return; |
|
53 | } |
|
54 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent"); |
|
55 | } |
|
56 | } |