Debian Codegraph @

vendor/ipl/web/src/FormElement/ScheduleElement/Common/FieldsProtector.php

raw
1 <?php
2
3 namespace ipl\Web\FormElement\ScheduleElement\Common;
4
5 trait FieldsProtector
6 {
7 /** @var callable */
8 protected $protector;
9
10 /**
11 * Set callback to protect ids with
12 *
13 * @param ?callable $protector
14 *
15 * @return $this
16 */
17 public function setIdProtector(?callable $protector): self
18 {
19 $this->protector = $protector;
20
21 return $this;
22 }
23
24 /**
25 * Protect the given html id
26 *
27 * The provided id is returned as is, if no protector is specified
28 *
29 * @param string $id
30 *
31 * @return string
32 */
33 public function protectId(string $id): string
34 {
35 if (is_callable($this->protector)) {
36 return call_user_func($this->protector, $id);
37 }
38
39 return $id;
40 }
41 }