ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ContextMatcher.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
21
29{
37 public function isDirectDescendantOfAny(array $context_asc, array $search_any): bool
38 {
39 // ensure minimum context size allowing direct descendants
40 $context_size = count($context_asc);
41 if (2 > $context_size) {
42 return false;
43 }
44 return in_array($context_asc[$context_size - 2], $search_any, true);
45 }
46
54 public function isDirectDescendantOf(array $context_asc, array $search_exactly): bool
55 {
56 // ensure minimum context size allowing direct descendants
57 $search_size = count($search_exactly);
58 if (0 === $search_size || $search_size + 1 > count($context_asc)) {
59 return false;
60 }
61 $ancestors = array_slice($context_asc, 0, -1);
62 return $search_exactly === array_slice($ancestors, -$search_size);
63 }
64
72 public function isIndirectDescendantOfAny(array $context_asc, array $search_any): bool
73 {
74 // ensure minimum context size allowing direct descendants
75 if (3 > count($context_asc)) {
76 return false;
77 }
78 $indirect_ancestors = array_slice($context_asc, 0, -2);
79 return [] !== array_intersect($indirect_ancestors, $search_any);
80 }
81
89 public function isIndirectDescendantOf(array $context_asc, array $search_exactly): bool
90 {
91 // ensure minimum context size allowing direct descendants
92 $search_size = count($search_exactly);
93 if (0 === $search_size || $search_size + 2 > count($context_asc)) {
94 return false;
95 }
96 $indirect_ancestors = array_slice($context_asc, 0, -2);
97 $last_start = count($indirect_ancestors) - $search_size;
98 for ($start = 0; $last_start >= $start; $start++) {
99 if ($search_exactly === array_slice($indirect_ancestors, $start, $search_size)) {
100 return true;
101 }
102 }
103 return false;
104 }
105
113 public function isDescendantOfAny(array $context_asc, array $search_any): bool
114 {
115 return $this->isDirectDescendantOfAny($context_asc, $search_any)
116 || $this->isIndirectDescendantOfAny($context_asc, $search_any);
117 }
118
126 public function isDescendantOf(array $context_asc, array $search_exactly): bool
127 {
128 return $this->isDirectDescendantOf($context_asc, $search_exactly)
129 || $this->isIndirectDescendantOf($context_asc, $search_exactly);
130 }
131}
Searches for patterns inside the given rendering context in order to apply context rendering.
isIndirectDescendantOf(array $context_asc, array $search_exactly)
Returns true the exact canonical names of $search_exactly are indirect ancestors of the last canonica...
isIndirectDescendantOfAny(array $context_asc, array $search_any)
Returns true if any canonical name of $search_any is an indirect ancestor of the last canonical name ...
isDescendantOfAny(array $context_asc, array $search_any)
Returns true if any canonical name of $search_any is an ancestor of any kind of the last canonical na...
isDirectDescendantOfAny(array $context_asc, array $search_any)
Returns true if any canonical name of $search_any is a direct ancestor of the last canonical name ins...
isDirectDescendantOf(array $context_asc, array $search_exactly)
Returns true the exact canonical names of $search_exactly are direct ancestors of the last canonical ...
isDescendantOf(array $context_asc, array $search_exactly)
Returns true the exact canonical names of $search_exactly are indirect ancestors of any kind of the l...