ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MessageBox.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2018 Thomas Famula <famula@leifos.de> Extended GPL, see docs/LICENSE */
4 
6 
7 use ILIAS\UI\Component as C;
9 
10 class MessageBox implements C\MessageBox\MessageBox
11 {
12  use ComponentHelper;
13 
17  private $type;
18 
22  private $message_text;
23 
27  private $buttons = [];
28 
32  private $links = [];
33 
37  private static $types = array(self::FAILURE
38  , self::SUCCESS
39  , self::INFO
40  , self::CONFIRMATION
41  );
42 
46  public function __construct($type, $message_text)
47  {
48  $this->checkArgIsElement("type", $type, self::$types, "message box type");
49  $this->checkStringArg("message_text", $message_text);
50  $this->type = $type;
51  $this->message_text = $message_text;
52  }
53 
57  public function getType()
58  {
59  return $this->type;
60  }
61 
65  public function getMessageText()
66  {
67  return $this->message_text;
68  }
69 
73  public function getButtons() : array
74  {
75  return $this->buttons;
76  }
77 
81  public function getLinks() : array
82  {
83  return $this->links;
84  }
85 
89  public function withButtons(array $buttons)
90  {
91  $types = array(C\Component::class);
92  $this->checkArgListElements("buttons", $buttons, $types);
93 
94  $clone = clone $this;
95  $clone->buttons = $buttons;
96  return $clone;
97  }
98 
102  public function withLinks(array $links)
103  {
104  $types = array(C\Component::class);
105  $this->checkArgListElements("links", $links, $types);
106 
107  $clone = clone $this;
108  $clone->links = $links;
109  return $clone;
110  }
111 }
checkArgIsElement($which, $value, $array, $name)
Throw an InvalidArgumentException if $value is not an element of array.
trait ComponentHelper
Provides common functionality for component implementations.
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
checkArgListElements($which, array &$values, &$classes)
Check every element of the list if it is an instance of one of the given classes. ...