Instruction.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Settings\Form; |
| 4 | |
| 5 | use AC\Form\Element; |
| 6 | |
| 7 | class Instruction { |
| 8 | |
| 9 | /** |
| 10 | * @var Element |
| 11 | */ |
| 12 | private $element; |
| 13 | |
| 14 | /** |
| 15 | * @var string |
| 16 | */ |
| 17 | private $instruction; |
| 18 | |
| 19 | public function __construct( Element $element, $instruction ) { |
| 20 | $this->element = $element; |
| 21 | $this->instruction = (string) $instruction; |
| 22 | } |
| 23 | |
| 24 | private function render() { |
| 25 | $html = $this->element->render(); |
| 26 | |
| 27 | if ( 'on' === $this->element->get_value() ) { |
| 28 | $html .= $this->instruction; |
| 29 | } |
| 30 | |
| 31 | return $html; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @return string |
| 36 | */ |
| 37 | public function __toString() { |
| 38 | return $this->render(); |
| 39 | } |
| 40 | |
| 41 | } |