|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpBoot\Controller\Annotations; |
|
4
|
|
|
|
|
5
|
|
|
use PhpBoot\Annotation\AnnotationBlock; |
|
6
|
|
|
use PhpBoot\Annotation\AnnotationTag; |
|
7
|
|
|
use PhpBoot\Controller\ControllerContainer; |
|
8
|
|
|
use PhpBoot\Entity\ContainerFactory; |
|
9
|
|
|
use PhpBoot\Entity\EntityContainerBuilder; |
|
10
|
|
|
use PhpBoot\Exceptions\AnnotationSyntaxException; |
|
11
|
|
|
use PhpBoot\Metas\ReturnMeta; |
|
12
|
|
|
use PhpBoot\Utils\AnnotationParams; |
|
13
|
|
|
use PhpBoot\Utils\Logger; |
|
14
|
|
|
|
|
15
|
|
|
class BindAnnotationHandler |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param ControllerContainer $container |
|
19
|
|
|
* @param AnnotationBlock|AnnotationTag $ann |
|
20
|
|
|
* @param EntityContainerBuilder $entityBuilder |
|
21
|
|
|
*/ |
|
22
|
3 |
|
public function __invoke(ControllerContainer $container, $ann, EntityContainerBuilder $entityBuilder) |
|
23
|
|
|
{ |
|
24
|
3 |
|
if(!$ann->parent || !$ann->parent->parent){ |
|
25
|
|
|
Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent param/return"); |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
3 |
|
$target = $ann->parent->parent->name; |
|
29
|
3 |
|
$route = $container->getRoute($target); |
|
30
|
3 |
|
if(!$route){ |
|
31
|
|
|
Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent param/return"); |
|
32
|
|
|
return ; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
3 |
|
$params = new AnnotationParams($ann->description, 2); |
|
36
|
|
|
|
|
37
|
3 |
|
$params->count()>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require 1 param, {$params->count()} given")); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
3 |
|
$handler = $route->getResponseHandler(); |
|
40
|
|
|
|
|
41
|
3 |
|
if ($ann->parent->name == 'return'){ |
|
42
|
|
|
list($target, $return) = $handler->getMappingBySource('return'); |
|
43
|
|
|
if($return){ |
|
44
|
|
|
$handler->eraseMapping($target); |
|
45
|
|
|
$handler->setMapping($params[0], $return); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
3 |
|
}elseif($ann->parent->name == 'param'){ |
|
49
|
3 |
|
list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
3 |
|
$paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
|
52
|
3 |
|
if($paramMeta->isPassedByReference){ |
|
53
|
3 |
|
list($target, $ori) = $handler->getMappingBySource('params.'.$paramName); |
|
54
|
3 |
|
if($ori){ |
|
55
|
3 |
|
$handler->eraseMapping($target); |
|
56
|
3 |
|
} |
|
57
|
|
|
//输出绑定 |
|
58
|
3 |
|
$handler->setMapping( |
|
59
|
3 |
|
$params[0], |
|
60
|
3 |
|
new ReturnMeta( |
|
61
|
3 |
|
'params.'.$paramMeta->name, |
|
62
|
3 |
|
$paramMeta->type, $paramDoc, |
|
63
|
3 |
|
ContainerFactory::create($entityBuilder, $paramMeta->type) |
|
64
|
3 |
|
) |
|
65
|
3 |
|
); |
|
66
|
3 |
|
}else{ |
|
67
|
3 |
|
$paramMeta->source = $params[0]; |
|
68
|
|
|
} |
|
69
|
3 |
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.