ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
State.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 use ILIAS\Data\URI;
28 
32 class State implements I\State\State
33 {
34  use ComponentHelper;
35 
36  public const CMD_CLOSE = 'close';
37  public const CMD_REDIRECT = 'redirect';
38 
39  protected array $buttons = [];
40  protected string $cmd = 'show';
41  protected array $params = [];
42  protected string $title = '';
43 
44  public function __construct(
45  protected ?I\IsPromptContent $content
46  ) {
47  }
48 
49  public function getTitle(): string
50  {
51  return $this->title ? $this->title : $this->content->getPromptTitle();
52  }
53 
54  public function withTitle(string $title): self
55  {
56  $clone = clone $this;
57  $clone->title = $title;
58  return $clone;
59  }
60 
61  public function withContent(I\IsPromptContent $content): self
62  {
63  $clone = clone $this;
64  $clone->content = $content;
65  return $clone;
66  }
67 
71  public function getContent(): ?I\IsPromptContent
72  {
73  return $this->content;
74  }
75 
79  public function getButtons(): array
80  {
81  return $this->content->getPromptButtons();
82  }
83 
84  public function withCloseModal(bool $flag): self
85  {
86  return $this->withCommand($flag ? self::CMD_CLOSE : '');
87  }
88 
89  public function withRedirect(URI $redirect): self
90  {
91  $clone = $this->withCommand(self::CMD_REDIRECT);
92  $clone->params = [
93  self::CMD_REDIRECT => $redirect->__toString()
94  ];
95  return $clone;
96  }
97 
98  protected function withCommand(string $cmd)
99  {
100  $clone = clone $this;
101  $clone->cmd = $cmd;
102  return $clone;
103  }
104 
105  public function getCommand(): string
106  {
107  return $this->cmd;
108  }
109 
110  public function getParameters(): array
111  {
112  return $this->params;
113  }
114 }
__toString()
Definition: URI.php:337
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
withContent(I\IsPromptContent $content)
Definition: State.php:61
__construct(protected ?I\IsPromptContent $content)
Definition: State.php:44