ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Image.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
4
6
12
17class Image implements C\Image\Image
18{
21 use Triggerer;
22
26 private $type;
27
31 private $src;
32
36 private $alt;
37
41 protected $action = '';
42
46 private static $types = [
47 self::STANDARD,
48 self::RESPONSIVE
49 ];
50
54 public function __construct($type, $source, $alt)
55 {
56 $this->checkStringArg("src", $source);
57 $this->checkStringArg("alt", $alt);
58 $this->checkArgIsElement("type", $type, self::$types, "image type");
59
60 $this->type = $type;
61 $this->src = $source;
62 $this->alt = $alt;
63 }
64
68 public function getType()
69 {
70 return $this->type;
71 }
72
76 public function withSource($source)
77 {
78 $this->checkStringArg("src", $source);
79
80 $clone = clone $this;
81 $clone->src = $source;
82 return $clone;
83 }
84
88 public function getSource()
89 {
90 return $this->src;
91 }
92
96 public function withAlt($alt)
97 {
98 $this->checkStringArg("alt", $alt);
99
100 $clone = clone $this;
101 $clone->alt = $alt;
102 return $clone;
103 }
104
108 public function getAlt()
109 {
110 return $this->alt;
111 }
112
116 public function withAction($action)
117 {
118 $this->checkStringOrSignalArg("action", $action);
119 $clone = clone $this;
120 if (is_string($action)) {
121 $clone->action = $action;
122 } else {
123 $clone->action = null;
124 $clone->setTriggeredSignal($action, "click");
125 }
126
127 return $clone;
128 }
129
133 public function getAction()
134 {
135 if ($this->action !== null) {
136 return $this->action;
137 }
138 return $this->getTriggeredSignalsFor("click");
139 }
140
144 public function withOnClick(Signal $signal)
145 {
146 return $this->withTriggeredSignal($signal, 'click');
147 }
148
152 public function appendOnClick(Signal $signal)
153 {
154 return $this->appendTriggeredSignal($signal, 'click');
155 }
156}
An exception for terminatinating execution or to throw for unit testing.
$source
Definition: metadata.php:76
checkStringOrSignalArg($which, $value)
Throw an InvalidArgumentException if $value is no string or Signal.
withTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any other signals registered on the same event.
Definition: Triggerer.php:48
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
appendTriggeredSignal(Component\Signal $signal, $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:31
getTriggeredSignalsFor($event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:85
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
trait ComponentHelper
Provides common functionality for component implementations.
checkArgIsElement($which, $value, $array, $name)
Throw an InvalidArgumentException if $value is not an element of array.