Conditions | 5 |
Paths | 5 |
Total Lines | 37 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
21 | public function render(NodeLocatorInterface $doc, Config $cfg, RenderEvent $parentEvent = null, callable $callback = null) |
||
22 | { |
||
23 | /** @var Config\Spec $spec */ |
||
24 | foreach ($cfg->getQueue() as $spec) { |
||
25 | // TODO skip if locator or node owner document empty |
||
26 | |||
27 | $events = $this->getEvents(); |
||
28 | $nodes = $doc->locate($spec->getLocator()); |
||
29 | |||
30 | $callback and call_user_func($callback, $spec, $nodes); |
||
|
|||
31 | |||
32 | /** @var NodeInterface $node */ |
||
33 | foreach ($nodes as $node) { |
||
34 | |||
35 | $event = new RenderEvent($this, $node, $spec, $parentEvent); |
||
36 | |||
37 | $events->attach(RenderEvent::class, function (RenderEvent $subEvent) use ($spec, $event) { |
||
38 | $view = $spec->getView(); |
||
39 | if (empty($view)) { |
||
40 | return; |
||
41 | } |
||
42 | |||
43 | $this->render( |
||
44 | $subEvent->getNode(), |
||
45 | new Config($view), |
||
46 | $event, |
||
47 | function(Config\Spec $spec, NodeList $nodes) use ($subEvent) { |
||
48 | $subEvent->setNode($nodes, $spec->getKey()); |
||
49 | } |
||
50 | ); |
||
51 | }, RenderEvent::FINISH); |
||
52 | |||
53 | |||
54 | $events->trigger($event); |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 |
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
die
introduces 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 withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.