1<?php 2/** 3 * Class representing an <optgroup> tag 4 * 5 * PHP version 5 6 * 7 * LICENSE 8 * 9 * This source file is subject to BSD 3-Clause License that is bundled 10 * with this package in the file LICENSE and available at the URL 11 * https://raw.githubusercontent.com/pear/HTML_QuickForm2/trunk/docs/LICENSE 12 * 13 * @category HTML 14 * @package HTML_QuickForm2 15 * @author Alexey Borzov <avb@php.net> 16 * @author Bertrand Mansion <golgote@mamasam.com> 17 * @copyright 2006-2021 Alexey Borzov <avb@php.net>, Bertrand Mansion <golgote@mamasam.com> 18 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License 19 * @link https://pear.php.net/package/HTML_QuickForm2 20 */ 21 22/** 23 * Collection of <option>s and <optgroup>s 24 */ 25require_once 'HTML/QuickForm2/Element/Select/OptionContainer.php'; 26 27/** 28 * Class representing an <optgroup> tag 29 * 30 * Do not instantiate this class yourself, use 31 * {@link HTML_QuickForm2_Element_Select::addOptgroup()} method 32 * 33 * @category HTML 34 * @package HTML_QuickForm2 35 * @author Alexey Borzov <avb@php.net> 36 * @author Bertrand Mansion <golgote@mamasam.com> 37 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License 38 * @version Release: 2.2.2 39 * @link https://pear.php.net/package/HTML_QuickForm2 40 * @internal 41 */ 42class HTML_QuickForm2_Element_Select_Optgroup 43 extends HTML_QuickForm2_Element_Select_OptionContainer 44{ 45 /** 46 * Class constructor 47 * 48 * @param array &$values Reference to values of parent <select> element 49 * @param array &$possibleValues Reference to possible values of parent <select> element 50 * @param string $label 'label' attribute for optgroup tag 51 * @param string|array $attributes Additional attributes for <optgroup> tag 52 * (either as a string or as an associative array) 53 */ 54 public function __construct(&$values, &$possibleValues, $label, $attributes = null) 55 { 56 parent::__construct($values, $possibleValues); 57 $this->setAttributes($attributes); 58 $this->attributes['label'] = (string)$label; 59 } 60 61 public function __toString() 62 { 63 $indent = $this->getIndent(); 64 $linebreak = self::getOption(self::OPTION_LINEBREAK); 65 return $indent . '<optgroup' . $this->getAttributes(true) . '>' . 66 $linebreak . parent::__toString() . $indent . '</optgroup>' . $linebreak; 67 } 68} 69?>