ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
LinkList.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
34 use Generator;
35 
39 class LinkList extends AbstractChildItem implements
40  hasTitle,
42  hasSymbol,
44  isChild
45 {
46  use hasSymbolTrait;
48 
49  protected string $title = '';
53  protected array $links = [];
54  protected bool $supports_async_loading = false;
55 
60  public function withTitle(string $title): hasTitle
61  {
62  $clone = clone($this);
63  $clone->title = $title;
64 
65  return $clone;
66  }
67 
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.
$r