ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
LinkList.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
35 use Generator;
36 
41 class LinkList extends AbstractChildItem implements
42  hasTitle,
44  hasSymbol,
46  isChild
47 {
49  use hasSymbolTrait;
51 
55  protected $title = '';
59  protected $links = [];
63  protected $supports_async_loading = false;
64 
69  public function withTitle(string $title) : hasTitle
70  {
71  $clone = clone($this);
72  $clone->title = $title;
73 
74  return $clone;
75  }
76 
80  public function getTitle() : string
81  {
82  return $this->title;
83  }
84 
88  public function withLinks($links) : self
89  {
90  if (is_callable($links)) {
91  try {
92  $r = new ReflectionFunction($links);
93  $links = $r->isGenerator() ? iterator_to_array($links()) : $links();
94  } catch (ReflectionException $e) {
95  $links = false;
96  }
97 
98  if (!is_array($links)) {
99  throw new InvalidArgumentException("withLinks only accepts arrays of Links or a callable providing them");
100  }
101  }
102  foreach ($links as $link) {
103  if (!$link instanceof Link) {
104  throw new InvalidArgumentException("withLinks only accepts arrays of Links or a callable providing them");
105  }
106  }
107  $clone = clone($this);
108  $clone->links = $links;
109 
110  return $clone;
111  }
112 
116  public function getLinks() : array
117  {
118  return $this->links;
119  }
120 
125  {
126  $clone = clone($this);
127  $clone->supports_async_loading = $supported;
128 
129  return $clone;
130  }
131 
135  public function supportsAsynchronousLoading() : bool
136  {
138  }
139 
140  public function isVisible() : bool
141  {
142  $visible_links = 0;
143  foreach ($this->getLinks() as $link) {
144  if ($link->isVisible()) {
145  $visible_links++;
146  }
147  }
148  return $visible_links > 0 && parent::isVisible();
149  }
150 }
Interface supportsAsynchronousLoading Types, which implement this interface, can load their content a...
Interface hasSymbol Methods for Entries with Symbols.
Definition: hasSymbol.php:32
trait hasSymbolTrait
Trait hasSymbolTrait.