@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class TSimpleDynamicParser |
21 | 21 | { |
22 | - const PARAMETER_TOKEN_REGEXP = '/\$([^\$]+)\$/'; |
|
23 | - const DYNAMIC_TOKEN = '`!`'; |
|
22 | + const PARAMETER_TOKEN_REGEXP='/\$([^\$]+)\$/'; |
|
23 | + const DYNAMIC_TOKEN='`!`'; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Parse the sql text for dynamic place holders of the form $name$. |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function parse($sqlText) |
31 | 31 | { |
32 | - $matches = array(); |
|
33 | - $mappings = array(); |
|
32 | + $matches=array(); |
|
33 | + $mappings=array(); |
|
34 | 34 | preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches); |
35 | - for($i = 0, $k=count($matches[1]); $i<$k; $i++) |
|
35 | + for($i=0, $k=count($matches[1]); $i < $k; $i++) |
|
36 | 36 | { |
37 | - $mappings[] = $matches[1][$i]; |
|
38 | - $sqlText = str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText); |
|
37 | + $mappings[]=$matches[1][$i]; |
|
38 | + $sqlText=str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText); |
|
39 | 39 | } |
40 | 40 | return array('sql'=>$sqlText, 'parameters'=>$mappings); |
41 | 41 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * Regular expression for parsing inline parameter maps. |
27 | 27 | */ |
28 | - const PARAMETER_TOKEN_REGEXP = '/#([^#]+)#/'; |
|
28 | + const PARAMETER_TOKEN_REGEXP='/#([^#]+)#/'; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Parse the sql text for inline parameters. |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function parse($sqlText, $scope) |
37 | 37 | { |
38 | - $matches = array(); |
|
39 | - $mappings = array(); |
|
38 | + $matches=array(); |
|
39 | + $mappings=array(); |
|
40 | 40 | preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches); |
41 | 41 | |
42 | - for($i = 0, $k=count($matches[1]); $i<$k; $i++) |
|
42 | + for($i=0, $k=count($matches[1]); $i < $k; $i++) |
|
43 | 43 | { |
44 | - $mappings[] = $this->parseMapping($matches[1][$i], $scope); |
|
45 | - $sqlText = str_replace($matches[0][$i], '?', $sqlText); |
|
44 | + $mappings[]=$this->parseMapping($matches[1][$i], $scope); |
|
45 | + $sqlText=str_replace($matches[0][$i], '?', $sqlText); |
|
46 | 46 | } |
47 | 47 | return array('sql'=>$sqlText, 'parameters'=>$mappings); |
48 | 48 | } |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | */ |
56 | 56 | protected function parseMapping($token, $scope) |
57 | 57 | { |
58 | - $mapping = new TParameterProperty; |
|
59 | - $properties = explode(',', $token); |
|
58 | + $mapping=new TParameterProperty; |
|
59 | + $properties=explode(',', $token); |
|
60 | 60 | $mapping->setProperty(trim(array_shift($properties))); |
61 | 61 | foreach($properties as $property) |
62 | 62 | { |
63 | - $prop = explode('=',$property); |
|
64 | - $name = trim($prop[0]); $value=trim($prop[1]); |
|
63 | + $prop=explode('=', $property); |
|
64 | + $name=trim($prop[0]); $value=trim($prop[1]); |
|
65 | 65 | if($mapping->canSetProperty($name)) |
66 | 66 | $mapping->{'set'.$name}($value); |
67 | 67 | else |
@@ -109,8 +109,7 @@ discard block |
||
109 | 109 | try |
110 | 110 | { |
111 | 111 | $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText()); |
112 | - } |
|
113 | - catch(Exception $e) |
|
112 | + } catch(Exception $e) |
|
114 | 113 | { |
115 | 114 | throw new TDbException('dbcommand_prepare_failed',$e->getMessage(),$this->getText()); |
116 | 115 | } |
@@ -186,11 +185,9 @@ discard block |
||
186 | 185 | { |
187 | 186 | $this->_statement->execute(); |
188 | 187 | return $this->_statement->rowCount(); |
189 | - } |
|
190 | - else |
|
188 | + } else |
|
191 | 189 | return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
192 | - } |
|
193 | - catch(Exception $e) |
|
190 | + } catch(Exception $e) |
|
194 | 191 | { |
195 | 192 | throw new TDbException('dbcommand_execute_failed',$e->getMessage(),$this->getDebugStatementText()); |
196 | 193 | } |
@@ -223,8 +220,7 @@ discard block |
||
223 | 220 | else |
224 | 221 | $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
225 | 222 | return new TDbDataReader($this); |
226 | - } |
|
227 | - catch(Exception $e) |
|
223 | + } catch(Exception $e) |
|
228 | 224 | { |
229 | 225 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
230 | 226 | } |
@@ -250,8 +246,7 @@ discard block |
||
250 | 246 | $result=$this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
251 | 247 | $this->_statement->closeCursor(); |
252 | 248 | return $result; |
253 | - } |
|
254 | - catch(Exception $e) |
|
249 | + } catch(Exception $e) |
|
255 | 250 | { |
256 | 251 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
257 | 252 | } |
@@ -279,8 +274,7 @@ discard block |
||
279 | 274 | return stream_get_contents($result); |
280 | 275 | else |
281 | 276 | return $result; |
282 | - } |
|
283 | - catch(Exception $e) |
|
277 | + } catch(Exception $e) |
|
284 | 278 | { |
285 | 279 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
286 | 280 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param TDbConnection the database connection |
46 | 46 | * @param string the SQL statement to be executed |
47 | 47 | */ |
48 | - public function __construct(TDbConnection $connection,$text) |
|
48 | + public function __construct(TDbConnection $connection, $text) |
|
49 | 49 | { |
50 | 50 | $this->_connection=$connection; |
51 | 51 | $this->setText($text); |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function __sleep() |
58 | 58 | { |
59 | - return array_diff(parent::__sleep(),array("\0TDbCommand\0_statement")); |
|
59 | + return array_diff(parent::__sleep(), array("\0TDbCommand\0_statement")); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | catch(Exception $e) |
114 | 114 | { |
115 | - throw new TDbException('dbcommand_prepare_failed',$e->getMessage(),$this->getText()); |
|
115 | + throw new TDbException('dbcommand_prepare_failed', $e->getMessage(), $this->getText()); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | { |
143 | 143 | $this->prepare(); |
144 | 144 | if($dataType===null) |
145 | - $this->_statement->bindParam($name,$value); |
|
145 | + $this->_statement->bindParam($name, $value); |
|
146 | 146 | else if($length===null) |
147 | - $this->_statement->bindParam($name,$value,$dataType); |
|
147 | + $this->_statement->bindParam($name, $value, $dataType); |
|
148 | 148 | else |
149 | - $this->_statement->bindParam($name,$value,$dataType,$length); |
|
149 | + $this->_statement->bindParam($name, $value, $dataType, $length); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | { |
164 | 164 | $this->prepare(); |
165 | 165 | if($dataType===null) |
166 | - $this->_statement->bindValue($name,$value); |
|
166 | + $this->_statement->bindValue($name, $value); |
|
167 | 167 | else |
168 | - $this->_statement->bindValue($name,$value,$dataType); |
|
168 | + $this->_statement->bindValue($name, $value, $dataType); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | } |
193 | 193 | catch(Exception $e) |
194 | 194 | { |
195 | - throw new TDbException('dbcommand_execute_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
195 | + throw new TDbException('dbcommand_execute_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | } |
227 | 227 | catch(Exception $e) |
228 | 228 | { |
229 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
229 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | } |
254 | 254 | catch(Exception $e) |
255 | 255 | { |
256 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
256 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | } |
283 | 283 | catch(Exception $e) |
284 | 284 | { |
285 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
285 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 |
@@ -165,6 +165,7 @@ discard block |
||
165 | 165 | * placeholders, this will be the 1-indexed position of the parameter. |
166 | 166 | * @param mixed The value to bind to the parameter |
167 | 167 | * @param int SQL data type of the parameter |
168 | + * @param string $name |
|
168 | 169 | * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php |
169 | 170 | */ |
170 | 171 | public function bindValue($name, $value, $dataType=null) |
@@ -269,7 +270,7 @@ discard block |
||
269 | 270 | * Executes the SQL statement and returns the value of the first column in the first row of data. |
270 | 271 | * This is a convenient method of {@link query} when only a single scalar |
271 | 272 | * value is needed (e.g. obtaining the count of the records). |
272 | - * @return mixed the value of the first column in the first row of the query result. False is returned if there is no value. |
|
273 | + * @return string the value of the first column in the first row of the query result. False is returned if there is no value. |
|
273 | 274 | * @throws TDbException execution failed |
274 | 275 | */ |
275 | 276 | public function queryScalar() |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | if(!extension_loaded('apc')) |
57 | 57 | throw new TConfigurationException('apccache_extension_required'); |
58 | 58 | |
59 | - if(ini_get('apc.enabled') == false) |
|
59 | + if(ini_get('apc.enabled')==false) |
|
60 | 60 | throw new TConfigurationException('apccache_extension_not_enabled'); |
61 | 61 | |
62 | - if(substr(php_sapi_name(), 0, 3) === 'cli' and ini_get('apc.enable_cli') == false) |
|
62 | + if(substr(php_sapi_name(), 0, 3)==='cli' and ini_get('apc.enable_cli')==false) |
|
63 | 63 | throw new TConfigurationException('apccache_extension_not_enabled_cli'); |
64 | 64 | |
65 | 65 | parent::init($config); |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
86 | 86 | * @return boolean true if the value is successfully stored into cache, false otherwise |
87 | 87 | */ |
88 | - protected function setValue($key,$value,$expire) |
|
88 | + protected function setValue($key, $value, $expire) |
|
89 | 89 | { |
90 | - return apc_store($key,$value,$expire); |
|
90 | + return apc_store($key, $value, $expire); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
100 | 100 | * @return boolean true if the value is successfully stored into cache, false otherwise |
101 | 101 | */ |
102 | - protected function addValue($key,$value,$expire) |
|
102 | + protected function addValue($key, $value, $expire) |
|
103 | 103 | { |
104 | - return apc_add($key,$value,$expire); |
|
104 | + return apc_add($key, $value, $expire); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -104,17 +104,17 @@ discard block |
||
104 | 104 | /** |
105 | 105 | * @var boolean controls the use of a persistent connection. Default to true. |
106 | 106 | */ |
107 | - private $_persistence = true; |
|
107 | + private $_persistence=true; |
|
108 | 108 | /** |
109 | 109 | * @var integer number of buckets to create for this server which in turn control its |
110 | 110 | * probability of it being selected. The probability is relative to the total weight |
111 | 111 | * of all servers. |
112 | 112 | */ |
113 | - private $_weight = 1; |
|
113 | + private $_weight=1; |
|
114 | 114 | |
115 | - private $_timeout = 360; |
|
115 | + private $_timeout=360; |
|
116 | 116 | |
117 | - private $_retryInterval = 15; |
|
117 | + private $_retryInterval=15; |
|
118 | 118 | /** |
119 | 119 | * @var integer Controls the minimum value length before attempting to compress automatically. |
120 | 120 | */ |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | */ |
126 | 126 | private $_minSavings=0.0; |
127 | 127 | |
128 | - private $_status = true; |
|
128 | + private $_status=true; |
|
129 | 129 | |
130 | - private $_failureCallback = null; |
|
130 | + private $_failureCallback=null; |
|
131 | 131 | |
132 | 132 | /** |
133 | 133 | * @var boolean whether to use memcached or memcache as the underlying caching extension. |
@@ -168,26 +168,26 @@ discard block |
||
168 | 168 | if(!extension_loaded('memcached') && $this->_useMemcached) |
169 | 169 | throw new TConfigurationException('memcached_extension_required'); |
170 | 170 | |
171 | - $this->_cache = $this->_useMemcached ? new Memcached : new Memcache; |
|
171 | + $this->_cache=$this->_useMemcached ? new Memcached : new Memcache; |
|
172 | 172 | $this->loadConfig($config); |
173 | 173 | if(count($this->_servers)) |
174 | 174 | { |
175 | 175 | foreach($this->_servers as $server) |
176 | 176 | { |
177 | 177 | Prado::trace('Adding server '.$server['Host'].' from serverlist', 'System.Caching.TMemCache'); |
178 | - if($this->_cache->addServer($server['Host'],$server['Port'],$server['Persistent'], |
|
179 | - $server['Weight'],$server['Timeout'],$server['RetryInterval'])===false) |
|
180 | - throw new TConfigurationException('memcache_connection_failed',$server['Host'],$server['Port']); |
|
178 | + if($this->_cache->addServer($server['Host'], $server['Port'], $server['Persistent'], |
|
179 | + $server['Weight'], $server['Timeout'], $server['RetryInterval'])===false) |
|
180 | + throw new TConfigurationException('memcache_connection_failed', $server['Host'], $server['Port']); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | else |
184 | 184 | { |
185 | 185 | Prado::trace('Adding server '.$this->_host, 'System.Caching.TMemCache'); |
186 | - if($this->_cache->addServer($this->_host,$this->_port)===false) |
|
187 | - throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port); |
|
186 | + if($this->_cache->addServer($this->_host, $this->_port)===false) |
|
187 | + throw new TConfigurationException('memcache_connection_failed', $this->_host, $this->_port); |
|
188 | 188 | } |
189 | 189 | if($this->_threshold!==0) |
190 | - $this->_cache->setCompressThreshold($this->_threshold,$this->_minSavings); |
|
190 | + $this->_cache->setCompressThreshold($this->_threshold, $this->_minSavings); |
|
191 | 191 | $this->_initialized=true; |
192 | 192 | parent::init($config); |
193 | 193 | } |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | throw new TConfigurationException('memcache_serverport_required'); |
211 | 211 | if(!is_numeric($port)) |
212 | 212 | throw new TConfigurationException('memcache_serverport_invalid'); |
213 | - $server = array('Host'=>$host,'Port'=>$port,'Weight'=>1,'Timeout'=>1800,'RetryInterval'=>15,'Persistent'=>true); |
|
214 | - $checks = array( |
|
213 | + $server=array('Host'=>$host, 'Port'=>$port, 'Weight'=>1, 'Timeout'=>1800, 'RetryInterval'=>15, 'Persistent'=>true); |
|
214 | + $checks=array( |
|
215 | 215 | 'Weight'=>'memcache_serverweight_invalid', |
216 | 216 | 'Timeout'=>'memcache_servertimeout_invalid', |
217 | 217 | 'RetryInterval'=>'memcach_serverretryinterval_invalid' |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | else if($value!==null) |
225 | 225 | throw new TConfigurationException($exception); |
226 | 226 | } |
227 | - $server['Persistent']= TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
|
227 | + $server['Persistent']=TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
|
228 | 228 | $this->_servers[]=$server; |
229 | 229 | } |
230 | 230 | } |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
351 | 351 | * @return boolean true if the value is successfully stored into cache, false otherwise |
352 | 352 | */ |
353 | - protected function setValue($key,$value,$expire) |
|
353 | + protected function setValue($key, $value, $expire) |
|
354 | 354 | { |
355 | 355 | if($this->_useMemcached) { |
356 | - return $this->_cache->set($key,$value,$expire); |
|
356 | + return $this->_cache->set($key, $value, $expire); |
|
357 | 357 | } else { |
358 | - return $this->_cache->set($key,$value,0,$expire); |
|
358 | + return $this->_cache->set($key, $value, 0, $expire); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
369 | 369 | * @return boolean true if the value is successfully stored into cache, false otherwise |
370 | 370 | */ |
371 | - protected function addValue($key,$value,$expire) |
|
371 | + protected function addValue($key, $value, $expire) |
|
372 | 372 | { |
373 | 373 | if($this->_useMemcached) { |
374 | - $this->_cache->add($key,$value,$expire); |
|
374 | + $this->_cache->add($key, $value, $expire); |
|
375 | 375 | } else { |
376 | - return $this->_cache->add($key,$value,0,$expire); |
|
376 | + return $this->_cache->add($key, $value, 0, $expire); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 |
@@ -124,8 +124,7 @@ |
||
124 | 124 | if (!@mysql_select_db($dsninfo['database'], $conn)) |
125 | 125 | throw new Exception('Error in connecting database, dns:'. |
126 | 126 | $dsninfo); |
127 | - } |
|
128 | - else |
|
127 | + } else |
|
129 | 128 | throw new Exception('Please provide a database for message'. |
130 | 129 | ' translation.'); |
131 | 130 | return $conn; |
@@ -111,30 +111,30 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * @var boolean controls the use of a persistent connection. Default to true. |
113 | 113 | */ |
114 | - private $_persistence = true; |
|
115 | - /** |
|
116 | - * @var integer number of buckets to create for this server which in turn control its |
|
117 | - * probability of it being selected. The probability is relative to the total weight |
|
118 | - * of all servers. |
|
119 | - */ |
|
120 | - private $_weight = 1; |
|
114 | + private $_persistence = true; |
|
115 | + /** |
|
116 | + * @var integer number of buckets to create for this server which in turn control its |
|
117 | + * probability of it being selected. The probability is relative to the total weight |
|
118 | + * of all servers. |
|
119 | + */ |
|
120 | + private $_weight = 1; |
|
121 | 121 | |
122 | - private $_timeout = 360; |
|
122 | + private $_timeout = 360; |
|
123 | 123 | |
124 | - private $_retryInterval = 15; |
|
124 | + private $_retryInterval = 15; |
|
125 | 125 | /** |
126 | - * @var integer Controls the minimum value length before attempting to compress automatically. |
|
127 | - */ |
|
128 | - private $_threshold=0; |
|
126 | + * @var integer Controls the minimum value length before attempting to compress automatically. |
|
127 | + */ |
|
128 | + private $_threshold=0; |
|
129 | 129 | |
130 | 130 | /** |
131 | - * @var float Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings. |
|
132 | - */ |
|
133 | - private $_minSavings=0.0; |
|
131 | + * @var float Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings. |
|
132 | + */ |
|
133 | + private $_minSavings=0.0; |
|
134 | 134 | |
135 | - private $_status = true; |
|
135 | + private $_status = true; |
|
136 | 136 | |
137 | - private $_failureCallback = null; |
|
137 | + private $_failureCallback = null; |
|
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @var boolean whether to use memcached or memcache as the underlying caching extension. |
@@ -178,63 +178,63 @@ discard block |
||
178 | 178 | $this->_cache = $this->_useMemcached ? new Memcached : new Memcache; |
179 | 179 | $this->loadConfig($config); |
180 | 180 | if(count($this->_servers)) |
181 | - { |
|
182 | - foreach($this->_servers as $server) |
|
183 | - { |
|
184 | - Prado::trace('Adding server '.$server['Host'].' from serverlist', '\Prado\Caching\TMemCache'); |
|
185 | - if($this->_cache->addServer($server['Host'],$server['Port'],$server['Persistent'], |
|
186 | - $server['Weight'],$server['Timeout'],$server['RetryInterval'])===false) |
|
187 | - throw new TConfigurationException('memcache_connection_failed',$server['Host'],$server['Port']); |
|
188 | - } |
|
189 | - } |
|
190 | - else |
|
191 | - { |
|
192 | - Prado::trace('Adding server '.$this->_host, '\Prado\Caching\TMemCache'); |
|
193 | - if($this->_cache->addServer($this->_host,$this->_port)===false) |
|
194 | - throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port); |
|
195 | - } |
|
181 | + { |
|
182 | + foreach($this->_servers as $server) |
|
183 | + { |
|
184 | + Prado::trace('Adding server '.$server['Host'].' from serverlist', '\Prado\Caching\TMemCache'); |
|
185 | + if($this->_cache->addServer($server['Host'],$server['Port'],$server['Persistent'], |
|
186 | + $server['Weight'],$server['Timeout'],$server['RetryInterval'])===false) |
|
187 | + throw new TConfigurationException('memcache_connection_failed',$server['Host'],$server['Port']); |
|
188 | + } |
|
189 | + } |
|
190 | + else |
|
191 | + { |
|
192 | + Prado::trace('Adding server '.$this->_host, '\Prado\Caching\TMemCache'); |
|
193 | + if($this->_cache->addServer($this->_host,$this->_port)===false) |
|
194 | + throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port); |
|
195 | + } |
|
196 | 196 | if($this->_threshold!==0) |
197 | - $this->_cache->setCompressThreshold($this->_threshold,$this->_minSavings); |
|
197 | + $this->_cache->setCompressThreshold($this->_threshold,$this->_minSavings); |
|
198 | 198 | $this->_initialized=true; |
199 | 199 | parent::init($config); |
200 | 200 | } |
201 | 201 | |
202 | - /** |
|
202 | + /** |
|
203 | 203 | * Loads configuration from an XML element |
204 | 204 | * @param TXmlElement configuration node |
205 | 205 | * @throws TConfigurationException if log route class or type is not specified |
206 | 206 | */ |
207 | 207 | private function loadConfig($xml) |
208 | 208 | { |
209 | - if($xml instanceof TXmlElement) |
|
209 | + if($xml instanceof TXmlElement) |
|
210 | 210 | { |
211 | - foreach($xml->getElementsByTagName('server') as $serverConfig) |
|
212 | - { |
|
213 | - $properties=$serverConfig->getAttributes(); |
|
214 | - if(($host=$properties->remove('Host'))===null) |
|
215 | - throw new TConfigurationException('memcache_serverhost_required'); |
|
216 | - if(($port=$properties->remove('Port'))===null) |
|
217 | - throw new TConfigurationException('memcache_serverport_required'); |
|
218 | - if(!is_numeric($port)) |
|
219 | - throw new TConfigurationException('memcache_serverport_invalid'); |
|
220 | - $server = array('Host'=>$host,'Port'=>$port,'Weight'=>1,'Timeout'=>1800,'RetryInterval'=>15,'Persistent'=>true); |
|
221 | - $checks = array( |
|
222 | - 'Weight'=>'memcache_serverweight_invalid', |
|
223 | - 'Timeout'=>'memcache_servertimeout_invalid', |
|
224 | - 'RetryInterval'=>'memcach_serverretryinterval_invalid' |
|
225 | - ); |
|
226 | - foreach($checks as $property=>$exception) |
|
227 | - { |
|
228 | - $value=$properties->remove($property); |
|
229 | - if($value!==null && is_numeric($value)) |
|
230 | - $server[$property]=$value; |
|
231 | - else if($value!==null) |
|
232 | - throw new TConfigurationException($exception); |
|
233 | - } |
|
234 | - $server['Persistent']= TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
|
235 | - $this->_servers[]=$server; |
|
236 | - } |
|
237 | - } |
|
211 | + foreach($xml->getElementsByTagName('server') as $serverConfig) |
|
212 | + { |
|
213 | + $properties=$serverConfig->getAttributes(); |
|
214 | + if(($host=$properties->remove('Host'))===null) |
|
215 | + throw new TConfigurationException('memcache_serverhost_required'); |
|
216 | + if(($port=$properties->remove('Port'))===null) |
|
217 | + throw new TConfigurationException('memcache_serverport_required'); |
|
218 | + if(!is_numeric($port)) |
|
219 | + throw new TConfigurationException('memcache_serverport_invalid'); |
|
220 | + $server = array('Host'=>$host,'Port'=>$port,'Weight'=>1,'Timeout'=>1800,'RetryInterval'=>15,'Persistent'=>true); |
|
221 | + $checks = array( |
|
222 | + 'Weight'=>'memcache_serverweight_invalid', |
|
223 | + 'Timeout'=>'memcache_servertimeout_invalid', |
|
224 | + 'RetryInterval'=>'memcach_serverretryinterval_invalid' |
|
225 | + ); |
|
226 | + foreach($checks as $property=>$exception) |
|
227 | + { |
|
228 | + $value=$properties->remove($property); |
|
229 | + if($value!==null && is_numeric($value)) |
|
230 | + $server[$property]=$value; |
|
231 | + else if($value!==null) |
|
232 | + throw new TConfigurationException($exception); |
|
233 | + } |
|
234 | + $server['Persistent']= TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
|
235 | + $this->_servers[]=$server; |
|
236 | + } |
|
237 | + } |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | if(!function_exists('xcache_isset')) |
53 | 53 | throw new TConfigurationException('xcache_extension_required'); |
54 | 54 | |
55 | - $enabled = (int)ini_get('xcache.cacher') !== 0; |
|
56 | - $var_size = (int)ini_get('xcache.var_size'); |
|
55 | + $enabled=(int) ini_get('xcache.cacher')!==0; |
|
56 | + $var_size=(int) ini_get('xcache.var_size'); |
|
57 | 57 | |
58 | 58 | if(!($enabled && $var_size > 0)) |
59 | 59 | throw new TConfigurationException('xcache_extension_not_enabled'); |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
82 | 82 | * @return boolean true if the value is successfully stored into cache, false otherwise |
83 | 83 | */ |
84 | - protected function setValue($key,$value,$expire) |
|
84 | + protected function setValue($key, $value, $expire) |
|
85 | 85 | { |
86 | - return xcache_set($key,$value,$expire); |
|
86 | + return xcache_set($key, $value, $expire); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
96 | 96 | * @return boolean true if the value is successfully stored into cache, false otherwise |
97 | 97 | */ |
98 | - protected function addValue($key,$value,$expire) |
|
98 | + protected function addValue($key, $value, $expire) |
|
99 | 99 | { |
100 | - return !xcache_isset($key) ? $this->setValue($key,$value,$expire) : false; |
|
100 | + return !xcache_isset($key) ? $this->setValue($key, $value, $expire) : false; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function flush() |
119 | 119 | { |
120 | - for($i=0, $max=xcache_count(XC_TYPE_VAR); $i<$max; $i++) |
|
120 | + for($i=0, $max=xcache_count(XC_TYPE_VAR); $i < $max; $i++) |
|
121 | 121 | { |
122 | 122 | if(xcache_clear_cache(XC_TYPE_VAR, $i)===false) |
123 | 123 | return false; |
@@ -181,22 +181,18 @@ discard block |
||
181 | 181 | $this->_currentPageIndex=$pageIndex; |
182 | 182 | $this->onPageIndexChanged(new TPagedListPageChangedEventParameter($oldPage)); |
183 | 183 | return $pageIndex; |
184 | - } |
|
185 | - else |
|
184 | + } else |
|
186 | 185 | return false; |
187 | - } |
|
188 | - else |
|
186 | + } else |
|
189 | 187 | return false; |
190 | - } |
|
191 | - else |
|
188 | + } else |
|
192 | 189 | { |
193 | 190 | if($pageIndex>=0 && $pageIndex<$this->getPageCount()) |
194 | 191 | { |
195 | 192 | $this->_currentPageIndex=$pageIndex; |
196 | 193 | $this->onPageIndexChanged(null); |
197 | 194 | return $pageIndex; |
198 | - } |
|
199 | - else |
|
195 | + } else |
|
200 | 196 | return false; |
201 | 197 | } |
202 | 198 | } |
@@ -248,8 +244,7 @@ discard block |
||
248 | 244 | return (int)(($this->_virtualCount+$this->_pageSize-1)/$this->_pageSize); |
249 | 245 | else |
250 | 246 | return -1; |
251 | - } |
|
252 | - else |
|
247 | + } else |
|
253 | 248 | return (int)((parent::getCount()+$this->_pageSize-1)/$this->_pageSize); |
254 | 249 | } |
255 | 250 |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | * @param array|Iterator the initial data. Default is null, meaning no initialization. |
82 | 82 | * @param boolean whether the list is read-only. Always true for paged list. |
83 | 83 | */ |
84 | - public function __construct($data=null,$readOnly=false) |
|
84 | + public function __construct($data=null, $readOnly=false) |
|
85 | 85 | { |
86 | - parent::__construct($data,true); |
|
86 | + parent::__construct($data, true); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function setPageSize($value) |
117 | 117 | { |
118 | - if(($value=TPropertyValue::ensureInteger($value))>0) |
|
118 | + if(($value=TPropertyValue::ensureInteger($value)) > 0) |
|
119 | 119 | $this->_pageSize=$value; |
120 | 120 | else |
121 | 121 | throw new TInvalidDataValueException('pagedlist_pagesize_invalid'); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function onPageIndexChanged($param) |
148 | 148 | { |
149 | - $this->raiseEvent('OnPageIndexChanged',$this,$param); |
|
149 | + $this->raiseEvent('OnPageIndexChanged', $this, $param); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function onFetchData($param) |
160 | 160 | { |
161 | - $this->raiseEvent('OnFetchData',$this,$param); |
|
161 | + $this->raiseEvent('OnFetchData', $this, $param); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | return $pageIndex; |
173 | 173 | if($this->_customPaging) |
174 | 174 | { |
175 | - if($pageIndex>=0 && ($this->_virtualCount<0 || $pageIndex<$this->getPageCount())) |
|
175 | + if($pageIndex >= 0 && ($this->_virtualCount < 0 || $pageIndex < $this->getPageCount())) |
|
176 | 176 | { |
177 | - $param=new TPagedListFetchDataEventParameter($pageIndex,$this->_pageSize*$pageIndex,$this->_pageSize); |
|
177 | + $param=new TPagedListFetchDataEventParameter($pageIndex, $this->_pageSize * $pageIndex, $this->_pageSize); |
|
178 | 178 | $this->onFetchData($param); |
179 | 179 | if(($data=$param->getData())!==null) |
180 | 180 | { |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | } |
195 | 195 | else |
196 | 196 | { |
197 | - if($pageIndex>=0 && $pageIndex<$this->getPageCount()) |
|
197 | + if($pageIndex >= 0 && $pageIndex < $this->getPageCount()) |
|
198 | 198 | { |
199 | 199 | $this->_currentPageIndex=$pageIndex; |
200 | 200 | $this->onPageIndexChanged(null); |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | */ |
212 | 212 | public function nextPage() |
213 | 213 | { |
214 | - return $this->gotoPage($this->_currentPageIndex+1); |
|
214 | + return $this->gotoPage($this->_currentPageIndex + 1); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function previousPage() |
222 | 222 | { |
223 | - return $this->gotoPage($this->_currentPageIndex-1); |
|
223 | + return $this->gotoPage($this->_currentPageIndex - 1); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function setVirtualCount($value) |
238 | 238 | { |
239 | - if(($value=TPropertyValue::ensureInteger($value))<0) |
|
239 | + if(($value=TPropertyValue::ensureInteger($value)) < 0) |
|
240 | 240 | $value=-1; |
241 | 241 | $this->_virtualCount=$value; |
242 | 242 | } |
@@ -248,13 +248,13 @@ discard block |
||
248 | 248 | { |
249 | 249 | if($this->_customPaging) |
250 | 250 | { |
251 | - if($this->_virtualCount>=0) |
|
252 | - return (int)(($this->_virtualCount+$this->_pageSize-1)/$this->_pageSize); |
|
251 | + if($this->_virtualCount >= 0) |
|
252 | + return (int) (($this->_virtualCount + $this->_pageSize - 1) / $this->_pageSize); |
|
253 | 253 | else |
254 | 254 | return -1; |
255 | 255 | } |
256 | 256 | else |
257 | - return (int)((parent::getCount()+$this->_pageSize-1)/$this->_pageSize); |
|
257 | + return (int) ((parent::getCount() + $this->_pageSize - 1) / $this->_pageSize); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | */ |
271 | 271 | public function getIsLastPage() |
272 | 272 | { |
273 | - return $this->_currentPageIndex===$this->getPageCount()-1; |
|
273 | + return $this->_currentPageIndex===$this->getPageCount() - 1; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | return parent::getCount(); |
283 | 283 | else |
284 | 284 | { |
285 | - if($this->_currentPageIndex===$this->getPageCount()-1) |
|
286 | - return parent::getCount()-$this->_pageSize*$this->_currentPageIndex; |
|
285 | + if($this->_currentPageIndex===$this->getPageCount() - 1) |
|
286 | + return parent::getCount() - $this->_pageSize * $this->_currentPageIndex; |
|
287 | 287 | else |
288 | 288 | return $this->_pageSize; |
289 | 289 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | if($this->_customPaging) |
316 | 316 | return parent::itemAt($index); |
317 | 317 | else |
318 | - return parent::itemAt($this->_pageSize*$this->_currentPageIndex+$index); |
|
318 | + return parent::itemAt($this->_pageSize * $this->_currentPageIndex + $index); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | public function indexOf($item) |
326 | 326 | { |
327 | 327 | $c=$this->getCount(); |
328 | - for($i=0;$i<$c;++$i) |
|
328 | + for($i=0; $i < $c; ++$i) |
|
329 | 329 | if($this->itemAt($i)===$item) |
330 | 330 | return $i; |
331 | 331 | return -1; |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public function offsetExists($offset) |
341 | 341 | { |
342 | - return ($offset>=0 && $offset<$this->getCount()); |
|
342 | + return ($offset >= 0 && $offset < $this->getCount()); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | { |
362 | 362 | $c=$this->getCount(); |
363 | 363 | $array=array(); |
364 | - for($i=0;$i<$c;++$i) |
|
364 | + for($i=0; $i < $c; ++$i) |
|
365 | 365 | $array[$i]=$this->itemAt($i); |
366 | 366 | return $array; |
367 | 367 | } |
@@ -96,6 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @param boolean whether to allow custom paging |
99 | + * @param boolean $value |
|
99 | 100 | */ |
100 | 101 | public function setCustomPaging($value) |
101 | 102 | { |
@@ -143,6 +144,7 @@ discard block |
||
143 | 144 | * Raises <b>OnPageIndexChanged</b> event. |
144 | 145 | * This event is raised each time when the list changes to a different page. |
145 | 146 | * @param TPagedListPageChangedEventParameter event parameter |
147 | + * @param TPagedListPageChangedEventParameter|null $param |
|
146 | 148 | */ |
147 | 149 | public function onPageIndexChanged($param) |
148 | 150 | { |
@@ -155,6 +157,7 @@ discard block |
||
155 | 157 | * and needs the new page of data. This event can only be raised when |
156 | 158 | * {@link setCustomPaging CustomPaging} is true. |
157 | 159 | * @param TPagedListFetchDataEventParameter event parameter |
160 | + * @param TPagedListFetchDataEventParameter $param |
|
158 | 161 | */ |
159 | 162 | public function onFetchData($param) |
160 | 163 | { |
@@ -290,7 +293,7 @@ discard block |
||
290 | 293 | } |
291 | 294 | |
292 | 295 | /** |
293 | - * @return Iterator iterator |
|
296 | + * @return \ArrayIterator iterator |
|
294 | 297 | */ |
295 | 298 | public function getIterator() |
296 | 299 | { |
@@ -163,11 +163,9 @@ discard block |
||
163 | 163 | $value=$this->_d[$key]; |
164 | 164 | unset($this->_d[$key]); |
165 | 165 | return $value; |
166 | - } |
|
167 | - else |
|
166 | + } else |
|
168 | 167 | return null; |
169 | - } |
|
170 | - else |
|
168 | + } else |
|
171 | 169 | throw new TInvalidOperationException('map_readonly',get_class($this)); |
172 | 170 | } |
173 | 171 | |
@@ -211,8 +209,7 @@ discard block |
||
211 | 209 | $this->clear(); |
212 | 210 | foreach($data as $key=>$value) |
213 | 211 | $this->add($key,$value); |
214 | - } |
|
215 | - else if($data!==null) |
|
212 | + } else if($data!==null) |
|
216 | 213 | throw new TInvalidDataTypeException('map_data_not_iterable'); |
217 | 214 | } |
218 | 215 | |
@@ -228,8 +225,7 @@ discard block |
||
228 | 225 | { |
229 | 226 | foreach($data as $key=>$value) |
230 | 227 | $this->add($key,$value); |
231 | - } |
|
232 | - else if($data!==null) |
|
228 | + } else if($data!==null) |
|
233 | 229 | throw new TInvalidDataTypeException('map_data_not_iterable'); |
234 | 230 | } |
235 | 231 |
@@ -86,6 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | /** |
88 | 88 | * @param boolean whether this list is read-only or not |
89 | + * @param boolean $value |
|
89 | 90 | */ |
90 | 91 | protected function setReadOnly($value) |
91 | 92 | { |
@@ -95,7 +96,7 @@ discard block |
||
95 | 96 | /** |
96 | 97 | * Returns an iterator for traversing the items in the list. |
97 | 98 | * This method is required by the interface \IteratorAggregate. |
98 | - * @return Iterator an iterator for traversing the items in the list. |
|
99 | + * @return \ArrayIterator an iterator for traversing the items in the list. |
|
99 | 100 | */ |
100 | 101 | public function getIterator() |
101 | 102 | { |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | protected function _getZappableSleepProps(&$exprops) |
57 | 57 | { |
58 | 58 | parent::_getZappableSleepProps($exprops); |
59 | - if ($this->_d===array()) |
|
60 | - $exprops[] = "\0TMap\0_d"; |
|
61 | - if ($this->_r===false) |
|
62 | - $exprops[] = "\0TMap\0_r"; |
|
59 | + if($this->_d===array()) |
|
60 | + $exprops[]="\0TMap\0_d"; |
|
61 | + if($this->_r===false) |
|
62 | + $exprops[]="\0TMap\0_r"; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param boolean whether the list is read-only |
70 | 70 | * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator. |
71 | 71 | */ |
72 | - public function __construct($data=null,$readOnly=false) |
|
72 | + public function __construct($data=null, $readOnly=false) |
|
73 | 73 | { |
74 | 74 | if($data!==null) |
75 | 75 | $this->copyFrom($data); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function getIterator() |
101 | 101 | { |
102 | - return new \ArrayIterator( $this->_d ); |
|
102 | + return new \ArrayIterator($this->_d); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | * @param mixed value |
147 | 147 | * @throws TInvalidOperationException if the map is read-only |
148 | 148 | */ |
149 | - public function add($key,$value) |
|
149 | + public function add($key, $value) |
|
150 | 150 | { |
151 | 151 | if(!$this->_r) |
152 | 152 | $this->_d[$key]=$value; |
153 | 153 | else |
154 | - throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
154 | + throw new TInvalidOperationException('map_readonly', get_class($this)); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | { |
165 | 165 | if(!$this->_r) |
166 | 166 | { |
167 | - if(isset($this->_d[$key]) || array_key_exists($key,$this->_d)) |
|
167 | + if(isset($this->_d[$key]) || array_key_exists($key, $this->_d)) |
|
168 | 168 | { |
169 | 169 | $value=$this->_d[$key]; |
170 | 170 | unset($this->_d[$key]); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | return null; |
175 | 175 | } |
176 | 176 | else |
177 | - throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
177 | + throw new TInvalidOperationException('map_readonly', get_class($this)); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function contains($key) |
194 | 194 | { |
195 | - return isset($this->_d[$key]) || array_key_exists($key,$this->_d); |
|
195 | + return isset($this->_d[$key]) || array_key_exists($key, $this->_d); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | { |
214 | 214 | if(is_array($data) || $data instanceof Traversable) |
215 | 215 | { |
216 | - if($this->getCount()>0) |
|
216 | + if($this->getCount() > 0) |
|
217 | 217 | $this->clear(); |
218 | 218 | foreach($data as $key=>$value) |
219 | - $this->add($key,$value); |
|
219 | + $this->add($key, $value); |
|
220 | 220 | } |
221 | 221 | else if($data!==null) |
222 | 222 | throw new TInvalidDataTypeException('map_data_not_iterable'); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | if(is_array($data) || $data instanceof Traversable) |
234 | 234 | { |
235 | 235 | foreach($data as $key=>$value) |
236 | - $this->add($key,$value); |
|
236 | + $this->add($key, $value); |
|
237 | 237 | } |
238 | 238 | else if($data!==null) |
239 | 239 | throw new TInvalidDataTypeException('map_data_not_iterable'); |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | * @param integer the offset to set element |
268 | 268 | * @param mixed the element value |
269 | 269 | */ |
270 | - public function offsetSet($offset,$item) |
|
270 | + public function offsetSet($offset, $item) |
|
271 | 271 | { |
272 | - $this->add($offset,$item); |
|
272 | + $this->add($offset, $item); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -155,11 +155,9 @@ discard block |
||
155 | 155 | { |
156 | 156 | array_splice($this->_d,$index,0,array($item)); |
157 | 157 | $this->_c++; |
158 | - } |
|
159 | - else |
|
158 | + } else |
|
160 | 159 | throw new TInvalidDataValueException('list_index_invalid',$index); |
161 | - } |
|
162 | - else |
|
160 | + } else |
|
163 | 161 | throw new TInvalidOperationException('list_readonly',get_class($this)); |
164 | 162 | } |
165 | 163 | |
@@ -180,11 +178,9 @@ discard block |
||
180 | 178 | { |
181 | 179 | $this->removeAt($index); |
182 | 180 | return $index; |
183 | - } |
|
184 | - else |
|
181 | + } else |
|
185 | 182 | throw new TInvalidDataValueException('list_item_inexistent'); |
186 | - } |
|
187 | - else |
|
183 | + } else |
|
188 | 184 | throw new TInvalidOperationException('list_readonly',get_class($this)); |
189 | 185 | } |
190 | 186 | |
@@ -210,11 +206,9 @@ discard block |
||
210 | 206 | array_splice($this->_d,$index,1); |
211 | 207 | return $item; |
212 | 208 | } |
213 | - } |
|
214 | - else |
|
209 | + } else |
|
215 | 210 | throw new TInvalidDataValueException('list_index_invalid',$index); |
216 | - } |
|
217 | - else |
|
211 | + } else |
|
218 | 212 | throw new TInvalidOperationException('list_readonly',get_class($this)); |
219 | 213 | } |
220 | 214 | |
@@ -268,8 +262,7 @@ discard block |
||
268 | 262 | $this->insertAt($index, $item); |
269 | 263 | |
270 | 264 | return $index; |
271 | - } |
|
272 | - else |
|
265 | + } else |
|
273 | 266 | throw new TInvalidOperationException('list_readonly',get_class($this)); |
274 | 267 | } |
275 | 268 | |
@@ -292,8 +285,7 @@ discard block |
||
292 | 285 | $this->insertAt($index + 1, $item); |
293 | 286 | |
294 | 287 | return $index + 1; |
295 | - } |
|
296 | - else |
|
288 | + } else |
|
297 | 289 | throw new TInvalidOperationException('list_readonly',get_class($this)); |
298 | 290 | } |
299 | 291 | |
@@ -319,8 +311,7 @@ discard block |
||
319 | 311 | $this->clear(); |
320 | 312 | foreach($data as $item) |
321 | 313 | $this->add($item); |
322 | - } |
|
323 | - else if($data!==null) |
|
314 | + } else if($data!==null) |
|
324 | 315 | throw new TInvalidDataTypeException('list_data_not_iterable'); |
325 | 316 | } |
326 | 317 | |
@@ -336,8 +327,7 @@ discard block |
||
336 | 327 | { |
337 | 328 | foreach($data as $item) |
338 | 329 | $this->add($item); |
339 | - } |
|
340 | - else if($data!==null) |
|
330 | + } else if($data!==null) |
|
341 | 331 | throw new TInvalidDataTypeException('list_data_not_iterable'); |
342 | 332 | } |
343 | 333 |
@@ -81,6 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @param boolean whether this list is read-only or not |
84 | + * @param boolean $value |
|
84 | 85 | */ |
85 | 86 | protected function setReadOnly($value) |
86 | 87 | { |
@@ -90,7 +91,7 @@ discard block |
||
90 | 91 | /** |
91 | 92 | * Returns an iterator for traversing the items in the list. |
92 | 93 | * This method is required by the interface \IteratorAggregate. |
93 | - * @return Iterator an iterator for traversing the items in the list. |
|
94 | + * @return \ArrayIterator an iterator for traversing the items in the list. |
|
94 | 95 | */ |
95 | 96 | public function getIterator() |
96 | 97 | { |
@@ -283,7 +284,7 @@ discard block |
||
283 | 284 | * Finds the base item. If found, the item is inserted after it. |
284 | 285 | * @param mixed the base item which comes before the second parameter when added to the list |
285 | 286 | * @param mixed the item |
286 | - * @return int the index where the item is inserted |
|
287 | + * @return double the index where the item is inserted |
|
287 | 288 | * @throws TInvalidDataValueException if the base item is not within this list |
288 | 289 | * @throws TInvalidOperationException if the list is read-only |
289 | 290 | * @since 3.2a |
@@ -334,6 +335,7 @@ discard block |
||
334 | 335 | * Merges iterable data into the map. |
335 | 336 | * New data will be appended to the end of the existing data. |
336 | 337 | * @param mixed the data to be merged with, must be an array or object implementing Traversable |
338 | + * @param \Prado\Web\UI\WebControls\TDataGridColumnCollection|null $data |
|
337 | 339 | * @throws TInvalidDataTypeException If data is neither an array nor an iterator. |
338 | 340 | */ |
339 | 341 | public function mergeWith($data) |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param boolean whether the list is read-only |
65 | 65 | * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator. |
66 | 66 | */ |
67 | - public function __construct($data=null,$readOnly=false) |
|
67 | + public function __construct($data=null, $readOnly=false) |
|
68 | 68 | { |
69 | 69 | if($data!==null) |
70 | 70 | $this->copyFrom($data); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function getIterator() |
96 | 96 | { |
97 | - return new \ArrayIterator( $this->_d ); |
|
97 | + return new \ArrayIterator($this->_d); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function itemAt($index) |
126 | 126 | { |
127 | - if($index>=0 && $index<$this->_c) |
|
127 | + if($index >= 0 && $index < $this->_c) |
|
128 | 128 | return $this->_d[$index]; |
129 | 129 | else |
130 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
130 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function add($item) |
140 | 140 | { |
141 | - $this->insertAt($this->_c,$item); |
|
142 | - return $this->_c-1; |
|
141 | + $this->insertAt($this->_c, $item); |
|
142 | + return $this->_c - 1; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -151,22 +151,22 @@ discard block |
||
151 | 151 | * @throws TInvalidDataValueException If the index specified exceeds the bound |
152 | 152 | * @throws TInvalidOperationException if the list is read-only |
153 | 153 | */ |
154 | - public function insertAt($index,$item) |
|
154 | + public function insertAt($index, $item) |
|
155 | 155 | { |
156 | 156 | if(!$this->_r) |
157 | 157 | { |
158 | 158 | if($index===$this->_c) |
159 | 159 | $this->_d[$this->_c++]=$item; |
160 | - else if($index>=0 && $index<$this->_c) |
|
160 | + else if($index >= 0 && $index < $this->_c) |
|
161 | 161 | { |
162 | - array_splice($this->_d,$index,0,array($item)); |
|
162 | + array_splice($this->_d, $index, 0, array($item)); |
|
163 | 163 | $this->_c++; |
164 | 164 | } |
165 | 165 | else |
166 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
166 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
167 | 167 | } |
168 | 168 | else |
169 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
169 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | { |
183 | 183 | if(!$this->_r) |
184 | 184 | { |
185 | - if(($index=$this->indexOf($item))>=0) |
|
185 | + if(($index=$this->indexOf($item)) >= 0) |
|
186 | 186 | { |
187 | 187 | $this->removeAt($index); |
188 | 188 | return $index; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | throw new TInvalidDataValueException('list_item_inexistent'); |
192 | 192 | } |
193 | 193 | else |
194 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
194 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | { |
206 | 206 | if(!$this->_r) |
207 | 207 | { |
208 | - if($index>=0 && $index<$this->_c) |
|
208 | + if($index >= 0 && $index < $this->_c) |
|
209 | 209 | { |
210 | 210 | $this->_c--; |
211 | 211 | if($index===$this->_c) |
@@ -213,15 +213,15 @@ discard block |
||
213 | 213 | else |
214 | 214 | { |
215 | 215 | $item=$this->_d[$index]; |
216 | - array_splice($this->_d,$index,1); |
|
216 | + array_splice($this->_d, $index, 1); |
|
217 | 217 | return $item; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | else |
221 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
221 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
222 | 222 | } |
223 | 223 | else |
224 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
224 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function clear() |
232 | 232 | { |
233 | - for($i=$this->_c-1;$i>=0;--$i) |
|
233 | + for($i=$this->_c - 1; $i >= 0; --$i) |
|
234 | 234 | $this->removeAt($i); |
235 | 235 | } |
236 | 236 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function contains($item) |
242 | 242 | { |
243 | - return $this->indexOf($item)>=0; |
|
243 | + return $this->indexOf($item) >= 0; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | */ |
250 | 250 | public function indexOf($item) |
251 | 251 | { |
252 | - if(($index=array_search($item,$this->_d,true))===false) |
|
252 | + if(($index=array_search($item, $this->_d, true))===false) |
|
253 | 253 | return -1; |
254 | 254 | else |
255 | 255 | return $index; |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | { |
269 | 269 | if(!$this->_r) |
270 | 270 | { |
271 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
271 | + if(($index=$this->indexOf($baseitem))==-1) |
|
272 | 272 | throw new TInvalidDataValueException('list_item_inexistent'); |
273 | 273 | |
274 | 274 | $this->insertAt($index, $item); |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | return $index; |
277 | 277 | } |
278 | 278 | else |
279 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
279 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | { |
293 | 293 | if(!$this->_r) |
294 | 294 | { |
295 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
295 | + if(($index=$this->indexOf($baseitem))==-1) |
|
296 | 296 | throw new TInvalidDataValueException('list_item_inexistent'); |
297 | 297 | |
298 | 298 | $this->insertAt($index + 1, $item); |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | return $index + 1; |
301 | 301 | } |
302 | 302 | else |
303 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
303 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | { |
322 | 322 | if(is_array($data) || ($data instanceof \Traversable)) |
323 | 323 | { |
324 | - if($this->_c>0) |
|
324 | + if($this->_c > 0) |
|
325 | 325 | $this->clear(); |
326 | 326 | foreach($data as $item) |
327 | 327 | $this->add($item); |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | */ |
356 | 356 | public function offsetExists($offset) |
357 | 357 | { |
358 | - return ($offset>=0 && $offset<$this->_c); |
|
358 | + return ($offset >= 0 && $offset < $this->_c); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -376,14 +376,14 @@ discard block |
||
376 | 376 | * @param integer the offset to set item |
377 | 377 | * @param mixed the item value |
378 | 378 | */ |
379 | - public function offsetSet($offset,$item) |
|
379 | + public function offsetSet($offset, $item) |
|
380 | 380 | { |
381 | 381 | if($offset===null || $offset===$this->_c) |
382 | - $this->insertAt($this->_c,$item); |
|
382 | + $this->insertAt($this->_c, $item); |
|
383 | 383 | else |
384 | 384 | { |
385 | 385 | $this->removeAt($offset); |
386 | - $this->insertAt($offset,$item); |
|
386 | + $this->insertAt($offset, $item); |
|
387 | 387 | } |
388 | 388 | } |
389 | 389 |