ILIAS  release_7 Revision v7.30-3-g800a261c036
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 {
126 $clone->action = null;
127 $clone->setTriggeredSignal($action, "click");
128 }
129
130 return $clone;
131 }
132
136 public function getAction()
137 {
138 if ($this->action !== null) {
139 return $this->action;
140 }
141 return $this->getTriggeredSignalsFor("click");
142 }
143
147 public function withOnClick(Signal $signal)
148 {
149 return $this->withTriggeredSignal($signal, 'click');
150 }
151
155 public function appendOnClick(Signal $signal)
156 {
157 return $this->appendTriggeredSignal($signal, 'click');
158 }
159}
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.