ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
LinkList.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\GlobalScreen\Scope\MainMenu\Factory\isInterchangeableItemTrait;
31use InvalidArgumentException;
32use ReflectionFunction;
33use ReflectionException;
34use Generator;
37
41class LinkList extends AbstractChildItem implements
46 isChild,
48{
50 use isInterchangeableItemTrait;
52
53 protected string $title = '';
57 protected array $links = [];
58 protected bool $supports_async_loading = false;
59
63 public function withTitle(string $title): hasTitle
64 {
65 $clone = clone($this);
66 $clone->title = $title;
67
68 return $clone;
69 }
70
71 public function getTitle(): string
72 {
73 return $this->title;
74 }
75
79 public function withLinks($links): self
80 {
81 if (is_callable($links)) {
82 try {
83 $r = new ReflectionFunction($links);
84 $links = $r->isGenerator() ? iterator_to_array($links()) : $links();
85 } catch (ReflectionException) {
86 $links = false;
87 }
88
89 if (!is_array($links)) {
90 throw new InvalidArgumentException("withLinks only accepts arrays of Links or a callable providing them");
91 }
92 }
93 foreach ($links as $link) {
94 if (!$link instanceof Link) {
95 throw new InvalidArgumentException("withLinks only accepts arrays of Links or a callable providing them");
96 }
97 }
98 $clone = clone($this);
99 $clone->links = $links;
100
101 return $clone;
102 }
103
107 public function getLinks(): array
108 {
109 return $this->links;
110 }
111
116 {
117 $clone = clone($this);
118 $clone->supports_async_loading = $supported;
119
120 return $clone;
121 }
122
126 public function supportsAsynchronousLoading(): bool
127 {
129 }
130
131 public function isVisible(): bool
132 {
133 $visible_links = 0;
134 foreach ($this->getLinks() as $link) {
135 if ($link->isVisible()) {
136 $visible_links++;
137 }
138 }
139 return $visible_links > 0 && parent::isVisible();
140 }
141}
Interface supportsAsynchronousLoading Types, which implement this interface, can load their content a...
trait hasSymbolTrait
Trait hasSymbolTrait.