This repository has been archived by the owner on Sep 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Option.php
executable file
·166 lines (150 loc) · 4.05 KB
/
Option.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/*
* ###########
* #__________#
* __________#
* ________#
* _____###_____²xiT development
* _________#
* ___________#
* #__________#
* _#________#
* __#______#
* ____####
*/
/**
* @package MyOOF
* @version 2.00
* @author Joris Berthelot <admin@eexit.net>
* @copyright Copyright (c) 2008, Joris Berthelot
* @license http://www.opensource.org/licenses/mit-license.php MIT Licence
*/
/**
* @package MyOOF
*/
class Option extends Element {
/**
* The Option content (visible value)
* @var string
* @access public
*/
public $caption = '';
/**
* The final compiled opbject result will go in this var
* @var string
* @access protected
*/
protected $_output;
/**
* List of available attributes
* @var array
* @access protected
*/
public $_pattern = array(
'class' => null,
'dir' => 'ltr',
'disabled' => null,
'id' => null,
'label' => null,
'lang' => null,
'selected' => null,
'style' => null,
'title' => null,
'value' => null,
'xml:lang' => null,
'xmlns' => null
);
/**
* List of default attribute values
* @var array
* @access protected
*/
protected $_defaultValues = array(
'dir' => array('ltr', 'rtl'),
'disabled' => 'disabled',
'selected' => 'selected'
);
/**
* Instanciates the self class if allowed in
* {@link Element::$_availableChilds}
* @final
* @access public
* @param [array $config = null Associative array of attributes]
* @param [string $caption = '' Option caption]
*/
final public function __construct(array $config = null, $caption = '') {
if (parent::__construct($this)) {
// Sets caption
$this->setCaption($caption);
if (!empty($config)) {
$this->setAttributes($config);
}
}
}
/**
* Sets the Option caption ({@link Option::$caption})
* @access public
* @param string $caption Caption to set
* @return object $this
*/
public function setCaption($caption) {
$this->caption = $caption;
return $this;
}
/**
* Gets the Option caption ({@link Option::$caption})
* @access public
* @return string $caption Option caption
*/
public function getCaption() {
return $this->caption;
}
/**
* Unsets the Option caption ({@link Option::$caption})
* @access public
* @return object $this
*/
public function unsetCaption() {
$this->caption = '';
return $this;
}
/**
* Gets final source code. Also called by {@link Element::__toString()}
* @final
* @access public
* @return mixed string The generated object source code | bool false
*/
final public function getOutput() {
if ($this->_buildOption()) {
return $this->_output;
}
// An error occured
$this->_printError('Fatal error', 'Unable to compile '
. __CLASS__
. '::_pattern. Please check your given attribute set');
return false;
}
/**
* Generates final source code. Called by {@link Option::getOutput()}
* @access private
* @return bool true
*/
private function _buildOption() {
$this->_output = '<option ';
foreach ($this->_pattern as $attr => $value) {
if (!is_null($value)) {
$this->_output .= $attr . '="' . $value . '" ';
}
}
if (empty($this->caption)) {
$this->_output = substr($this->_output, 0, -1) . '></option>';
} else {
$this->_output = substr($this->_output, 0, -1)
. '>'
. $this->caption
. '</option>';
}
return true;
}
}
?>