@@ -11,10 +11,12 @@ discard block |
||
| 11 | 11 | * Do not modify this file manually. |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if(!defined('PRADO_DIR')) |
|
| 14 | +if(!defined('PRADO_DIR')) { |
|
| 15 | 15 | define('PRADO_DIR',dirname(__FILE__)); |
| 16 | -if(!defined('PRADO_CHMOD')) |
|
| 16 | +} |
|
| 17 | +if(!defined('PRADO_CHMOD')) { |
|
| 17 | 18 | define('PRADO_CHMOD',0777); |
| 19 | +} |
|
| 18 | 20 | class PradoBase |
| 19 | 21 | { |
| 20 | 22 | const CLASS_FILE_EXT='.php'; |
@@ -36,8 +38,9 @@ discard block |
||
| 36 | 38 | public static function autoload($className) |
| 37 | 39 | { |
| 38 | 40 | include_once($className.self::CLASS_FILE_EXT); |
| 39 | - if(!class_exists($className,false) && !interface_exists($className,false)) |
|
| 40 | - self::fatalError("Class file for '$className' cannot be found."); |
|
| 41 | + if(!class_exists($className,false) && !interface_exists($className,false)) { |
|
| 42 | + self::fatalError("Class file for '$className' cannot be found."); |
|
| 43 | + } |
|
| 41 | 44 | } |
| 42 | 45 | public static function poweredByPrado($logoType=0) |
| 43 | 46 | { |
@@ -46,15 +49,16 @@ discard block |
||
| 46 | 49 | { |
| 47 | 50 | $am=self::$_application->getAssetManager(); |
| 48 | 51 | $url=$am->publishFilePath(self::getPathOfNamespace('System.'.$logoName,'.gif')); |
| 52 | + } else { |
|
| 53 | + $url='http://pradosoft.github.io/docs/'.$logoName.'.gif'; |
|
| 49 | 54 | } |
| 50 | - else |
|
| 51 | - $url='http://pradosoft.github.io/docs/'.$logoName.'.gif'; |
|
| 52 | 55 | return '<a title="Powered by PRADO" href="https://github.com/pradosoft/prado" target="_blank"><img src="'.$url.'" style="border-width:0px;" alt="Powered by PRADO" /></a>'; |
| 53 | 56 | } |
| 54 | 57 | public static function phpErrorHandler($errno,$errstr,$errfile,$errline) |
| 55 | 58 | { |
| 56 | - if(error_reporting() & $errno) |
|
| 57 | - throw new TPhpErrorException($errno,$errstr,$errfile,$errline); |
|
| 59 | + if(error_reporting() & $errno) { |
|
| 60 | + throw new TPhpErrorException($errno,$errstr,$errfile,$errline); |
|
| 61 | + } |
|
| 58 | 62 | } |
| 59 | 63 | public static function phpFatalErrorHandler() |
| 60 | 64 | { |
@@ -71,8 +75,7 @@ discard block |
||
| 71 | 75 | if(self::$_application!==null && ($errorHandler=self::$_application->getErrorHandler())!==null) |
| 72 | 76 | { |
| 73 | 77 | $errorHandler->handleError(null,$exception); |
| 74 | - } |
|
| 75 | - else |
|
| 78 | + } else |
|
| 76 | 79 | { |
| 77 | 80 | echo $exception; |
| 78 | 81 | } |
@@ -80,8 +83,9 @@ discard block |
||
| 80 | 83 | } |
| 81 | 84 | public static function setApplication($application) |
| 82 | 85 | { |
| 83 | - if(self::$_application!==null && !defined('PRADO_TEST_RUN')) |
|
| 84 | - throw new TInvalidOperationException('prado_application_singleton_required'); |
|
| 86 | + if(self::$_application!==null && !defined('PRADO_TEST_RUN')) { |
|
| 87 | + throw new TInvalidOperationException('prado_application_singleton_required'); |
|
| 88 | + } |
|
| 85 | 89 | self::$_application=$application; |
| 86 | 90 | } |
| 87 | 91 | public static function getApplication() |
@@ -94,14 +98,16 @@ discard block |
||
| 94 | 98 | } |
| 95 | 99 | public static function createComponent($type) |
| 96 | 100 | { |
| 97 | - if(!isset(self::$classExists[$type])) |
|
| 98 | - self::$classExists[$type] = class_exists($type, false); |
|
| 101 | + if(!isset(self::$classExists[$type])) { |
|
| 102 | + self::$classExists[$type] = class_exists($type, false); |
|
| 103 | + } |
|
| 99 | 104 | if( !isset(self::$_usings[$type]) && !self::$classExists[$type]) { |
| 100 | 105 | self::using($type); |
| 101 | 106 | self::$classExists[$type] = class_exists($type, false); |
| 102 | 107 | } |
| 103 | - if( ($pos = strrpos($type, '.')) !== false) |
|
| 104 | - $type = substr($type,$pos+1); |
|
| 108 | + if( ($pos = strrpos($type, '.')) !== false) { |
|
| 109 | + $type = substr($type,$pos+1); |
|
| 110 | + } |
|
| 105 | 111 | if(($n=func_num_args())>1) |
| 106 | 112 | { |
| 107 | 113 | $args = func_get_args(); |
@@ -120,74 +126,77 @@ discard block |
||
| 120 | 126 | break; |
| 121 | 127 | default: |
| 122 | 128 | $s='$args[1]'; |
| 123 | - for($i=2;$i<$n;++$i) |
|
| 124 | - $s.=",\$args[$i]"; |
|
| 129 | + for($i=2;$i<$n;++$i) { |
|
| 130 | + $s.=",\$args[$i]"; |
|
| 131 | + } |
|
| 125 | 132 | eval("\$component=new $type($s);"); |
| 126 | 133 | return $component; |
| 127 | 134 | break; |
| 128 | 135 | } |
| 136 | + } else { |
|
| 137 | + return new $type; |
|
| 129 | 138 | } |
| 130 | - else |
|
| 131 | - return new $type; |
|
| 132 | 139 | } |
| 133 | 140 | public static function using($namespace,$checkClassExistence=true) |
| 134 | 141 | { |
| 135 | - if(isset(self::$_usings[$namespace]) || class_exists($namespace,false)) |
|
| 136 | - return; |
|
| 142 | + if(isset(self::$_usings[$namespace]) || class_exists($namespace,false)) { |
|
| 143 | + return; |
|
| 144 | + } |
|
| 137 | 145 | if(($pos=strrpos($namespace,'.'))===false) { |
| 138 | 146 | try |
| 139 | 147 | { |
| 140 | 148 | include_once($namespace.self::CLASS_FILE_EXT); |
| 141 | - } |
|
| 142 | - catch(Exception $e) |
|
| 149 | + } catch(Exception $e) |
|
| 143 | 150 | { |
| 144 | - if($checkClassExistence && !class_exists($namespace,false)) |
|
| 145 | - throw new TInvalidOperationException('prado_component_unknown',$namespace,$e->getMessage()); |
|
| 146 | - else |
|
| 147 | - throw $e; |
|
| 151 | + if($checkClassExistence && !class_exists($namespace,false)) { |
|
| 152 | + throw new TInvalidOperationException('prado_component_unknown',$namespace,$e->getMessage()); |
|
| 153 | + } else { |
|
| 154 | + throw $e; |
|
| 155 | + } |
|
| 148 | 156 | } |
| 149 | - } |
|
| 150 | - else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null) |
|
| 157 | + } else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null) |
|
| 151 | 158 | { |
| 152 | 159 | $className=substr($namespace,$pos+1); |
| 153 | 160 | if($className==='*') { |
| 154 | 161 | self::$_usings[$namespace]=$path; |
| 155 | 162 | set_include_path(get_include_path().PATH_SEPARATOR.$path); |
| 156 | - } |
|
| 157 | - else { |
|
| 163 | + } else { |
|
| 158 | 164 | self::$_usings[$namespace]=$path; |
| 159 | 165 | if(!$checkClassExistence || !class_exists($className,false)) |
| 160 | 166 | { |
| 161 | 167 | try |
| 162 | 168 | { |
| 163 | 169 | include_once($path); |
| 164 | - } |
|
| 165 | - catch(Exception $e) |
|
| 170 | + } catch(Exception $e) |
|
| 166 | 171 | { |
| 167 | - if($checkClassExistence && !class_exists($className,false)) |
|
| 168 | - throw new TInvalidOperationException('prado_component_unknown',$className,$e->getMessage()); |
|
| 169 | - else |
|
| 170 | - throw $e; |
|
| 172 | + if($checkClassExistence && !class_exists($className,false)) { |
|
| 173 | + throw new TInvalidOperationException('prado_component_unknown',$className,$e->getMessage()); |
|
| 174 | + } else { |
|
| 175 | + throw $e; |
|
| 176 | + } |
|
| 171 | 177 | } |
| 172 | 178 | } |
| 173 | 179 | } |
| 180 | + } else { |
|
| 181 | + throw new TInvalidDataValueException('prado_using_invalid',$namespace); |
|
| 174 | 182 | } |
| 175 | - else |
|
| 176 | - throw new TInvalidDataValueException('prado_using_invalid',$namespace); |
|
| 177 | 183 | } |
| 178 | 184 | public static function getPathOfNamespace($namespace, $ext='') |
| 179 | 185 | { |
| 180 | 186 | if(self::CLASS_FILE_EXT === $ext || empty($ext)) |
| 181 | 187 | { |
| 182 | - if(isset(self::$_usings[$namespace])) |
|
| 183 | - return self::$_usings[$namespace]; |
|
| 184 | - if(isset(self::$_aliases[$namespace])) |
|
| 185 | - return self::$_aliases[$namespace]; |
|
| 188 | + if(isset(self::$_usings[$namespace])) { |
|
| 189 | + return self::$_usings[$namespace]; |
|
| 190 | + } |
|
| 191 | + if(isset(self::$_aliases[$namespace])) { |
|
| 192 | + return self::$_aliases[$namespace]; |
|
| 193 | + } |
|
| 186 | 194 | } |
| 187 | 195 | $segs = explode('.',$namespace); |
| 188 | 196 | $alias = array_shift($segs); |
| 189 | - if(null !== ($file = array_pop($segs)) && null !== ($root = self::getPathOfAlias($alias))) |
|
| 190 | - return rtrim($root.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR ,$segs),'/\\').(($file === '*') ? '' : DIRECTORY_SEPARATOR.$file.$ext); |
|
| 197 | + if(null !== ($file = array_pop($segs)) && null !== ($root = self::getPathOfAlias($alias))) { |
|
| 198 | + return rtrim($root.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR ,$segs),'/\\').(($file === '*') ? '' : DIRECTORY_SEPARATOR.$file.$ext); |
|
| 199 | + } |
|
| 191 | 200 | return null; |
| 192 | 201 | } |
| 193 | 202 | public static function getPathOfAlias($alias) |
@@ -200,39 +209,45 @@ discard block |
||
| 200 | 209 | } |
| 201 | 210 | public static function setPathOfAlias($alias,$path) |
| 202 | 211 | { |
| 203 | - if(isset(self::$_aliases[$alias]) && !defined('PRADO_TEST_RUN')) |
|
| 204 | - throw new TInvalidOperationException('prado_alias_redefined',$alias); |
|
| 205 | - else if(($rp=realpath($path))!==false && is_dir($rp)) |
|
| 212 | + if(isset(self::$_aliases[$alias]) && !defined('PRADO_TEST_RUN')) { |
|
| 213 | + throw new TInvalidOperationException('prado_alias_redefined',$alias); |
|
| 214 | + } else if(($rp=realpath($path))!==false && is_dir($rp)) |
|
| 206 | 215 | { |
| 207 | - if(strpos($alias,'.')===false) |
|
| 208 | - self::$_aliases[$alias]=$rp; |
|
| 209 | - else |
|
| 210 | - throw new TInvalidDataValueException('prado_aliasname_invalid',$alias); |
|
| 216 | + if(strpos($alias,'.')===false) { |
|
| 217 | + self::$_aliases[$alias]=$rp; |
|
| 218 | + } else { |
|
| 219 | + throw new TInvalidDataValueException('prado_aliasname_invalid',$alias); |
|
| 220 | + } |
|
| 221 | + } else { |
|
| 222 | + throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path); |
|
| 211 | 223 | } |
| 212 | - else |
|
| 213 | - throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path); |
|
| 214 | 224 | } |
| 215 | 225 | public static function fatalError($msg) |
| 216 | 226 | { |
| 217 | 227 | echo '<h1>Fatal Error</h1>'; |
| 218 | 228 | echo '<p>'.$msg.'</p>'; |
| 219 | - if(!function_exists('debug_backtrace')) |
|
| 220 | - return; |
|
| 229 | + if(!function_exists('debug_backtrace')) { |
|
| 230 | + return; |
|
| 231 | + } |
|
| 221 | 232 | echo '<h2>Debug Backtrace</h2>'; |
| 222 | 233 | echo '<pre>'; |
| 223 | 234 | $index=-1; |
| 224 | 235 | foreach(debug_backtrace() as $t) |
| 225 | 236 | { |
| 226 | 237 | $index++; |
| 227 | - if($index==0) continue; |
|
| 238 | + if($index==0) { |
|
| 239 | + continue; |
|
| 240 | + } |
|
| 228 | 241 | echo '#'.$index.' '; |
| 229 | - if(isset($t['file'])) |
|
| 230 | - echo basename($t['file']) . ':' . $t['line']; |
|
| 231 | - else |
|
| 232 | - echo '<PHP inner-code>'; |
|
| 242 | + if(isset($t['file'])) { |
|
| 243 | + echo basename($t['file']) . ':' . $t['line']; |
|
| 244 | + } else { |
|
| 245 | + echo '<PHP inner-code>'; |
|
| 246 | + } |
|
| 233 | 247 | echo ' -- '; |
| 234 | - if(isset($t['class'])) |
|
| 235 | - echo $t['class'] . $t['type']; |
|
| 248 | + if(isset($t['class'])) { |
|
| 249 | + echo $t['class'] . $t['type']; |
|
| 250 | + } |
|
| 236 | 251 | echo $t['function'] . '('; |
| 237 | 252 | if(isset($t['args']) && sizeof($t['args']) > 0) |
| 238 | 253 | { |
@@ -242,26 +257,28 @@ discard block |
||
| 242 | 257 | if(is_string($item)) |
| 243 | 258 | { |
| 244 | 259 | $str=htmlentities(str_replace("\r\n", "", $item), ENT_QUOTES); |
| 245 | - if (strlen($item) > 70) |
|
| 246 | - echo "'". substr($str, 0, 70) . "...'"; |
|
| 247 | - else |
|
| 248 | - echo "'" . $str . "'"; |
|
| 260 | + if (strlen($item) > 70) { |
|
| 261 | + echo "'". substr($str, 0, 70) . "...'"; |
|
| 262 | + } else { |
|
| 263 | + echo "'" . $str . "'"; |
|
| 264 | + } |
|
| 265 | + } else if (is_int($item) || is_float($item)) { |
|
| 266 | + echo $item; |
|
| 267 | + } else if (is_object($item)) { |
|
| 268 | + echo get_class($item); |
|
| 269 | + } else if (is_array($item)) { |
|
| 270 | + echo 'array(' . count($item) . ')'; |
|
| 271 | + } else if (is_bool($item)) { |
|
| 272 | + echo $item ? 'true' : 'false'; |
|
| 273 | + } else if ($item === null) { |
|
| 274 | + echo 'NULL'; |
|
| 275 | + } else if (is_resource($item)) { |
|
| 276 | + echo get_resource_type($item); |
|
| 249 | 277 | } |
| 250 | - else if (is_int($item) || is_float($item)) |
|
| 251 | - echo $item; |
|
| 252 | - else if (is_object($item)) |
|
| 253 | - echo get_class($item); |
|
| 254 | - else if (is_array($item)) |
|
| 255 | - echo 'array(' . count($item) . ')'; |
|
| 256 | - else if (is_bool($item)) |
|
| 257 | - echo $item ? 'true' : 'false'; |
|
| 258 | - else if ($item === null) |
|
| 259 | - echo 'NULL'; |
|
| 260 | - else if (is_resource($item)) |
|
| 261 | - echo get_resource_type($item); |
|
| 262 | 278 | $count++; |
| 263 | - if (count($t['args']) > $count) |
|
| 264 | - echo ', '; |
|
| 279 | + if (count($t['args']) > $count) { |
|
| 280 | + echo ', '; |
|
| 281 | + } |
|
| 265 | 282 | } |
| 266 | 283 | } |
| 267 | 284 | echo ")\n"; |
@@ -274,9 +291,9 @@ discard block |
||
| 274 | 291 | static $languages=null; |
| 275 | 292 | if($languages===null) |
| 276 | 293 | { |
| 277 | - if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
|
| 278 | - $languages[0]='en'; |
|
| 279 | - else |
|
| 294 | + if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 295 | + $languages[0]='en'; |
|
| 296 | + } else |
|
| 280 | 297 | { |
| 281 | 298 | $languages=array(); |
| 282 | 299 | foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language) |
@@ -286,8 +303,9 @@ discard block |
||
| 286 | 303 | } |
| 287 | 304 | arsort($languages); |
| 288 | 305 | $languages=array_keys($languages); |
| 289 | - if(empty($languages)) |
|
| 290 | - $languages[0]='en'; |
|
| 306 | + if(empty($languages)) { |
|
| 307 | + $languages[0]='en'; |
|
| 308 | + } |
|
| 291 | 309 | } |
| 292 | 310 | } |
| 293 | 311 | return $languages; |
@@ -299,38 +317,43 @@ discard block |
||
| 299 | 317 | { |
| 300 | 318 | $langs=Prado::getUserLanguages(); |
| 301 | 319 | $lang=explode('-',$langs[0]); |
| 302 | - if(empty($lang[0]) || !ctype_alpha($lang[0])) |
|
| 303 | - $language='en'; |
|
| 304 | - else |
|
| 305 | - $language=$lang[0]; |
|
| 320 | + if(empty($lang[0]) || !ctype_alpha($lang[0])) { |
|
| 321 | + $language='en'; |
|
| 322 | + } else { |
|
| 323 | + $language=$lang[0]; |
|
| 324 | + } |
|
| 306 | 325 | } |
| 307 | 326 | return $language; |
| 308 | 327 | } |
| 309 | 328 | public static function trace($msg,$category='Uncategorized',$ctl=null) |
| 310 | 329 | { |
| 311 | - if(self::$_application && self::$_application->getMode()===TApplicationMode::Performance) |
|
| 312 | - return; |
|
| 330 | + if(self::$_application && self::$_application->getMode()===TApplicationMode::Performance) { |
|
| 331 | + return; |
|
| 332 | + } |
|
| 313 | 333 | if(!self::$_application || self::$_application->getMode()===TApplicationMode::Debug) |
| 314 | 334 | { |
| 315 | 335 | $trace=debug_backtrace(); |
| 316 | - if(isset($trace[0]['file']) && isset($trace[0]['line'])) |
|
| 317 | - $msg.=" (line {$trace[0]['line']}, {$trace[0]['file']})"; |
|
| 336 | + if(isset($trace[0]['file']) && isset($trace[0]['line'])) { |
|
| 337 | + $msg.=" (line {$trace[0]['line']}, {$trace[0]['file']})"; |
|
| 338 | + } |
|
| 318 | 339 | $level=TLogger::DEBUG; |
| 340 | + } else { |
|
| 341 | + $level=TLogger::INFO; |
|
| 319 | 342 | } |
| 320 | - else |
|
| 321 | - $level=TLogger::INFO; |
|
| 322 | 343 | self::log($msg,$level,$category,$ctl); |
| 323 | 344 | } |
| 324 | 345 | public static function log($msg,$level=TLogger::INFO,$category='Uncategorized',$ctl=null) |
| 325 | 346 | { |
| 326 | - if(self::$_logger===null) |
|
| 327 | - self::$_logger=new TLogger; |
|
| 347 | + if(self::$_logger===null) { |
|
| 348 | + self::$_logger=new TLogger; |
|
| 349 | + } |
|
| 328 | 350 | self::$_logger->log($msg,$level,$category,$ctl); |
| 329 | 351 | } |
| 330 | 352 | public static function getLogger() |
| 331 | 353 | { |
| 332 | - if(self::$_logger===null) |
|
| 333 | - self::$_logger=new TLogger; |
|
| 354 | + if(self::$_logger===null) { |
|
| 355 | + self::$_logger=new TLogger; |
|
| 356 | + } |
|
| 334 | 357 | return self::$_logger; |
| 335 | 358 | } |
| 336 | 359 | public static function varDump($var,$depth=10,$highlight=false) |
@@ -343,17 +366,24 @@ discard block |
||
| 343 | 366 | Prado::using('System.I18N.Translation'); |
| 344 | 367 | $app = Prado::getApplication()->getGlobalization(false); |
| 345 | 368 | $params = array(); |
| 346 | - foreach($parameters as $key => $value) |
|
| 347 | - $params['{'.$key.'}'] = $value; |
|
| 348 | - if($app===null || ($config = $app->getTranslationConfiguration())===null) |
|
| 349 | - return strtr($text, $params); |
|
| 350 | - if ($catalogue===null) |
|
| 351 | - $catalogue=isset($config['catalogue'])?$config['catalogue']:'messages'; |
|
| 369 | + foreach($parameters as $key => $value) { |
|
| 370 | + $params['{'.$key.'}'] = $value; |
|
| 371 | + } |
|
| 372 | + if($app===null || ($config = $app->getTranslationConfiguration())===null) { |
|
| 373 | + return strtr($text, $params); |
|
| 374 | + } |
|
| 375 | + if ($catalogue===null) { |
|
| 376 | + $catalogue=isset($config['catalogue'])?$config['catalogue']:'messages'; |
|
| 377 | + } |
|
| 352 | 378 | Translation::init($catalogue); |
| 353 | 379 | $appCharset = $app===null ? '' : $app->getCharset(); |
| 354 | 380 | $defaultCharset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset(); |
| 355 | - if(empty($charset)) $charset = $appCharset; |
|
| 356 | - if(empty($charset)) $charset = $defaultCharset; |
|
| 381 | + if(empty($charset)) { |
|
| 382 | + $charset = $appCharset; |
|
| 383 | + } |
|
| 384 | + if(empty($charset)) { |
|
| 385 | + $charset = $defaultCharset; |
|
| 386 | + } |
|
| 357 | 387 | return Translation::formatter($catalogue)->format($text,$params,$catalogue,$charset); |
| 358 | 388 | } |
| 359 | 389 | } |
@@ -472,8 +502,9 @@ discard block |
||
| 472 | 502 | } |
| 473 | 503 | public function publishAsset($assetPath,$className=null) |
| 474 | 504 | { |
| 475 | - if($className===null) |
|
| 476 | - $className=get_class($this); |
|
| 505 | + if($className===null) { |
|
| 506 | + $className=get_class($this); |
|
| 507 | + } |
|
| 477 | 508 | $class=new ReflectionClass($className); |
| 478 | 509 | $fullPath=dirname($class->getFileName()).DIRECTORY_SEPARATOR.$assetPath; |
| 479 | 510 | return $this->publishFilePath($fullPath); |
@@ -537,37 +568,42 @@ discard block |
||
| 537 | 568 | } |
| 538 | 569 | public function getErrorTemplatePath() |
| 539 | 570 | { |
| 540 | - if($this->_templatePath===null) |
|
| 541 | - $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates'; |
|
| 571 | + if($this->_templatePath===null) { |
|
| 572 | + $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates'; |
|
| 573 | + } |
|
| 542 | 574 | return $this->_templatePath; |
| 543 | 575 | } |
| 544 | 576 | public function setErrorTemplatePath($value) |
| 545 | 577 | { |
| 546 | - if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath)) |
|
| 547 | - $this->_templatePath=$templatePath; |
|
| 548 | - else |
|
| 549 | - throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value); |
|
| 578 | + if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath)) { |
|
| 579 | + $this->_templatePath=$templatePath; |
|
| 580 | + } else { |
|
| 581 | + throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value); |
|
| 582 | + } |
|
| 550 | 583 | } |
| 551 | 584 | public function handleError($sender,$param) |
| 552 | 585 | { |
| 553 | 586 | static $handling=false; |
| 554 | 587 | restore_error_handler(); |
| 555 | 588 | restore_exception_handler(); |
| 556 | - if($handling) |
|
| 557 | - $this->handleRecursiveError($param); |
|
| 558 | - else |
|
| 589 | + if($handling) { |
|
| 590 | + $this->handleRecursiveError($param); |
|
| 591 | + } else |
|
| 559 | 592 | { |
| 560 | 593 | $handling=true; |
| 561 | - if(($response=$this->getResponse())!==null) |
|
| 562 | - $response->clear(); |
|
| 563 | - if(!headers_sent()) |
|
| 564 | - header('Content-Type: text/html; charset=UTF-8'); |
|
| 565 | - if($param instanceof THttpException) |
|
| 566 | - $this->handleExternalError($param->getStatusCode(),$param); |
|
| 567 | - else if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
| 568 | - $this->displayException($param); |
|
| 569 | - else |
|
| 570 | - $this->handleExternalError(500,$param); |
|
| 594 | + if(($response=$this->getResponse())!==null) { |
|
| 595 | + $response->clear(); |
|
| 596 | + } |
|
| 597 | + if(!headers_sent()) { |
|
| 598 | + header('Content-Type: text/html; charset=UTF-8'); |
|
| 599 | + } |
|
| 600 | + if($param instanceof THttpException) { |
|
| 601 | + $this->handleExternalError($param->getStatusCode(),$param); |
|
| 602 | + } else if($this->getApplication()->getMode()===TApplicationMode::Debug) { |
|
| 603 | + $this->displayException($param); |
|
| 604 | + } else { |
|
| 605 | + $this->handleExternalError(500,$param); |
|
| 606 | + } |
|
| 571 | 607 | } |
| 572 | 608 | } |
| 573 | 609 | protected static function hideSecurityRelated($value, $exception=null) |
@@ -578,28 +614,32 @@ discard block |
||
| 578 | 614 | $aTrace = $exception->getTrace(); |
| 579 | 615 | foreach($aTrace as $item) |
| 580 | 616 | { |
| 581 | - if(isset($item['file'])) |
|
| 582 | - $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
| 617 | + if(isset($item['file'])) { |
|
| 618 | + $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
| 619 | + } |
|
| 583 | 620 | } |
| 584 | 621 | } |
| 585 | 622 | $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}'; |
| 586 | 623 | $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}'; |
| 587 | 624 | $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR; |
| 588 | - if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
| 625 | + if(isset($aRpl[DIRECTORY_SEPARATOR])) { |
|
| 626 | + unset($aRpl[DIRECTORY_SEPARATOR]); |
|
| 627 | + } |
|
| 589 | 628 | $aRpl = array_reverse($aRpl, true); |
| 590 | 629 | return str_replace(array_keys($aRpl), $aRpl, $value); |
| 591 | 630 | } |
| 592 | 631 | protected function handleExternalError($statusCode,$exception) |
| 593 | 632 | { |
| 594 | - if(!($exception instanceof THttpException)) |
|
| 595 | - error_log($exception->__toString()); |
|
| 633 | + if(!($exception instanceof THttpException)) { |
|
| 634 | + error_log($exception->__toString()); |
|
| 635 | + } |
|
| 596 | 636 | $content=$this->getErrorTemplate($statusCode,$exception); |
| 597 | 637 | $serverAdmin=isset($_SERVER['SERVER_ADMIN'])?$_SERVER['SERVER_ADMIN']:''; |
| 598 | 638 | $isDebug = $this->getApplication()->getMode()===TApplicationMode::Debug; |
| 599 | 639 | $errorMessage = $exception->getMessage(); |
| 600 | - if($isDebug) |
|
| 601 | - $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 602 | - else |
|
| 640 | + if($isDebug) { |
|
| 641 | + $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 642 | + } else |
|
| 603 | 643 | { |
| 604 | 644 | $version=''; |
| 605 | 645 | $errorMessage = self::hideSecurityRelated($errorMessage, $exception); |
@@ -622,8 +662,7 @@ discard block |
||
| 622 | 662 | echo "<body><h1>Recursive Error</h1>\n"; |
| 623 | 663 | echo "<pre>".$exception->__toString()."</pre>\n"; |
| 624 | 664 | echo "</body></html>"; |
| 625 | - } |
|
| 626 | - else |
|
| 665 | + } else |
|
| 627 | 666 | { |
| 628 | 667 | error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
| 629 | 668 | header('HTTP/1.0 500 Internal Error'); |
@@ -642,28 +681,28 @@ discard block |
||
| 642 | 681 | $fileName=$exception->getTemplateFile(); |
| 643 | 682 | $lines=empty($fileName)?explode("\n",$exception->getTemplateSource()):@file($fileName); |
| 644 | 683 | $source=$this->getSourceCode($lines,$exception->getLineNumber()); |
| 645 | - if($fileName==='') |
|
| 646 | - $fileName='---embedded template---'; |
|
| 684 | + if($fileName==='') { |
|
| 685 | + $fileName='---embedded template---'; |
|
| 686 | + } |
|
| 647 | 687 | $errorLine=$exception->getLineNumber(); |
| 648 | - } |
|
| 649 | - else |
|
| 688 | + } else |
|
| 650 | 689 | { |
| 651 | 690 | if(($trace=$this->getExactTrace($exception))!==null) |
| 652 | 691 | { |
| 653 | 692 | $fileName=$trace['file']; |
| 654 | 693 | $errorLine=$trace['line']; |
| 655 | - } |
|
| 656 | - else |
|
| 694 | + } else |
|
| 657 | 695 | { |
| 658 | 696 | $fileName=$exception->getFile(); |
| 659 | 697 | $errorLine=$exception->getLine(); |
| 660 | 698 | } |
| 661 | 699 | $source=$this->getSourceCode(@file($fileName),$errorLine); |
| 662 | 700 | } |
| 663 | - if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
| 664 | - $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 665 | - else |
|
| 666 | - $version=''; |
|
| 701 | + if($this->getApplication()->getMode()===TApplicationMode::Debug) { |
|
| 702 | + $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 703 | + } else { |
|
| 704 | + $version=''; |
|
| 705 | + } |
|
| 667 | 706 | $tokens=array( |
| 668 | 707 | '%%ErrorType%%' => get_class($exception), |
| 669 | 708 | '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())), |
@@ -680,26 +719,30 @@ discard block |
||
| 680 | 719 | { |
| 681 | 720 | $lang=Prado::getPreferredLanguage(); |
| 682 | 721 | $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'-'.$lang.'.html'; |
| 683 | - if(!is_file($exceptionFile)) |
|
| 684 | - $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html'; |
|
| 685 | - if(($content=@file_get_contents($exceptionFile))===false) |
|
| 686 | - die("Unable to open exception template file '$exceptionFile'."); |
|
| 722 | + if(!is_file($exceptionFile)) { |
|
| 723 | + $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html'; |
|
| 724 | + } |
|
| 725 | + if(($content=@file_get_contents($exceptionFile))===false) { |
|
| 726 | + die("Unable to open exception template file '$exceptionFile'."); |
|
| 727 | + } |
|
| 687 | 728 | return $content; |
| 688 | 729 | } |
| 689 | 730 | protected function getErrorTemplate($statusCode,$exception) |
| 690 | 731 | { |
| 691 | 732 | $base=$this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME; |
| 692 | 733 | $lang=Prado::getPreferredLanguage(); |
| 693 | - if(is_file("$base$statusCode-$lang.html")) |
|
| 694 | - $errorFile="$base$statusCode-$lang.html"; |
|
| 695 | - else if(is_file("$base$statusCode.html")) |
|
| 696 | - $errorFile="$base$statusCode.html"; |
|
| 697 | - else if(is_file("$base-$lang.html")) |
|
| 698 | - $errorFile="$base-$lang.html"; |
|
| 699 | - else |
|
| 700 | - $errorFile="$base.html"; |
|
| 701 | - if(($content=@file_get_contents($errorFile))===false) |
|
| 702 | - die("Unable to open error template file '$errorFile'."); |
|
| 734 | + if(is_file("$base$statusCode-$lang.html")) { |
|
| 735 | + $errorFile="$base$statusCode-$lang.html"; |
|
| 736 | + } else if(is_file("$base$statusCode.html")) { |
|
| 737 | + $errorFile="$base$statusCode.html"; |
|
| 738 | + } else if(is_file("$base-$lang.html")) { |
|
| 739 | + $errorFile="$base-$lang.html"; |
|
| 740 | + } else { |
|
| 741 | + $errorFile="$base.html"; |
|
| 742 | + } |
|
| 743 | + if(($content=@file_get_contents($errorFile))===false) { |
|
| 744 | + die("Unable to open error template file '$errorFile'."); |
|
| 745 | + } |
|
| 703 | 746 | return $content; |
| 704 | 747 | } |
| 705 | 748 | private function getExactTrace($exception) |
@@ -708,18 +751,20 @@ discard block |
||
| 708 | 751 | $result=null; |
| 709 | 752 | if($exception instanceof TPhpErrorException) |
| 710 | 753 | { |
| 711 | - if(isset($trace[0]['file'])) |
|
| 712 | - $result=$trace[0]; |
|
| 713 | - elseif(isset($trace[1])) |
|
| 714 | - $result=$trace[1]; |
|
| 715 | - } |
|
| 716 | - else if($exception instanceof TInvalidOperationException) |
|
| 754 | + if(isset($trace[0]['file'])) { |
|
| 755 | + $result=$trace[0]; |
|
| 756 | + } elseif(isset($trace[1])) { |
|
| 757 | + $result=$trace[1]; |
|
| 758 | + } |
|
| 759 | + } else if($exception instanceof TInvalidOperationException) |
|
| 717 | 760 | { |
| 718 | - if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null) |
|
| 719 | - $result=$this->getPropertyAccessTrace($trace,'__set'); |
|
| 761 | + if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null) { |
|
| 762 | + $result=$this->getPropertyAccessTrace($trace,'__set'); |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + if($result!==null && strpos($result['file'],': eval()\'d code')!==false) { |
|
| 766 | + return null; |
|
| 720 | 767 | } |
| 721 | - if($result!==null && strpos($result['file'],': eval()\'d code')!==false) |
|
| 722 | - return null; |
|
| 723 | 768 | return $result; |
| 724 | 769 | } |
| 725 | 770 | private function getPropertyAccessTrace($trace,$pattern) |
@@ -727,10 +772,11 @@ discard block |
||
| 727 | 772 | $result=null; |
| 728 | 773 | foreach($trace as $t) |
| 729 | 774 | { |
| 730 | - if(isset($t['function']) && $t['function']===$pattern) |
|
| 731 | - $result=$t; |
|
| 732 | - else |
|
| 733 | - break; |
|
| 775 | + if(isset($t['function']) && $t['function']===$pattern) { |
|
| 776 | + $result=$t; |
|
| 777 | + } else { |
|
| 778 | + break; |
|
| 779 | + } |
|
| 734 | 780 | } |
| 735 | 781 | return $result; |
| 736 | 782 | } |
@@ -745,9 +791,9 @@ discard block |
||
| 745 | 791 | { |
| 746 | 792 | $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
| 747 | 793 | $source.="<div class=\"error\">".$line."</div>"; |
| 794 | + } else { |
|
| 795 | + $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
| 748 | 796 | } |
| 749 | - else |
|
| 750 | - $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
| 751 | 797 | } |
| 752 | 798 | return $source; |
| 753 | 799 | } |
@@ -764,8 +810,9 @@ discard block |
||
| 764 | 810 | private $_r=false; |
| 765 | 811 | public function __construct($data=null,$readOnly=false) |
| 766 | 812 | { |
| 767 | - if($data!==null) |
|
| 768 | - $this->copyFrom($data); |
|
| 813 | + if($data!==null) { |
|
| 814 | + $this->copyFrom($data); |
|
| 815 | + } |
|
| 769 | 816 | $this->setReadOnly($readOnly); |
| 770 | 817 | } |
| 771 | 818 | public function getReadOnly() |
@@ -790,10 +837,11 @@ discard block |
||
| 790 | 837 | } |
| 791 | 838 | public function itemAt($index) |
| 792 | 839 | { |
| 793 | - if($index>=0 && $index<$this->_c) |
|
| 794 | - return $this->_d[$index]; |
|
| 795 | - else |
|
| 796 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 840 | + if($index>=0 && $index<$this->_c) { |
|
| 841 | + return $this->_d[$index]; |
|
| 842 | + } else { |
|
| 843 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 844 | + } |
|
| 797 | 845 | } |
| 798 | 846 | public function add($item) |
| 799 | 847 | { |
@@ -804,18 +852,18 @@ discard block |
||
| 804 | 852 | { |
| 805 | 853 | if(!$this->_r) |
| 806 | 854 | { |
| 807 | - if($index===$this->_c) |
|
| 808 | - $this->_d[$this->_c++]=$item; |
|
| 809 | - else if($index>=0 && $index<$this->_c) |
|
| 855 | + if($index===$this->_c) { |
|
| 856 | + $this->_d[$this->_c++]=$item; |
|
| 857 | + } else if($index>=0 && $index<$this->_c) |
|
| 810 | 858 | { |
| 811 | 859 | array_splice($this->_d,$index,0,array($item)); |
| 812 | 860 | $this->_c++; |
| 861 | + } else { |
|
| 862 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 813 | 863 | } |
| 814 | - else |
|
| 815 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 864 | + } else { |
|
| 865 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 816 | 866 | } |
| 817 | - else |
|
| 818 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 819 | 867 | } |
| 820 | 868 | public function remove($item) |
| 821 | 869 | { |
@@ -825,12 +873,12 @@ discard block |
||
| 825 | 873 | { |
| 826 | 874 | $this->removeAt($index); |
| 827 | 875 | return $index; |
| 876 | + } else { |
|
| 877 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 828 | 878 | } |
| 829 | - else |
|
| 830 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 879 | + } else { |
|
| 880 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 831 | 881 | } |
| 832 | - else |
|
| 833 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 834 | 882 | } |
| 835 | 883 | public function removeAt($index) |
| 836 | 884 | { |
@@ -839,25 +887,26 @@ discard block |
||
| 839 | 887 | if($index>=0 && $index<$this->_c) |
| 840 | 888 | { |
| 841 | 889 | $this->_c--; |
| 842 | - if($index===$this->_c) |
|
| 843 | - return array_pop($this->_d); |
|
| 844 | - else |
|
| 890 | + if($index===$this->_c) { |
|
| 891 | + return array_pop($this->_d); |
|
| 892 | + } else |
|
| 845 | 893 | { |
| 846 | 894 | $item=$this->_d[$index]; |
| 847 | 895 | array_splice($this->_d,$index,1); |
| 848 | 896 | return $item; |
| 849 | 897 | } |
| 898 | + } else { |
|
| 899 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 850 | 900 | } |
| 851 | - else |
|
| 852 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 901 | + } else { |
|
| 902 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 853 | 903 | } |
| 854 | - else |
|
| 855 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 856 | 904 | } |
| 857 | 905 | public function clear() |
| 858 | 906 | { |
| 859 | - for($i=$this->_c-1;$i>=0;--$i) |
|
| 860 | - $this->removeAt($i); |
|
| 907 | + for($i=$this->_c-1;$i>=0;--$i) { |
|
| 908 | + $this->removeAt($i); |
|
| 909 | + } |
|
| 861 | 910 | } |
| 862 | 911 | public function contains($item) |
| 863 | 912 | { |
@@ -865,34 +914,37 @@ discard block |
||
| 865 | 914 | } |
| 866 | 915 | public function indexOf($item) |
| 867 | 916 | { |
| 868 | - if(($index=array_search($item,$this->_d,true))===false) |
|
| 869 | - return -1; |
|
| 870 | - else |
|
| 871 | - return $index; |
|
| 917 | + if(($index=array_search($item,$this->_d,true))===false) { |
|
| 918 | + return -1; |
|
| 919 | + } else { |
|
| 920 | + return $index; |
|
| 921 | + } |
|
| 872 | 922 | } |
| 873 | 923 | public function insertBefore($baseitem, $item) |
| 874 | 924 | { |
| 875 | 925 | if(!$this->_r) |
| 876 | 926 | { |
| 877 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
| 878 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 927 | + if(($index = $this->indexOf($baseitem)) == -1) { |
|
| 928 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 929 | + } |
|
| 879 | 930 | $this->insertAt($index, $item); |
| 880 | 931 | return $index; |
| 932 | + } else { |
|
| 933 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 881 | 934 | } |
| 882 | - else |
|
| 883 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 884 | 935 | } |
| 885 | 936 | public function insertAfter($baseitem, $item) |
| 886 | 937 | { |
| 887 | 938 | if(!$this->_r) |
| 888 | 939 | { |
| 889 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
| 890 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 940 | + if(($index = $this->indexOf($baseitem)) == -1) { |
|
| 941 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 942 | + } |
|
| 891 | 943 | $this->insertAt($index + 1, $item); |
| 892 | 944 | return $index + 1; |
| 945 | + } else { |
|
| 946 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 893 | 947 | } |
| 894 | - else |
|
| 895 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 896 | 948 | } |
| 897 | 949 | public function toArray() |
| 898 | 950 | { |
@@ -902,23 +954,26 @@ discard block |
||
| 902 | 954 | { |
| 903 | 955 | if(is_array($data) || ($data instanceof Traversable)) |
| 904 | 956 | { |
| 905 | - if($this->_c>0) |
|
| 906 | - $this->clear(); |
|
| 907 | - foreach($data as $item) |
|
| 908 | - $this->add($item); |
|
| 957 | + if($this->_c>0) { |
|
| 958 | + $this->clear(); |
|
| 959 | + } |
|
| 960 | + foreach($data as $item) { |
|
| 961 | + $this->add($item); |
|
| 962 | + } |
|
| 963 | + } else if($data!==null) { |
|
| 964 | + throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
| 909 | 965 | } |
| 910 | - else if($data!==null) |
|
| 911 | - throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
| 912 | 966 | } |
| 913 | 967 | public function mergeWith($data) |
| 914 | 968 | { |
| 915 | 969 | if(is_array($data) || ($data instanceof Traversable)) |
| 916 | 970 | { |
| 917 | - foreach($data as $item) |
|
| 918 | - $this->add($item); |
|
| 971 | + foreach($data as $item) { |
|
| 972 | + $this->add($item); |
|
| 973 | + } |
|
| 974 | + } else if($data!==null) { |
|
| 975 | + throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
| 919 | 976 | } |
| 920 | - else if($data!==null) |
|
| 921 | - throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
| 922 | 977 | } |
| 923 | 978 | public function offsetExists($offset) |
| 924 | 979 | { |
@@ -930,9 +985,9 @@ discard block |
||
| 930 | 985 | } |
| 931 | 986 | public function offsetSet($offset,$item) |
| 932 | 987 | { |
| 933 | - if($offset===null || $offset===$this->_c) |
|
| 934 | - $this->insertAt($this->_c,$item); |
|
| 935 | - else |
|
| 988 | + if($offset===null || $offset===$this->_c) { |
|
| 989 | + $this->insertAt($this->_c,$item); |
|
| 990 | + } else |
|
| 936 | 991 | { |
| 937 | 992 | $this->removeAt($offset); |
| 938 | 993 | $this->insertAt($offset,$item); |
@@ -952,14 +1007,16 @@ discard block |
||
| 952 | 1007 | private $_primary=true; |
| 953 | 1008 | public function init($config) |
| 954 | 1009 | { |
| 955 | - if($this->_prefix===null) |
|
| 956 | - $this->_prefix=$this->getApplication()->getUniqueID(); |
|
| 1010 | + if($this->_prefix===null) { |
|
| 1011 | + $this->_prefix=$this->getApplication()->getUniqueID(); |
|
| 1012 | + } |
|
| 957 | 1013 | if($this->_primary) |
| 958 | 1014 | { |
| 959 | - if($this->getApplication()->getCache()===null) |
|
| 960 | - $this->getApplication()->setCache($this); |
|
| 961 | - else |
|
| 962 | - throw new TConfigurationException('cache_primary_duplicated',get_class($this)); |
|
| 1015 | + if($this->getApplication()->getCache()===null) { |
|
| 1016 | + $this->getApplication()->setCache($this); |
|
| 1017 | + } else { |
|
| 1018 | + throw new TConfigurationException('cache_primary_duplicated',get_class($this)); |
|
| 1019 | + } |
|
| 963 | 1020 | } |
| 964 | 1021 | } |
| 965 | 1022 | public function getPrimaryCache() |
@@ -986,18 +1043,20 @@ discard block |
||
| 986 | 1043 | { |
| 987 | 1044 | if(($data=$this->getValue($this->generateUniqueKey($id)))!==false) |
| 988 | 1045 | { |
| 989 | - if(!is_array($data)) |
|
| 990 | - return false; |
|
| 991 | - if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()) |
|
| 992 | - return $data[0]; |
|
| 1046 | + if(!is_array($data)) { |
|
| 1047 | + return false; |
|
| 1048 | + } |
|
| 1049 | + if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()) { |
|
| 1050 | + return $data[0]; |
|
| 1051 | + } |
|
| 993 | 1052 | } |
| 994 | 1053 | return false; |
| 995 | 1054 | } |
| 996 | 1055 | public function set($id,$value,$expire=0,$dependency=null) |
| 997 | 1056 | { |
| 998 | - if(empty($value) && $expire === 0) |
|
| 999 | - $this->delete($id); |
|
| 1000 | - else |
|
| 1057 | + if(empty($value) && $expire === 0) { |
|
| 1058 | + $this->delete($id); |
|
| 1059 | + } else |
|
| 1001 | 1060 | { |
| 1002 | 1061 | $data=array($value,$dependency); |
| 1003 | 1062 | return $this->setValue($this->generateUniqueKey($id),$data,$expire); |
@@ -1005,8 +1064,9 @@ discard block |
||
| 1005 | 1064 | } |
| 1006 | 1065 | public function add($id,$value,$expire=0,$dependency=null) |
| 1007 | 1066 | { |
| 1008 | - if(empty($value) && $expire === 0) |
|
| 1009 | - return false; |
|
| 1067 | + if(empty($value) && $expire === 0) { |
|
| 1068 | + return false; |
|
| 1069 | + } |
|
| 1010 | 1070 | $data=array($value,$dependency); |
| 1011 | 1071 | return $this->addValue($this->generateUniqueKey($id),$data,$expire); |
| 1012 | 1072 | } |
@@ -1084,8 +1144,9 @@ discard block |
||
| 1084 | 1144 | } |
| 1085 | 1145 | public function setDirectory($directory) |
| 1086 | 1146 | { |
| 1087 | - if(($path=realpath($directory))===false || !is_dir($path)) |
|
| 1088 | - throw new TInvalidDataValueException('directorycachedependency_directory_invalid',$directory); |
|
| 1147 | + if(($path=realpath($directory))===false || !is_dir($path)) { |
|
| 1148 | + throw new TInvalidDataValueException('directorycachedependency_directory_invalid',$directory); |
|
| 1149 | + } |
|
| 1089 | 1150 | $this->_directory=$path; |
| 1090 | 1151 | $this->_timestamps=$this->generateTimestamps($path); |
| 1091 | 1152 | } |
@@ -1119,21 +1180,23 @@ discard block |
||
| 1119 | 1180 | } |
| 1120 | 1181 | protected function generateTimestamps($directory,$level=0) |
| 1121 | 1182 | { |
| 1122 | - if(($dir=opendir($directory))===false) |
|
| 1123 | - throw new TIOException('directorycachedependency_directory_invalid',$directory); |
|
| 1183 | + if(($dir=opendir($directory))===false) { |
|
| 1184 | + throw new TIOException('directorycachedependency_directory_invalid',$directory); |
|
| 1185 | + } |
|
| 1124 | 1186 | $timestamps=array(); |
| 1125 | 1187 | while(($file=readdir($dir))!==false) |
| 1126 | 1188 | { |
| 1127 | 1189 | $path=$directory.DIRECTORY_SEPARATOR.$file; |
| 1128 | - if($file==='.' || $file==='..') |
|
| 1129 | - continue; |
|
| 1130 | - else if(is_dir($path)) |
|
| 1190 | + if($file==='.' || $file==='..') { |
|
| 1191 | + continue; |
|
| 1192 | + } else if(is_dir($path)) |
|
| 1131 | 1193 | { |
| 1132 | - if(($this->_recursiveLevel<0 || $level<$this->_recursiveLevel) && $this->validateDirectory($path)) |
|
| 1133 | - $timestamps=array_merge($this->generateTimestamps($path,$level+1)); |
|
| 1194 | + if(($this->_recursiveLevel<0 || $level<$this->_recursiveLevel) && $this->validateDirectory($path)) { |
|
| 1195 | + $timestamps=array_merge($this->generateTimestamps($path,$level+1)); |
|
| 1196 | + } |
|
| 1197 | + } else if($this->validateFile($path)) { |
|
| 1198 | + $timestamps[$path]=filemtime($path); |
|
| 1134 | 1199 | } |
| 1135 | - else if($this->validateFile($path)) |
|
| 1136 | - $timestamps[$path]=filemtime($path); |
|
| 1137 | 1200 | } |
| 1138 | 1201 | closedir($dir); |
| 1139 | 1202 | return $timestamps; |
@@ -1166,17 +1229,19 @@ discard block |
||
| 1166 | 1229 | private $_dependencies=null; |
| 1167 | 1230 | public function getDependencies() |
| 1168 | 1231 | { |
| 1169 | - if($this->_dependencies===null) |
|
| 1170 | - $this->_dependencies=new TCacheDependencyList; |
|
| 1232 | + if($this->_dependencies===null) { |
|
| 1233 | + $this->_dependencies=new TCacheDependencyList; |
|
| 1234 | + } |
|
| 1171 | 1235 | return $this->_dependencies; |
| 1172 | 1236 | } |
| 1173 | 1237 | public function getHasChanged() |
| 1174 | 1238 | { |
| 1175 | 1239 | if($this->_dependencies!==null) |
| 1176 | 1240 | { |
| 1177 | - foreach($this->_dependencies as $dependency) |
|
| 1178 | - if($dependency->getHasChanged()) |
|
| 1241 | + foreach($this->_dependencies as $dependency) { |
|
| 1242 | + if($dependency->getHasChanged()) |
|
| 1179 | 1243 | return true; |
| 1244 | + } |
|
| 1180 | 1245 | } |
| 1181 | 1246 | return false; |
| 1182 | 1247 | } |
@@ -1192,10 +1257,11 @@ discard block |
||
| 1192 | 1257 | { |
| 1193 | 1258 | public function insertAt($index,$item) |
| 1194 | 1259 | { |
| 1195 | - if($item instanceof ICacheDependency) |
|
| 1196 | - parent::insertAt($index,$item); |
|
| 1197 | - else |
|
| 1198 | - throw new TInvalidDataTypeException('cachedependencylist_cachedependency_required'); |
|
| 1260 | + if($item instanceof ICacheDependency) { |
|
| 1261 | + parent::insertAt($index,$item); |
|
| 1262 | + } else { |
|
| 1263 | + throw new TInvalidDataTypeException('cachedependencylist_cachedependency_required'); |
|
| 1264 | + } |
|
| 1199 | 1265 | } |
| 1200 | 1266 | } |
| 1201 | 1267 | class TTextWriter extends TComponent implements ITextWriter |
@@ -1227,8 +1293,9 @@ discard block |
||
| 1227 | 1293 | public function __construct($data=null,$readOnly=false,$defaultPriority=10,$precision=8) |
| 1228 | 1294 | { |
| 1229 | 1295 | parent::__construct(); |
| 1230 | - if($data!==null) |
|
| 1231 | - $this->copyFrom($data); |
|
| 1296 | + if($data!==null) { |
|
| 1297 | + $this->copyFrom($data); |
|
| 1298 | + } |
|
| 1232 | 1299 | $this->setReadOnly($readOnly); |
| 1233 | 1300 | $this->setPrecision($precision); |
| 1234 | 1301 | $this->setDefaultPriority($defaultPriority); |
@@ -1243,11 +1310,13 @@ discard block |
||
| 1243 | 1310 | } |
| 1244 | 1311 | public function getPriorityCount($priority=null) |
| 1245 | 1312 | { |
| 1246 | - if($priority===null) |
|
| 1247 | - $priority=$this->getDefaultPriority(); |
|
| 1313 | + if($priority===null) { |
|
| 1314 | + $priority=$this->getDefaultPriority(); |
|
| 1315 | + } |
|
| 1248 | 1316 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1249 | - if(!isset($this->_d[$priority]) || !is_array($this->_d[$priority])) |
|
| 1250 | - return false; |
|
| 1317 | + if(!isset($this->_d[$priority]) || !is_array($this->_d[$priority])) { |
|
| 1318 | + return false; |
|
| 1319 | + } |
|
| 1251 | 1320 | return count($this->_d[$priority]); |
| 1252 | 1321 | } |
| 1253 | 1322 | public function getDefaultPriority() |
@@ -1282,12 +1351,14 @@ discard block |
||
| 1282 | 1351 | } |
| 1283 | 1352 | } |
| 1284 | 1353 | protected function flattenPriorities() { |
| 1285 | - if(is_array($this->_fd)) |
|
| 1286 | - return $this->_fd; |
|
| 1354 | + if(is_array($this->_fd)) { |
|
| 1355 | + return $this->_fd; |
|
| 1356 | + } |
|
| 1287 | 1357 | $this->sortPriorities(); |
| 1288 | 1358 | $this->_fd=array(); |
| 1289 | - foreach($this->_d as $priority => $itemsatpriority) |
|
| 1290 | - $this->_fd=array_merge($this->_fd,$itemsatpriority); |
|
| 1359 | + foreach($this->_d as $priority => $itemsatpriority) { |
|
| 1360 | + $this->_fd=array_merge($this->_fd,$itemsatpriority); |
|
| 1361 | + } |
|
| 1291 | 1362 | return $this->_fd; |
| 1292 | 1363 | } |
| 1293 | 1364 | public function itemAt($index) |
@@ -1295,20 +1366,23 @@ discard block |
||
| 1295 | 1366 | if($index>=0&&$index<$this->getCount()) { |
| 1296 | 1367 | $arr=$this->flattenPriorities(); |
| 1297 | 1368 | return $arr[$index]; |
| 1298 | - } else |
|
| 1299 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 1369 | + } else { |
|
| 1370 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 1371 | + } |
|
| 1300 | 1372 | } |
| 1301 | 1373 | public function itemsAtPriority($priority=null) |
| 1302 | 1374 | { |
| 1303 | - if($priority===null) |
|
| 1304 | - $priority=$this->getDefaultPriority(); |
|
| 1375 | + if($priority===null) { |
|
| 1376 | + $priority=$this->getDefaultPriority(); |
|
| 1377 | + } |
|
| 1305 | 1378 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1306 | 1379 | return isset($this->_d[$priority])?$this->_d[$priority]:null; |
| 1307 | 1380 | } |
| 1308 | 1381 | public function itemAtIndexInPriority($index,$priority=null) |
| 1309 | 1382 | { |
| 1310 | - if($priority===null) |
|
| 1311 | - $priority=$this->getDefaultPriority(); |
|
| 1383 | + if($priority===null) { |
|
| 1384 | + $priority=$this->getDefaultPriority(); |
|
| 1385 | + } |
|
| 1312 | 1386 | $priority=(string)round(TPropertyValue::ensureFloat($priority), $this->_p); |
| 1313 | 1387 | return !isset($this->_d[$priority])?false:( |
| 1314 | 1388 | isset($this->_d[$priority][$index])?$this->_d[$priority][$index]:false |
@@ -1316,34 +1390,41 @@ discard block |
||
| 1316 | 1390 | } |
| 1317 | 1391 | public function add($item,$priority=null) |
| 1318 | 1392 | { |
| 1319 | - if($this->getReadOnly()) |
|
| 1320 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1393 | + if($this->getReadOnly()) { |
|
| 1394 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1395 | + } |
|
| 1321 | 1396 | return $this->insertAtIndexInPriority($item,false,$priority,true); |
| 1322 | 1397 | } |
| 1323 | 1398 | public function insertAt($index,$item) |
| 1324 | 1399 | { |
| 1325 | - if($this->getReadOnly()) |
|
| 1326 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1327 | - if(($priority=$this->priorityAt($index,true))!==false) |
|
| 1328 | - $this->insertAtIndexInPriority($item,$priority[1],$priority[0]); |
|
| 1329 | - else |
|
| 1330 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 1400 | + if($this->getReadOnly()) { |
|
| 1401 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1402 | + } |
|
| 1403 | + if(($priority=$this->priorityAt($index,true))!==false) { |
|
| 1404 | + $this->insertAtIndexInPriority($item,$priority[1],$priority[0]); |
|
| 1405 | + } else { |
|
| 1406 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 1407 | + } |
|
| 1331 | 1408 | } |
| 1332 | 1409 | public function insertAtIndexInPriority($item,$index=false,$priority=null,$preserveCache=false) |
| 1333 | 1410 | { |
| 1334 | - if($this->getReadOnly()) |
|
| 1335 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1336 | - if($priority===null) |
|
| 1337 | - $priority=$this->getDefaultPriority(); |
|
| 1411 | + if($this->getReadOnly()) { |
|
| 1412 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1413 | + } |
|
| 1414 | + if($priority===null) { |
|
| 1415 | + $priority=$this->getDefaultPriority(); |
|
| 1416 | + } |
|
| 1338 | 1417 | $priority=(string)round(TPropertyValue::ensureFloat($priority), $this->_p); |
| 1339 | 1418 | if($preserveCache) { |
| 1340 | 1419 | $this->sortPriorities(); |
| 1341 | 1420 | $cc=0; |
| 1342 | - foreach($this->_d as $prioritykey=>$items) |
|
| 1343 | - if($prioritykey>=$priority) |
|
| 1421 | + foreach($this->_d as $prioritykey=>$items) { |
|
| 1422 | + if($prioritykey>=$priority) |
|
| 1344 | 1423 | break; |
| 1345 | - else |
|
| 1346 | - $cc+=count($items); |
|
| 1424 | + } |
|
| 1425 | + else { |
|
| 1426 | + $cc+=count($items); |
|
| 1427 | + } |
|
| 1347 | 1428 | if($index===false&&isset($this->_d[$priority])) { |
| 1348 | 1429 | $c=count($this->_d[$priority]); |
| 1349 | 1430 | $c+=$cc; |
@@ -1356,7 +1437,9 @@ discard block |
||
| 1356 | 1437 | $this->_o = false; |
| 1357 | 1438 | $this->_d[$priority]=array($item); |
| 1358 | 1439 | } |
| 1359 | - if($this->_fd&&is_array($this->_fd)) array_splice($this->_fd,$c,0,array($item)); |
|
| 1440 | + if($this->_fd&&is_array($this->_fd)) { |
|
| 1441 | + array_splice($this->_fd,$c,0,array($item)); |
|
| 1442 | + } |
|
| 1360 | 1443 | } else { |
| 1361 | 1444 | $c=null; |
| 1362 | 1445 | if($index===false&&isset($this->_d[$priority])) { |
@@ -1370,66 +1453,78 @@ discard block |
||
| 1370 | 1453 | $this->_o=false; |
| 1371 | 1454 | $this->_d[$priority]=array($item); |
| 1372 | 1455 | } |
| 1373 | - if($this->_fd&&is_array($this->_fd)&&count($this->_d)==1) |
|
| 1374 | - array_splice($this->_fd,$cc,0,array($item)); |
|
| 1375 | - else |
|
| 1376 | - $this->_fd=null; |
|
| 1456 | + if($this->_fd&&is_array($this->_fd)&&count($this->_d)==1) { |
|
| 1457 | + array_splice($this->_fd,$cc,0,array($item)); |
|
| 1458 | + } else { |
|
| 1459 | + $this->_fd=null; |
|
| 1460 | + } |
|
| 1377 | 1461 | } |
| 1378 | 1462 | $this->_c++; |
| 1379 | 1463 | return $c; |
| 1380 | 1464 | } |
| 1381 | 1465 | public function remove($item,$priority=false) |
| 1382 | 1466 | { |
| 1383 | - if($this->getReadOnly()) |
|
| 1384 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1467 | + if($this->getReadOnly()) { |
|
| 1468 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1469 | + } |
|
| 1385 | 1470 | if(($p=$this->priorityOf($item,true))!==false) |
| 1386 | 1471 | { |
| 1387 | 1472 | if($priority!==false) { |
| 1388 | - if($priority===null) |
|
| 1389 | - $priority=$this->getDefaultPriority(); |
|
| 1473 | + if($priority===null) { |
|
| 1474 | + $priority=$this->getDefaultPriority(); |
|
| 1475 | + } |
|
| 1390 | 1476 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1391 | - if($p[0]!=$priority) |
|
| 1392 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1477 | + if($p[0]!=$priority) { |
|
| 1478 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1479 | + } |
|
| 1393 | 1480 | } |
| 1394 | 1481 | $this->removeAtIndexInPriority($p[1],$p[0]); |
| 1395 | 1482 | return $p[2]; |
| 1483 | + } else { |
|
| 1484 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1396 | 1485 | } |
| 1397 | - else |
|
| 1398 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1399 | 1486 | } |
| 1400 | 1487 | public function removeAt($index) |
| 1401 | 1488 | { |
| 1402 | - if($this->getReadOnly()) |
|
| 1403 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1404 | - if(($priority=$this->priorityAt($index, true))!==false) |
|
| 1405 | - return $this->removeAtIndexInPriority($priority[1],$priority[0]); |
|
| 1489 | + if($this->getReadOnly()) { |
|
| 1490 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1491 | + } |
|
| 1492 | + if(($priority=$this->priorityAt($index, true))!==false) { |
|
| 1493 | + return $this->removeAtIndexInPriority($priority[1],$priority[0]); |
|
| 1494 | + } |
|
| 1406 | 1495 | throw new TInvalidDataValueException('list_index_invalid',$index); |
| 1407 | 1496 | } |
| 1408 | 1497 | public function removeAtIndexInPriority($index, $priority=null) |
| 1409 | 1498 | { |
| 1410 | - if($this->getReadOnly()) |
|
| 1411 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1412 | - if($priority===null) |
|
| 1413 | - $priority=$this->getDefaultPriority(); |
|
| 1499 | + if($this->getReadOnly()) { |
|
| 1500 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1501 | + } |
|
| 1502 | + if($priority===null) { |
|
| 1503 | + $priority=$this->getDefaultPriority(); |
|
| 1504 | + } |
|
| 1414 | 1505 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1415 | - if(!isset($this->_d[$priority])||$index<0||$index>=count($this->_d[$priority])) |
|
| 1416 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1506 | + if(!isset($this->_d[$priority])||$index<0||$index>=count($this->_d[$priority])) { |
|
| 1507 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1508 | + } |
|
| 1417 | 1509 | $value=array_splice($this->_d[$priority],$index,1); |
| 1418 | 1510 | $value=$value[0]; |
| 1419 | - if(!count($this->_d[$priority])) |
|
| 1420 | - unset($this->_d[$priority]); |
|
| 1511 | + if(!count($this->_d[$priority])) { |
|
| 1512 | + unset($this->_d[$priority]); |
|
| 1513 | + } |
|
| 1421 | 1514 | $this->_c--; |
| 1422 | 1515 | $this->_fd=null; |
| 1423 | 1516 | return $value; |
| 1424 | 1517 | } |
| 1425 | 1518 | public function clear() |
| 1426 | 1519 | { |
| 1427 | - if($this->getReadOnly()) |
|
| 1428 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1520 | + if($this->getReadOnly()) { |
|
| 1521 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1522 | + } |
|
| 1429 | 1523 | $d=array_reverse($this->_d,true); |
| 1430 | 1524 | foreach($this->_d as $priority=>$items) { |
| 1431 | - for($index=count($items)-1;$index>=0;$index--) |
|
| 1432 | - $this->removeAtIndexInPriority($index,$priority); |
|
| 1525 | + for($index=count($items)-1;$index>=0;$index--) { |
|
| 1526 | + $this->removeAtIndexInPriority($index,$priority); |
|
| 1527 | + } |
|
| 1433 | 1528 | unset($this->_d[$priority]); |
| 1434 | 1529 | } |
| 1435 | 1530 | } |
@@ -1439,10 +1534,11 @@ discard block |
||
| 1439 | 1534 | } |
| 1440 | 1535 | public function indexOf($item) |
| 1441 | 1536 | { |
| 1442 | - if(($index=array_search($item,$this->flattenPriorities(),true))===false) |
|
| 1443 | - return -1; |
|
| 1444 | - else |
|
| 1445 | - return $index; |
|
| 1537 | + if(($index=array_search($item,$this->flattenPriorities(),true))===false) { |
|
| 1538 | + return -1; |
|
| 1539 | + } else { |
|
| 1540 | + return $index; |
|
| 1541 | + } |
|
| 1446 | 1542 | } |
| 1447 | 1543 | public function priorityOf($item,$withindex = false) |
| 1448 | 1544 | { |
@@ -1453,41 +1549,48 @@ discard block |
||
| 1453 | 1549 | $absindex+=$index; |
| 1454 | 1550 | return $withindex?array($priority,$index,$absindex, |
| 1455 | 1551 | 'priority'=>$priority,'index'=>$index,'absindex'=>$absindex):$priority; |
| 1456 | - } else |
|
| 1457 | - $absindex+=count($items); |
|
| 1552 | + } else { |
|
| 1553 | + $absindex+=count($items); |
|
| 1554 | + } |
|
| 1458 | 1555 | } |
| 1459 | 1556 | return false; |
| 1460 | 1557 | } |
| 1461 | 1558 | public function priorityAt($index,$withindex = false) |
| 1462 | 1559 | { |
| 1463 | - if($index<0||$index>=$this->getCount()) |
|
| 1464 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 1560 | + if($index<0||$index>=$this->getCount()) { |
|
| 1561 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
| 1562 | + } |
|
| 1465 | 1563 | $absindex=$index; |
| 1466 | 1564 | $this->sortPriorities(); |
| 1467 | 1565 | foreach($this->_d as $priority=>$items) { |
| 1468 | - if($index>=($c=count($items))) |
|
| 1469 | - $index-=$c; |
|
| 1470 | - else |
|
| 1471 | - return $withindex?array($priority,$index,$absindex, |
|
| 1566 | + if($index>=($c=count($items))) { |
|
| 1567 | + $index-=$c; |
|
| 1568 | + } else { |
|
| 1569 | + return $withindex?array($priority,$index,$absindex, |
|
| 1472 | 1570 | 'priority'=>$priority,'index'=>$index,'absindex'=>$absindex):$priority; |
| 1571 | + } |
|
| 1473 | 1572 | } |
| 1474 | 1573 | return false; |
| 1475 | 1574 | } |
| 1476 | 1575 | public function insertBefore($indexitem, $item) |
| 1477 | 1576 | { |
| 1478 | - if($this->getReadOnly()) |
|
| 1479 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1480 | - if(($priority=$this->priorityOf($indexitem,true))===false) |
|
| 1481 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1577 | + if($this->getReadOnly()) { |
|
| 1578 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1579 | + } |
|
| 1580 | + if(($priority=$this->priorityOf($indexitem,true))===false) { |
|
| 1581 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1582 | + } |
|
| 1482 | 1583 | $this->insertAtIndexInPriority($item,$priority[1],$priority[0]); |
| 1483 | 1584 | return $priority[2]; |
| 1484 | 1585 | } |
| 1485 | 1586 | public function insertAfter($indexitem, $item) |
| 1486 | 1587 | { |
| 1487 | - if($this->getReadOnly()) |
|
| 1488 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1489 | - if(($priority=$this->priorityOf($indexitem,true))===false) |
|
| 1490 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1588 | + if($this->getReadOnly()) { |
|
| 1589 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
| 1590 | + } |
|
| 1591 | + if(($priority=$this->priorityOf($indexitem,true))===false) { |
|
| 1592 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
| 1593 | + } |
|
| 1491 | 1594 | $this->insertAtIndexInPriority($item,$priority[1]+1,$priority[0]); |
| 1492 | 1595 | return $priority[2]+1; |
| 1493 | 1596 | } |
@@ -1506,8 +1609,9 @@ discard block |
||
| 1506 | 1609 | $items=array(); |
| 1507 | 1610 | foreach($this->_d as $itemspriority=>$itemsatpriority) |
| 1508 | 1611 | { |
| 1509 | - if((!$inclusive&&$itemspriority>=$priority)||$itemspriority>$priority) |
|
| 1510 | - break; |
|
| 1612 | + if((!$inclusive&&$itemspriority>=$priority)||$itemspriority>$priority) { |
|
| 1613 | + break; |
|
| 1614 | + } |
|
| 1511 | 1615 | $items=array_merge($items,$itemsatpriority); |
| 1512 | 1616 | } |
| 1513 | 1617 | return $items; |
@@ -1518,8 +1622,9 @@ discard block |
||
| 1518 | 1622 | $items=array(); |
| 1519 | 1623 | foreach($this->_d as $itemspriority=>$itemsatpriority) |
| 1520 | 1624 | { |
| 1521 | - if((!$inclusive&&$itemspriority<=$priority)||$itemspriority<$priority) |
|
| 1522 | - continue; |
|
| 1625 | + if((!$inclusive&&$itemspriority<=$priority)||$itemspriority<$priority) { |
|
| 1626 | + continue; |
|
| 1627 | + } |
|
| 1523 | 1628 | $items=array_merge($items,$itemsatpriority); |
| 1524 | 1629 | } |
| 1525 | 1630 | return $items; |
@@ -1528,20 +1633,25 @@ discard block |
||
| 1528 | 1633 | { |
| 1529 | 1634 | if($data instanceof TPriorityList) |
| 1530 | 1635 | { |
| 1531 | - if($this->getCount()>0) |
|
| 1532 | - $this->clear(); |
|
| 1636 | + if($this->getCount()>0) { |
|
| 1637 | + $this->clear(); |
|
| 1638 | + } |
|
| 1533 | 1639 | foreach($data->getPriorities() as $priority) |
| 1534 | 1640 | { |
| 1535 | - foreach($data->itemsAtPriority($priority) as $index=>$item) |
|
| 1536 | - $this->insertAtIndexInPriority($item,$index,$priority); |
|
| 1641 | + foreach($data->itemsAtPriority($priority) as $index=>$item) { |
|
| 1642 | + $this->insertAtIndexInPriority($item,$index,$priority); |
|
| 1643 | + } |
|
| 1537 | 1644 | } |
| 1538 | 1645 | } else if(is_array($data)||$data instanceof Traversable) { |
| 1539 | - if($this->getCount()>0) |
|
| 1540 | - $this->clear(); |
|
| 1541 | - foreach($data as $key=>$item) |
|
| 1542 | - $this->add($item); |
|
| 1543 | - } else if($data!==null) |
|
| 1544 | - throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1646 | + if($this->getCount()>0) { |
|
| 1647 | + $this->clear(); |
|
| 1648 | + } |
|
| 1649 | + foreach($data as $key=>$item) { |
|
| 1650 | + $this->add($item); |
|
| 1651 | + } |
|
| 1652 | + } else if($data!==null) { |
|
| 1653 | + throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1654 | + } |
|
| 1545 | 1655 | } |
| 1546 | 1656 | public function mergeWith($data) |
| 1547 | 1657 | { |
@@ -1549,17 +1659,18 @@ discard block |
||
| 1549 | 1659 | { |
| 1550 | 1660 | foreach($data->getPriorities() as $priority) |
| 1551 | 1661 | { |
| 1552 | - foreach($data->itemsAtPriority($priority) as $index=>$item) |
|
| 1553 | - $this->insertAtIndexInPriority($item,false,$priority); |
|
| 1662 | + foreach($data->itemsAtPriority($priority) as $index=>$item) { |
|
| 1663 | + $this->insertAtIndexInPriority($item,false,$priority); |
|
| 1664 | + } |
|
| 1554 | 1665 | } |
| 1555 | - } |
|
| 1556 | - else if(is_array($data)||$data instanceof Traversable) |
|
| 1666 | + } else if(is_array($data)||$data instanceof Traversable) |
|
| 1557 | 1667 | { |
| 1558 | - foreach($data as $priority=>$item) |
|
| 1559 | - $this->add($item); |
|
| 1668 | + foreach($data as $priority=>$item) { |
|
| 1669 | + $this->add($item); |
|
| 1670 | + } |
|
| 1671 | + } else if($data!==null) { |
|
| 1672 | + throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1560 | 1673 | } |
| 1561 | - else if($data!==null) |
|
| 1562 | - throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1563 | 1674 | } |
| 1564 | 1675 | public function offsetExists($offset) |
| 1565 | 1676 | { |
@@ -1571,8 +1682,9 @@ discard block |
||
| 1571 | 1682 | } |
| 1572 | 1683 | public function offsetSet($offset,$item) |
| 1573 | 1684 | { |
| 1574 | - if($offset===null) |
|
| 1575 | - return $this->add($item); |
|
| 1685 | + if($offset===null) { |
|
| 1686 | + return $this->add($item); |
|
| 1687 | + } |
|
| 1576 | 1688 | if($offset===$this->getCount()) { |
| 1577 | 1689 | $priority=$this->priorityAt($offset-1,true); |
| 1578 | 1690 | $priority[1]++; |
@@ -1594,15 +1706,18 @@ discard block |
||
| 1594 | 1706 | protected function __getZappableSleepProps(&$exprops) |
| 1595 | 1707 | { |
| 1596 | 1708 | parent::__getZappableSleepProps($exprops); |
| 1597 | - if ($this->_d===array()) |
|
| 1598 | - $exprops[] = "\0TMap\0_d"; |
|
| 1599 | - if ($this->_r===false) |
|
| 1600 | - $exprops[] = "\0TMap\0_r"; |
|
| 1709 | + if ($this->_d===array()) { |
|
| 1710 | + $exprops[] = "\0TMap\0_d"; |
|
| 1711 | + } |
|
| 1712 | + if ($this->_r===false) { |
|
| 1713 | + $exprops[] = "\0TMap\0_r"; |
|
| 1714 | + } |
|
| 1601 | 1715 | } |
| 1602 | 1716 | public function __construct($data=null,$readOnly=false) |
| 1603 | 1717 | { |
| 1604 | - if($data!==null) |
|
| 1605 | - $this->copyFrom($data); |
|
| 1718 | + if($data!==null) { |
|
| 1719 | + $this->copyFrom($data); |
|
| 1720 | + } |
|
| 1606 | 1721 | $this->setReadOnly($readOnly); |
| 1607 | 1722 | } |
| 1608 | 1723 | public function getReadOnly() |
@@ -1635,10 +1750,11 @@ discard block |
||
| 1635 | 1750 | } |
| 1636 | 1751 | public function add($key,$value) |
| 1637 | 1752 | { |
| 1638 | - if(!$this->_r) |
|
| 1639 | - $this->_d[$key]=$value; |
|
| 1640 | - else |
|
| 1641 | - throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
| 1753 | + if(!$this->_r) { |
|
| 1754 | + $this->_d[$key]=$value; |
|
| 1755 | + } else { |
|
| 1756 | + throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
| 1757 | + } |
|
| 1642 | 1758 | } |
| 1643 | 1759 | public function remove($key) |
| 1644 | 1760 | { |
@@ -1649,17 +1765,18 @@ discard block |
||
| 1649 | 1765 | $value=$this->_d[$key]; |
| 1650 | 1766 | unset($this->_d[$key]); |
| 1651 | 1767 | return $value; |
| 1768 | + } else { |
|
| 1769 | + return null; |
|
| 1652 | 1770 | } |
| 1653 | - else |
|
| 1654 | - return null; |
|
| 1771 | + } else { |
|
| 1772 | + throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
| 1655 | 1773 | } |
| 1656 | - else |
|
| 1657 | - throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
| 1658 | 1774 | } |
| 1659 | 1775 | public function clear() |
| 1660 | 1776 | { |
| 1661 | - foreach(array_keys($this->_d) as $key) |
|
| 1662 | - $this->remove($key); |
|
| 1777 | + foreach(array_keys($this->_d) as $key) { |
|
| 1778 | + $this->remove($key); |
|
| 1779 | + } |
|
| 1663 | 1780 | } |
| 1664 | 1781 | public function contains($key) |
| 1665 | 1782 | { |
@@ -1673,23 +1790,26 @@ discard block |
||
| 1673 | 1790 | { |
| 1674 | 1791 | if(is_array($data) || $data instanceof Traversable) |
| 1675 | 1792 | { |
| 1676 | - if($this->getCount()>0) |
|
| 1677 | - $this->clear(); |
|
| 1678 | - foreach($data as $key=>$value) |
|
| 1679 | - $this->add($key,$value); |
|
| 1793 | + if($this->getCount()>0) { |
|
| 1794 | + $this->clear(); |
|
| 1795 | + } |
|
| 1796 | + foreach($data as $key=>$value) { |
|
| 1797 | + $this->add($key,$value); |
|
| 1798 | + } |
|
| 1799 | + } else if($data!==null) { |
|
| 1800 | + throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1680 | 1801 | } |
| 1681 | - else if($data!==null) |
|
| 1682 | - throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1683 | 1802 | } |
| 1684 | 1803 | public function mergeWith($data) |
| 1685 | 1804 | { |
| 1686 | 1805 | if(is_array($data) || $data instanceof Traversable) |
| 1687 | 1806 | { |
| 1688 | - foreach($data as $key=>$value) |
|
| 1689 | - $this->add($key,$value); |
|
| 1807 | + foreach($data as $key=>$value) { |
|
| 1808 | + $this->add($key,$value); |
|
| 1809 | + } |
|
| 1810 | + } else if($data!==null) { |
|
| 1811 | + throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1690 | 1812 | } |
| 1691 | - else if($data!==null) |
|
| 1692 | - throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1693 | 1813 | } |
| 1694 | 1814 | public function offsetExists($offset) |
| 1695 | 1815 | { |
@@ -1722,8 +1842,9 @@ discard block |
||
| 1722 | 1842 | private $_p=8; |
| 1723 | 1843 | public function __construct($data=null,$readOnly=false,$defaultPriority=10,$precision=8) |
| 1724 | 1844 | { |
| 1725 | - if($data!==null) |
|
| 1726 | - $this->copyFrom($data); |
|
| 1845 | + if($data!==null) { |
|
| 1846 | + $this->copyFrom($data); |
|
| 1847 | + } |
|
| 1727 | 1848 | $this->setReadOnly($readOnly); |
| 1728 | 1849 | $this->setPrecision($precision); |
| 1729 | 1850 | $this->setDefaultPriority($defaultPriority); |
@@ -1763,12 +1884,14 @@ discard block |
||
| 1763 | 1884 | } |
| 1764 | 1885 | } |
| 1765 | 1886 | protected function flattenPriorities() { |
| 1766 | - if(is_array($this->_fd)) |
|
| 1767 | - return $this->_fd; |
|
| 1887 | + if(is_array($this->_fd)) { |
|
| 1888 | + return $this->_fd; |
|
| 1889 | + } |
|
| 1768 | 1890 | $this->sortPriorities(); |
| 1769 | 1891 | $this->_fd = array(); |
| 1770 | - foreach($this->_d as $priority => $itemsatpriority) |
|
| 1771 | - $this->_fd = array_merge($this->_fd, $itemsatpriority); |
|
| 1892 | + foreach($this->_d as $priority => $itemsatpriority) { |
|
| 1893 | + $this->_fd = array_merge($this->_fd, $itemsatpriority); |
|
| 1894 | + } |
|
| 1772 | 1895 | return $this->_fd; |
| 1773 | 1896 | } |
| 1774 | 1897 | public function count() |
@@ -1781,11 +1904,13 @@ discard block |
||
| 1781 | 1904 | } |
| 1782 | 1905 | public function getPriorityCount($priority=null) |
| 1783 | 1906 | { |
| 1784 | - if($priority===null) |
|
| 1785 | - $priority=$this->getDefaultPriority(); |
|
| 1907 | + if($priority===null) { |
|
| 1908 | + $priority=$this->getDefaultPriority(); |
|
| 1909 | + } |
|
| 1786 | 1910 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1787 | - if(!isset($this->_d[$priority])||!is_array($this->_d[$priority])) |
|
| 1788 | - return false; |
|
| 1911 | + if(!isset($this->_d[$priority])||!is_array($this->_d[$priority])) { |
|
| 1912 | + return false; |
|
| 1913 | + } |
|
| 1789 | 1914 | return count($this->_d[$priority]); |
| 1790 | 1915 | } |
| 1791 | 1916 | public function getPriorities() |
@@ -1803,16 +1928,18 @@ discard block |
||
| 1803 | 1928 | $map=$this->flattenPriorities(); |
| 1804 | 1929 | return isset($map[$key])?$map[$key]:null; |
| 1805 | 1930 | } else { |
| 1806 | - if($priority===null) |
|
| 1807 | - $priority=$this->getDefaultPriority(); |
|
| 1931 | + if($priority===null) { |
|
| 1932 | + $priority=$this->getDefaultPriority(); |
|
| 1933 | + } |
|
| 1808 | 1934 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1809 | 1935 | return (isset($this->_d[$priority])&&isset($this->_d[$priority][$key]))?$this->_d[$priority][$key]:null; |
| 1810 | 1936 | } |
| 1811 | 1937 | } |
| 1812 | 1938 | public function setPriorityAt($key,$priority=null) |
| 1813 | 1939 | { |
| 1814 | - if($priority===null) |
|
| 1815 | - $priority=$this->getDefaultPriority(); |
|
| 1940 | + if($priority===null) { |
|
| 1941 | + $priority=$this->getDefaultPriority(); |
|
| 1942 | + } |
|
| 1816 | 1943 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1817 | 1944 | $oldpriority=$this->priorityAt($key); |
| 1818 | 1945 | if($oldpriority!==false&&$oldpriority!=$priority) { |
@@ -1823,68 +1950,76 @@ discard block |
||
| 1823 | 1950 | } |
| 1824 | 1951 | public function itemsAtPriority($priority=null) |
| 1825 | 1952 | { |
| 1826 | - if($priority===null) |
|
| 1827 | - $priority=$this->getDefaultPriority(); |
|
| 1953 | + if($priority===null) { |
|
| 1954 | + $priority=$this->getDefaultPriority(); |
|
| 1955 | + } |
|
| 1828 | 1956 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1829 | 1957 | return isset($this->_d[$priority])?$this->_d[$priority]:null; |
| 1830 | 1958 | } |
| 1831 | 1959 | public function priorityOf($item) |
| 1832 | 1960 | { |
| 1833 | 1961 | $this->sortPriorities(); |
| 1834 | - foreach($this->_d as $priority=>$items) |
|
| 1835 | - if(($index=array_search($item,$items,true))!==false) |
|
| 1962 | + foreach($this->_d as $priority=>$items) { |
|
| 1963 | + if(($index=array_search($item,$items,true))!==false) |
|
| 1836 | 1964 | return $priority; |
| 1965 | + } |
|
| 1837 | 1966 | return false; |
| 1838 | 1967 | } |
| 1839 | 1968 | public function priorityAt($key) |
| 1840 | 1969 | { |
| 1841 | 1970 | $this->sortPriorities(); |
| 1842 | - foreach($this->_d as $priority=>$items) |
|
| 1843 | - if(array_key_exists($key,$items)) |
|
| 1971 | + foreach($this->_d as $priority=>$items) { |
|
| 1972 | + if(array_key_exists($key,$items)) |
|
| 1844 | 1973 | return $priority; |
| 1974 | + } |
|
| 1845 | 1975 | return false; |
| 1846 | 1976 | } |
| 1847 | 1977 | public function add($key,$value,$priority=null) |
| 1848 | 1978 | { |
| 1849 | - if($priority===null) |
|
| 1850 | - $priority=$this->getDefaultPriority(); |
|
| 1979 | + if($priority===null) { |
|
| 1980 | + $priority=$this->getDefaultPriority(); |
|
| 1981 | + } |
|
| 1851 | 1982 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1852 | 1983 | if(!$this->_r) |
| 1853 | 1984 | { |
| 1854 | - foreach($this->_d as $innerpriority=>$items) |
|
| 1855 | - if(array_key_exists($key,$items)) |
|
| 1985 | + foreach($this->_d as $innerpriority=>$items) { |
|
| 1986 | + if(array_key_exists($key,$items)) |
|
| 1856 | 1987 | { |
| 1857 | 1988 | unset($this->_d[$innerpriority][$key]); |
| 1989 | + } |
|
| 1858 | 1990 | $this->_c--; |
| 1859 | - if(count($this->_d[$innerpriority])===0) |
|
| 1860 | - unset($this->_d[$innerpriority]); |
|
| 1991 | + if(count($this->_d[$innerpriority])===0) { |
|
| 1992 | + unset($this->_d[$innerpriority]); |
|
| 1993 | + } |
|
| 1861 | 1994 | } |
| 1862 | 1995 | if(!isset($this->_d[$priority])) { |
| 1863 | 1996 | $this->_d[$priority]=array($key=>$value); |
| 1864 | 1997 | $this->_o=false; |
| 1998 | + } else { |
|
| 1999 | + $this->_d[$priority][$key]=$value; |
|
| 1865 | 2000 | } |
| 1866 | - else |
|
| 1867 | - $this->_d[$priority][$key]=$value; |
|
| 1868 | 2001 | $this->_c++; |
| 1869 | 2002 | $this->_fd=null; |
| 2003 | + } else { |
|
| 2004 | + throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
| 1870 | 2005 | } |
| 1871 | - else |
|
| 1872 | - throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
| 1873 | 2006 | return $priority; |
| 1874 | 2007 | } |
| 1875 | 2008 | public function remove($key,$priority=false) |
| 1876 | 2009 | { |
| 1877 | 2010 | if(!$this->_r) |
| 1878 | 2011 | { |
| 1879 | - if($priority===null) |
|
| 1880 | - $priority=$this->getDefaultPriority(); |
|
| 2012 | + if($priority===null) { |
|
| 2013 | + $priority=$this->getDefaultPriority(); |
|
| 2014 | + } |
|
| 1881 | 2015 | if($priority===false) |
| 1882 | 2016 | { |
| 1883 | 2017 | $this->sortPriorities(); |
| 1884 | - foreach($this->_d as $priority=>$items) |
|
| 1885 | - if(array_key_exists($key,$items)) |
|
| 2018 | + foreach($this->_d as $priority=>$items) { |
|
| 2019 | + if(array_key_exists($key,$items)) |
|
| 1886 | 2020 | { |
| 1887 | 2021 | $value=$this->_d[$priority][$key]; |
| 2022 | + } |
|
| 1888 | 2023 | unset($this->_d[$priority][$key]); |
| 1889 | 2024 | $this->_c--; |
| 1890 | 2025 | if(count($this->_d[$priority])===0) |
@@ -1896,8 +2031,7 @@ discard block |
||
| 1896 | 2031 | return $value; |
| 1897 | 2032 | } |
| 1898 | 2033 | return null; |
| 1899 | - } |
|
| 1900 | - else |
|
| 2034 | + } else |
|
| 1901 | 2035 | { |
| 1902 | 2036 | $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p); |
| 1903 | 2037 | if(isset($this->_d[$priority])&&(isset($this->_d[$priority][$key])||array_key_exists($key,$this->_d[$priority]))) |
@@ -1911,19 +2045,20 @@ discard block |
||
| 1911 | 2045 | } |
| 1912 | 2046 | $this->_fd=null; |
| 1913 | 2047 | return $value; |
| 2048 | + } else { |
|
| 2049 | + return null; |
|
| 1914 | 2050 | } |
| 1915 | - else |
|
| 1916 | - return null; |
|
| 1917 | 2051 | } |
| 2052 | + } else { |
|
| 2053 | + throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
| 1918 | 2054 | } |
| 1919 | - else |
|
| 1920 | - throw new TInvalidOperationException('map_readonly',get_class($this)); |
|
| 1921 | 2055 | } |
| 1922 | 2056 | public function clear() |
| 1923 | 2057 | { |
| 1924 | - foreach($this->_d as $priority=>$items) |
|
| 1925 | - foreach(array_keys($items) as $key) |
|
| 2058 | + foreach($this->_d as $priority=>$items) { |
|
| 2059 | + foreach(array_keys($items) as $key) |
|
| 1926 | 2060 | $this->remove($key); |
| 2061 | + } |
|
| 1927 | 2062 | } |
| 1928 | 2063 | public function contains($key) |
| 1929 | 2064 | { |
@@ -1940,8 +2075,9 @@ discard block |
||
| 1940 | 2075 | $items=array(); |
| 1941 | 2076 | foreach($this->_d as $itemspriority=>$itemsatpriority) |
| 1942 | 2077 | { |
| 1943 | - if((!$inclusive&&$itemspriority>=$priority)||$itemspriority>$priority) |
|
| 1944 | - break; |
|
| 2078 | + if((!$inclusive&&$itemspriority>=$priority)||$itemspriority>$priority) { |
|
| 2079 | + break; |
|
| 2080 | + } |
|
| 1945 | 2081 | $items=array_merge($items,$itemsatpriority); |
| 1946 | 2082 | } |
| 1947 | 2083 | return $items; |
@@ -1952,8 +2088,9 @@ discard block |
||
| 1952 | 2088 | $items=array(); |
| 1953 | 2089 | foreach($this->_d as $itemspriority=>$itemsatpriority) |
| 1954 | 2090 | { |
| 1955 | - if((!$inclusive&&$itemspriority<=$priority)||$itemspriority<$priority) |
|
| 1956 | - continue; |
|
| 2091 | + if((!$inclusive&&$itemspriority<=$priority)||$itemspriority<$priority) { |
|
| 2092 | + continue; |
|
| 2093 | + } |
|
| 1957 | 2094 | $items=array_merge($items,$itemsatpriority); |
| 1958 | 2095 | } |
| 1959 | 2096 | return $items; |
@@ -1962,23 +2099,25 @@ discard block |
||
| 1962 | 2099 | { |
| 1963 | 2100 | if($data instanceof TPriorityMap) |
| 1964 | 2101 | { |
| 1965 | - if($this->getCount()>0) |
|
| 1966 | - $this->clear(); |
|
| 2102 | + if($this->getCount()>0) { |
|
| 2103 | + $this->clear(); |
|
| 2104 | + } |
|
| 1967 | 2105 | foreach($data->getPriorities() as $priority) { |
| 1968 | 2106 | foreach($data->itemsAtPriority($priority) as $key => $value) { |
| 1969 | 2107 | $this->add($key,$value,$priority); |
| 1970 | 2108 | } |
| 1971 | 2109 | } |
| 1972 | - } |
|
| 1973 | - else if(is_array($data)||$data instanceof Traversable) |
|
| 2110 | + } else if(is_array($data)||$data instanceof Traversable) |
|
| 1974 | 2111 | { |
| 1975 | - if($this->getCount()>0) |
|
| 1976 | - $this->clear(); |
|
| 1977 | - foreach($data as $key=>$value) |
|
| 1978 | - $this->add($key,$value); |
|
| 2112 | + if($this->getCount()>0) { |
|
| 2113 | + $this->clear(); |
|
| 2114 | + } |
|
| 2115 | + foreach($data as $key=>$value) { |
|
| 2116 | + $this->add($key,$value); |
|
| 2117 | + } |
|
| 2118 | + } else if($data!==null) { |
|
| 2119 | + throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1979 | 2120 | } |
| 1980 | - else if($data!==null) |
|
| 1981 | - throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1982 | 2121 | } |
| 1983 | 2122 | public function mergeWith($data) |
| 1984 | 2123 | { |
@@ -1986,17 +2125,18 @@ discard block |
||
| 1986 | 2125 | { |
| 1987 | 2126 | foreach($data->getPriorities() as $priority) |
| 1988 | 2127 | { |
| 1989 | - foreach($data->itemsAtPriority($priority) as $key => $value) |
|
| 1990 | - $this->add($key,$value,$priority); |
|
| 2128 | + foreach($data->itemsAtPriority($priority) as $key => $value) { |
|
| 2129 | + $this->add($key,$value,$priority); |
|
| 2130 | + } |
|
| 1991 | 2131 | } |
| 1992 | - } |
|
| 1993 | - else if(is_array($data)||$data instanceof Traversable) |
|
| 2132 | + } else if(is_array($data)||$data instanceof Traversable) |
|
| 1994 | 2133 | { |
| 1995 | - foreach($data as $key=>$value) |
|
| 1996 | - $this->add($key,$value); |
|
| 2134 | + foreach($data as $key=>$value) { |
|
| 2135 | + $this->add($key,$value); |
|
| 2136 | + } |
|
| 2137 | + } else if($data!==null) { |
|
| 2138 | + throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 1997 | 2139 | } |
| 1998 | - else if($data!==null) |
|
| 1999 | - throw new TInvalidDataTypeException('map_data_not_iterable'); |
|
| 2000 | 2140 | } |
| 2001 | 2141 | public function offsetExists($offset) |
| 2002 | 2142 | { |
@@ -2021,8 +2161,9 @@ discard block |
||
| 2021 | 2161 | private $_c=0; |
| 2022 | 2162 | public function __construct($data=null) |
| 2023 | 2163 | { |
| 2024 | - if($data!==null) |
|
| 2025 | - $this->copyFrom($data); |
|
| 2164 | + if($data!==null) { |
|
| 2165 | + $this->copyFrom($data); |
|
| 2166 | + } |
|
| 2026 | 2167 | } |
| 2027 | 2168 | public function toArray() |
| 2028 | 2169 | { |
@@ -2038,9 +2179,9 @@ discard block |
||
| 2038 | 2179 | $this->_d[]=$item; |
| 2039 | 2180 | ++$this->_c; |
| 2040 | 2181 | } |
| 2182 | + } else if($data!==null) { |
|
| 2183 | + throw new TInvalidDataTypeException('stack_data_not_iterable'); |
|
| 2041 | 2184 | } |
| 2042 | - else if($data!==null) |
|
| 2043 | - throw new TInvalidDataTypeException('stack_data_not_iterable'); |
|
| 2044 | 2185 | } |
| 2045 | 2186 | public function clear() |
| 2046 | 2187 | { |
@@ -2053,16 +2194,17 @@ discard block |
||
| 2053 | 2194 | } |
| 2054 | 2195 | public function peek() |
| 2055 | 2196 | { |
| 2056 | - if($this->_c===0) |
|
| 2057 | - throw new TInvalidOperationException('stack_empty'); |
|
| 2058 | - else |
|
| 2059 | - return $this->_d[$this->_c-1]; |
|
| 2197 | + if($this->_c===0) { |
|
| 2198 | + throw new TInvalidOperationException('stack_empty'); |
|
| 2199 | + } else { |
|
| 2200 | + return $this->_d[$this->_c-1]; |
|
| 2201 | + } |
|
| 2060 | 2202 | } |
| 2061 | 2203 | public function pop() |
| 2062 | 2204 | { |
| 2063 | - if($this->_c===0) |
|
| 2064 | - throw new TInvalidOperationException('stack_empty'); |
|
| 2065 | - else |
|
| 2205 | + if($this->_c===0) { |
|
| 2206 | + throw new TInvalidOperationException('stack_empty'); |
|
| 2207 | + } else |
|
| 2066 | 2208 | { |
| 2067 | 2209 | --$this->_c; |
| 2068 | 2210 | return array_pop($this->_d); |
@@ -2163,10 +2305,11 @@ discard block |
||
| 2163 | 2305 | } |
| 2164 | 2306 | public function getAttribute($name) |
| 2165 | 2307 | { |
| 2166 | - if($this->_attributes!==null) |
|
| 2167 | - return $this->_attributes->itemAt($name); |
|
| 2168 | - else |
|
| 2169 | - return null; |
|
| 2308 | + if($this->_attributes!==null) { |
|
| 2309 | + return $this->_attributes->itemAt($name); |
|
| 2310 | + } else { |
|
| 2311 | + return null; |
|
| 2312 | + } |
|
| 2170 | 2313 | } |
| 2171 | 2314 | public function setAttribute($name,$value) |
| 2172 | 2315 | { |
@@ -2174,23 +2317,26 @@ discard block |
||
| 2174 | 2317 | } |
| 2175 | 2318 | public function getElements() |
| 2176 | 2319 | { |
| 2177 | - if(!$this->_elements) |
|
| 2178 | - $this->_elements=new TXmlElementList($this); |
|
| 2320 | + if(!$this->_elements) { |
|
| 2321 | + $this->_elements=new TXmlElementList($this); |
|
| 2322 | + } |
|
| 2179 | 2323 | return $this->_elements; |
| 2180 | 2324 | } |
| 2181 | 2325 | public function getAttributes() |
| 2182 | 2326 | { |
| 2183 | - if(!$this->_attributes) |
|
| 2184 | - $this->_attributes=new TMap; |
|
| 2327 | + if(!$this->_attributes) { |
|
| 2328 | + $this->_attributes=new TMap; |
|
| 2329 | + } |
|
| 2185 | 2330 | return $this->_attributes; |
| 2186 | 2331 | } |
| 2187 | 2332 | public function getElementByTagName($tagName) |
| 2188 | 2333 | { |
| 2189 | 2334 | if($this->_elements) |
| 2190 | 2335 | { |
| 2191 | - foreach($this->_elements as $element) |
|
| 2192 | - if($element->_tagName===$tagName) |
|
| 2336 | + foreach($this->_elements as $element) { |
|
| 2337 | + if($element->_tagName===$tagName) |
|
| 2193 | 2338 | return $element; |
| 2339 | + } |
|
| 2194 | 2340 | } |
| 2195 | 2341 | return null; |
| 2196 | 2342 | } |
@@ -2199,9 +2345,10 @@ discard block |
||
| 2199 | 2345 | $list=new TList; |
| 2200 | 2346 | if($this->_elements) |
| 2201 | 2347 | { |
| 2202 | - foreach($this->_elements as $element) |
|
| 2203 | - if($element->_tagName===$tagName) |
|
| 2348 | + foreach($this->_elements as $element) { |
|
| 2349 | + if($element->_tagName===$tagName) |
|
| 2204 | 2350 | $list->add($element); |
| 2351 | + } |
|
| 2205 | 2352 | } |
| 2206 | 2353 | return $list; |
| 2207 | 2354 | } |
@@ -2220,18 +2367,18 @@ discard block |
||
| 2220 | 2367 | if($this->getHasElement()) |
| 2221 | 2368 | { |
| 2222 | 2369 | $str=$prefix."<{$this->_tagName}$attr>\n"; |
| 2223 | - foreach($this->getElements() as $element) |
|
| 2224 | - $str.=$element->toString($indent+1)."\n"; |
|
| 2370 | + foreach($this->getElements() as $element) { |
|
| 2371 | + $str.=$element->toString($indent+1)."\n"; |
|
| 2372 | + } |
|
| 2225 | 2373 | $str.=$prefix."</{$this->_tagName}>"; |
| 2226 | 2374 | return $str; |
| 2227 | - } |
|
| 2228 | - else if(($value=$this->getValue())!=='') |
|
| 2375 | + } else if(($value=$this->getValue())!=='') |
|
| 2229 | 2376 | { |
| 2230 | 2377 | $value=$this->xmlEncode($value); |
| 2231 | 2378 | return $prefix."<{$this->_tagName}$attr>$value</{$this->_tagName}>"; |
| 2379 | + } else { |
|
| 2380 | + return $prefix."<{$this->_tagName}$attr />"; |
|
| 2232 | 2381 | } |
| 2233 | - else |
|
| 2234 | - return $prefix."<{$this->_tagName}$attr />"; |
|
| 2235 | 2382 | } |
| 2236 | 2383 | public function __toString() |
| 2237 | 2384 | { |
@@ -2277,16 +2424,18 @@ discard block |
||
| 2277 | 2424 | } |
| 2278 | 2425 | public function loadFromFile($file) |
| 2279 | 2426 | { |
| 2280 | - if(($str=@file_get_contents($file))!==false) |
|
| 2281 | - return $this->loadFromString($str); |
|
| 2282 | - else |
|
| 2283 | - throw new TIOException('xmldocument_file_read_failed',$file); |
|
| 2427 | + if(($str=@file_get_contents($file))!==false) { |
|
| 2428 | + return $this->loadFromString($str); |
|
| 2429 | + } else { |
|
| 2430 | + throw new TIOException('xmldocument_file_read_failed',$file); |
|
| 2431 | + } |
|
| 2284 | 2432 | } |
| 2285 | 2433 | public function loadFromString($string) |
| 2286 | 2434 | { |
| 2287 | 2435 | $doc=new DOMDocument(); |
| 2288 | - if($doc->loadXML($string)===false) |
|
| 2289 | - return false; |
|
| 2436 | + if($doc->loadXML($string)===false) { |
|
| 2437 | + return false; |
|
| 2438 | + } |
|
| 2290 | 2439 | $this->setEncoding($doc->encoding); |
| 2291 | 2440 | $this->setVersion($doc->xmlVersion); |
| 2292 | 2441 | $element=$doc->documentElement; |
@@ -2297,8 +2446,9 @@ discard block |
||
| 2297 | 2446 | $elements->clear(); |
| 2298 | 2447 | $attributes->clear(); |
| 2299 | 2448 | static $bSimpleXml; |
| 2300 | - if($bSimpleXml === null) |
|
| 2301 | - $bSimpleXml = (boolean)function_exists('simplexml_load_string'); |
|
| 2449 | + if($bSimpleXml === null) { |
|
| 2450 | + $bSimpleXml = (boolean)function_exists('simplexml_load_string'); |
|
| 2451 | + } |
|
| 2302 | 2452 | if($bSimpleXml) |
| 2303 | 2453 | { |
| 2304 | 2454 | $simpleDoc = simplexml_load_string($string); |
@@ -2306,18 +2456,21 @@ discard block |
||
| 2306 | 2456 | $simpleDoc = null; |
| 2307 | 2457 | foreach($docNamespaces as $prefix => $uri) |
| 2308 | 2458 | { |
| 2309 | - if($prefix === '') |
|
| 2310 | - $attributes->add('xmlns', $uri); |
|
| 2311 | - else |
|
| 2312 | - $attributes->add('xmlns:'.$prefix, $uri); |
|
| 2459 | + if($prefix === '') { |
|
| 2460 | + $attributes->add('xmlns', $uri); |
|
| 2461 | + } else { |
|
| 2462 | + $attributes->add('xmlns:'.$prefix, $uri); |
|
| 2463 | + } |
|
| 2313 | 2464 | } |
| 2314 | 2465 | } |
| 2315 | - foreach($element->attributes as $name=>$attr) |
|
| 2316 | - $attributes->add(($attr->prefix === '' ? '' : $attr->prefix . ':') .$name,$attr->value); |
|
| 2466 | + foreach($element->attributes as $name=>$attr) { |
|
| 2467 | + $attributes->add(($attr->prefix === '' ? '' : $attr->prefix . ':') .$name,$attr->value); |
|
| 2468 | + } |
|
| 2317 | 2469 | foreach($element->childNodes as $child) |
| 2318 | 2470 | { |
| 2319 | - if($child instanceof DOMElement) |
|
| 2320 | - $elements->add($this->buildElement($child)); |
|
| 2471 | + if($child instanceof DOMElement) { |
|
| 2472 | + $elements->add($this->buildElement($child)); |
|
| 2473 | + } |
|
| 2321 | 2474 | } |
| 2322 | 2475 | return true; |
| 2323 | 2476 | } |
@@ -2327,9 +2480,9 @@ discard block |
||
| 2327 | 2480 | { |
| 2328 | 2481 | fwrite($fw,$this->saveToString()); |
| 2329 | 2482 | fclose($fw); |
| 2483 | + } else { |
|
| 2484 | + throw new TIOException('xmldocument_file_write_failed',$file); |
|
| 2330 | 2485 | } |
| 2331 | - else |
|
| 2332 | - throw new TIOException('xmldocument_file_write_failed',$file); |
|
| 2333 | 2486 | } |
| 2334 | 2487 | public function saveToString() |
| 2335 | 2488 | { |
@@ -2345,12 +2498,14 @@ discard block |
||
| 2345 | 2498 | { |
| 2346 | 2499 | $element=new TXmlElement($node->tagName); |
| 2347 | 2500 | $element->setValue($node->nodeValue); |
| 2348 | - foreach($node->attributes as $name=>$attr) |
|
| 2349 | - $element->getAttributes()->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name,$attr->value); |
|
| 2501 | + foreach($node->attributes as $name=>$attr) { |
|
| 2502 | + $element->getAttributes()->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name,$attr->value); |
|
| 2503 | + } |
|
| 2350 | 2504 | foreach($node->childNodes as $child) |
| 2351 | 2505 | { |
| 2352 | - if($child instanceof DOMElement) |
|
| 2353 | - $element->getElements()->add($this->buildElement($child)); |
|
| 2506 | + if($child instanceof DOMElement) { |
|
| 2507 | + $element->getElements()->add($this->buildElement($child)); |
|
| 2508 | + } |
|
| 2354 | 2509 | } |
| 2355 | 2510 | return $element; |
| 2356 | 2511 | } |
@@ -2371,18 +2526,20 @@ discard block |
||
| 2371 | 2526 | if($item instanceof TXmlElement) |
| 2372 | 2527 | { |
| 2373 | 2528 | parent::insertAt($index,$item); |
| 2374 | - if($item->getParent()!==null) |
|
| 2375 | - $item->getParent()->getElements()->remove($item); |
|
| 2529 | + if($item->getParent()!==null) { |
|
| 2530 | + $item->getParent()->getElements()->remove($item); |
|
| 2531 | + } |
|
| 2376 | 2532 | $item->setParent($this->_o); |
| 2533 | + } else { |
|
| 2534 | + throw new TInvalidDataTypeException('xmlelementlist_xmlelement_required'); |
|
| 2377 | 2535 | } |
| 2378 | - else |
|
| 2379 | - throw new TInvalidDataTypeException('xmlelementlist_xmlelement_required'); |
|
| 2380 | 2536 | } |
| 2381 | 2537 | public function removeAt($index) |
| 2382 | 2538 | { |
| 2383 | 2539 | $item=parent::removeAt($index); |
| 2384 | - if($item instanceof TXmlElement) |
|
| 2385 | - $item->setParent(null); |
|
| 2540 | + if($item instanceof TXmlElement) { |
|
| 2541 | + $item->setParent(null); |
|
| 2542 | + } |
|
| 2386 | 2543 | return $item; |
| 2387 | 2544 | } |
| 2388 | 2545 | } |
@@ -2399,18 +2556,20 @@ discard block |
||
| 2399 | 2556 | public function __construct($action,$users,$roles,$verb='',$ipRules='') |
| 2400 | 2557 | { |
| 2401 | 2558 | $action=strtolower(trim($action)); |
| 2402 | - if($action==='allow' || $action==='deny') |
|
| 2403 | - $this->_action=$action; |
|
| 2404 | - else |
|
| 2405 | - throw new TInvalidDataValueException('authorizationrule_action_invalid',$action); |
|
| 2559 | + if($action==='allow' || $action==='deny') { |
|
| 2560 | + $this->_action=$action; |
|
| 2561 | + } else { |
|
| 2562 | + throw new TInvalidDataValueException('authorizationrule_action_invalid',$action); |
|
| 2563 | + } |
|
| 2406 | 2564 | $this->_users=array(); |
| 2407 | 2565 | $this->_roles=array(); |
| 2408 | 2566 | $this->_ipRules=array(); |
| 2409 | 2567 | $this->_everyone=false; |
| 2410 | 2568 | $this->_guest=false; |
| 2411 | 2569 | $this->_authenticated=false; |
| 2412 | - if(trim($users)==='') |
|
| 2413 | - $users='*'; |
|
| 2570 | + if(trim($users)==='') { |
|
| 2571 | + $users='*'; |
|
| 2572 | + } |
|
| 2414 | 2573 | foreach(explode(',',$users) as $user) |
| 2415 | 2574 | { |
| 2416 | 2575 | if(($user=trim(strtolower($user)))!=='') |
@@ -2419,34 +2578,40 @@ discard block |
||
| 2419 | 2578 | { |
| 2420 | 2579 | $this->_everyone=true; |
| 2421 | 2580 | break; |
| 2581 | + } else if($user==='?') { |
|
| 2582 | + $this->_guest=true; |
|
| 2583 | + } else if($user==='@') { |
|
| 2584 | + $this->_authenticated=true; |
|
| 2585 | + } else { |
|
| 2586 | + $this->_users[]=$user; |
|
| 2422 | 2587 | } |
| 2423 | - else if($user==='?') |
|
| 2424 | - $this->_guest=true; |
|
| 2425 | - else if($user==='@') |
|
| 2426 | - $this->_authenticated=true; |
|
| 2427 | - else |
|
| 2428 | - $this->_users[]=$user; |
|
| 2429 | 2588 | } |
| 2430 | 2589 | } |
| 2431 | - if(trim($roles)==='') |
|
| 2432 | - $roles='*'; |
|
| 2590 | + if(trim($roles)==='') { |
|
| 2591 | + $roles='*'; |
|
| 2592 | + } |
|
| 2433 | 2593 | foreach(explode(',',$roles) as $role) |
| 2434 | 2594 | { |
| 2435 | - if(($role=trim(strtolower($role)))!=='') |
|
| 2436 | - $this->_roles[]=$role; |
|
| 2437 | - } |
|
| 2438 | - if(($verb=trim(strtolower($verb)))==='') |
|
| 2439 | - $verb='*'; |
|
| 2440 | - if($verb==='*' || $verb==='get' || $verb==='post') |
|
| 2441 | - $this->_verb=$verb; |
|
| 2442 | - else |
|
| 2443 | - throw new TInvalidDataValueException('authorizationrule_verb_invalid',$verb); |
|
| 2444 | - if(trim($ipRules)==='') |
|
| 2445 | - $ipRules='*'; |
|
| 2595 | + if(($role=trim(strtolower($role)))!=='') { |
|
| 2596 | + $this->_roles[]=$role; |
|
| 2597 | + } |
|
| 2598 | + } |
|
| 2599 | + if(($verb=trim(strtolower($verb)))==='') { |
|
| 2600 | + $verb='*'; |
|
| 2601 | + } |
|
| 2602 | + if($verb==='*' || $verb==='get' || $verb==='post') { |
|
| 2603 | + $this->_verb=$verb; |
|
| 2604 | + } else { |
|
| 2605 | + throw new TInvalidDataValueException('authorizationrule_verb_invalid',$verb); |
|
| 2606 | + } |
|
| 2607 | + if(trim($ipRules)==='') { |
|
| 2608 | + $ipRules='*'; |
|
| 2609 | + } |
|
| 2446 | 2610 | foreach(explode(',',$ipRules) as $ipRule) |
| 2447 | 2611 | { |
| 2448 | - if(($ipRule=trim($ipRule))!=='') |
|
| 2449 | - $this->_ipRules[]=$ipRule; |
|
| 2612 | + if(($ipRule=trim($ipRule))!=='') { |
|
| 2613 | + $this->_ipRules[]=$ipRule; |
|
| 2614 | + } |
|
| 2450 | 2615 | } |
| 2451 | 2616 | } |
| 2452 | 2617 | public function getAction() |
@@ -2483,19 +2648,22 @@ discard block |
||
| 2483 | 2648 | } |
| 2484 | 2649 | public function isUserAllowed(IUser $user,$verb,$ip) |
| 2485 | 2650 | { |
| 2486 | - if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user)) |
|
| 2487 | - return ($this->_action==='allow')?1:-1; |
|
| 2488 | - else |
|
| 2489 | - return 0; |
|
| 2651 | + if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user)) { |
|
| 2652 | + return ($this->_action==='allow')?1:-1; |
|
| 2653 | + } else { |
|
| 2654 | + return 0; |
|
| 2655 | + } |
|
| 2490 | 2656 | } |
| 2491 | 2657 | private function isIpMatched($ip) |
| 2492 | 2658 | { |
| 2493 | - if(empty($this->_ipRules)) |
|
| 2494 | - return 1; |
|
| 2659 | + if(empty($this->_ipRules)) { |
|
| 2660 | + return 1; |
|
| 2661 | + } |
|
| 2495 | 2662 | foreach($this->_ipRules as $rule) |
| 2496 | 2663 | { |
| 2497 | - if($rule==='*' || $rule===$ip || (($pos=strpos($rule,'*'))!==false && strncmp($ip,$rule,$pos)===0)) |
|
| 2498 | - return 1; |
|
| 2664 | + if($rule==='*' || $rule===$ip || (($pos=strpos($rule,'*'))!==false && strncmp($ip,$rule,$pos)===0)) { |
|
| 2665 | + return 1; |
|
| 2666 | + } |
|
| 2499 | 2667 | } |
| 2500 | 2668 | return 0; |
| 2501 | 2669 | } |
@@ -2507,8 +2675,9 @@ discard block |
||
| 2507 | 2675 | { |
| 2508 | 2676 | foreach($this->_roles as $role) |
| 2509 | 2677 | { |
| 2510 | - if($role==='*' || $user->isInRole($role)) |
|
| 2511 | - return true; |
|
| 2678 | + if($role==='*' || $user->isInRole($role)) { |
|
| 2679 | + return true; |
|
| 2680 | + } |
|
| 2512 | 2681 | } |
| 2513 | 2682 | return false; |
| 2514 | 2683 | } |
@@ -2526,20 +2695,22 @@ discard block |
||
| 2526 | 2695 | $verb=strtolower(trim($verb)); |
| 2527 | 2696 | foreach($this as $rule) |
| 2528 | 2697 | { |
| 2529 | - if(($decision=$rule->isUserAllowed($user,$verb,$ip))!==0) |
|
| 2530 | - return ($decision>0); |
|
| 2698 | + if(($decision=$rule->isUserAllowed($user,$verb,$ip))!==0) { |
|
| 2699 | + return ($decision>0); |
|
| 2700 | + } |
|
| 2531 | 2701 | } |
| 2532 | 2702 | return true; |
| 2703 | + } else { |
|
| 2704 | + return false; |
|
| 2533 | 2705 | } |
| 2534 | - else |
|
| 2535 | - return false; |
|
| 2536 | 2706 | } |
| 2537 | 2707 | public function insertAt($index,$item) |
| 2538 | 2708 | { |
| 2539 | - if($item instanceof TAuthorizationRule) |
|
| 2540 | - parent::insertAt($index,$item); |
|
| 2541 | - else |
|
| 2542 | - throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required'); |
|
| 2709 | + if($item instanceof TAuthorizationRule) { |
|
| 2710 | + parent::insertAt($index,$item); |
|
| 2711 | + } else { |
|
| 2712 | + throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required'); |
|
| 2713 | + } |
|
| 2543 | 2714 | } |
| 2544 | 2715 | } |
| 2545 | 2716 | class TSecurityManager extends TModule |
@@ -2572,8 +2743,9 @@ discard block |
||
| 2572 | 2743 | } |
| 2573 | 2744 | public function setValidationKey($value) |
| 2574 | 2745 | { |
| 2575 | - if('' === $value) |
|
| 2576 | - throw new TInvalidDataValueException('securitymanager_validationkey_invalid'); |
|
| 2746 | + if('' === $value) { |
|
| 2747 | + throw new TInvalidDataValueException('securitymanager_validationkey_invalid'); |
|
| 2748 | + } |
|
| 2577 | 2749 | $this->_validationKey = $value; |
| 2578 | 2750 | } |
| 2579 | 2751 | public function getEncryptionKey() |
@@ -2588,8 +2760,9 @@ discard block |
||
| 2588 | 2760 | } |
| 2589 | 2761 | public function setEncryptionKey($value) |
| 2590 | 2762 | { |
| 2591 | - if('' === $value) |
|
| 2592 | - throw new TInvalidDataValueException('securitymanager_encryptionkey_invalid'); |
|
| 2763 | + if('' === $value) { |
|
| 2764 | + throw new TInvalidDataValueException('securitymanager_encryptionkey_invalid'); |
|
| 2765 | + } |
|
| 2593 | 2766 | $this->_encryptionKey = $value; |
| 2594 | 2767 | } |
| 2595 | 2768 | public function getValidation() |
@@ -2610,8 +2783,9 @@ discard block |
||
| 2610 | 2783 | } |
| 2611 | 2784 | public function getEncryption() |
| 2612 | 2785 | { |
| 2613 | - if(is_string($this->_cryptAlgorithm)) |
|
| 2614 | - return $this->_cryptAlgorithm; |
|
| 2786 | + if(is_string($this->_cryptAlgorithm)) { |
|
| 2787 | + return $this->_cryptAlgorithm; |
|
| 2788 | + } |
|
| 2615 | 2789 | return "3DES"; |
| 2616 | 2790 | } |
| 2617 | 2791 | public function setEncryption($value) |
@@ -2654,16 +2828,18 @@ discard block |
||
| 2654 | 2828 | { |
| 2655 | 2829 | if(extension_loaded('mcrypt')) |
| 2656 | 2830 | { |
| 2657 | - if(is_array($this->_cryptAlgorithm)) |
|
| 2658 | - $module=@call_user_func_array('mcrypt_module_open',$this->_cryptAlgorithm); |
|
| 2659 | - else |
|
| 2660 | - $module=@mcrypt_module_open($this->_cryptAlgorithm,'', MCRYPT_MODE_CBC,''); |
|
| 2661 | - if($module===false) |
|
| 2662 | - throw new TNotSupportedException('securitymanager_mcryptextension_initfailed'); |
|
| 2831 | + if(is_array($this->_cryptAlgorithm)) { |
|
| 2832 | + $module=@call_user_func_array('mcrypt_module_open',$this->_cryptAlgorithm); |
|
| 2833 | + } else { |
|
| 2834 | + $module=@mcrypt_module_open($this->_cryptAlgorithm,'', MCRYPT_MODE_CBC,''); |
|
| 2835 | + } |
|
| 2836 | + if($module===false) { |
|
| 2837 | + throw new TNotSupportedException('securitymanager_mcryptextension_initfailed'); |
|
| 2838 | + } |
|
| 2663 | 2839 | return $module; |
| 2840 | + } else { |
|
| 2841 | + throw new TNotSupportedException('securitymanager_mcryptextension_required'); |
|
| 2664 | 2842 | } |
| 2665 | - else |
|
| 2666 | - throw new TNotSupportedException('securitymanager_mcryptextension_required'); |
|
| 2667 | 2843 | } |
| 2668 | 2844 | public function hashData($data) |
| 2669 | 2845 | { |
@@ -2673,8 +2849,9 @@ discard block |
||
| 2673 | 2849 | public function validateData($data) |
| 2674 | 2850 | { |
| 2675 | 2851 | $len=$this->strlen($this->computeHMAC('test')); |
| 2676 | - if($this->strlen($data) < $len) |
|
| 2677 | - return false; |
|
| 2852 | + if($this->strlen($data) < $len) { |
|
| 2853 | + return false; |
|
| 2854 | + } |
|
| 2678 | 2855 | $hmac = $this->substr($data, 0, $len); |
| 2679 | 2856 | $data2=$this->substr($data, $len, $this->strlen($data)); |
| 2680 | 2857 | return $hmac === $this->computeHMAC($data2) ? $data2 : false; |
@@ -2682,8 +2859,9 @@ discard block |
||
| 2682 | 2859 | protected function computeHMAC($data) |
| 2683 | 2860 | { |
| 2684 | 2861 | $key = $this->getValidationKey(); |
| 2685 | - if(function_exists('hash_hmac')) |
|
| 2686 | - return hash_hmac($this->_hashAlgorithm, $data, $key); |
|
| 2862 | + if(function_exists('hash_hmac')) { |
|
| 2863 | + return hash_hmac($this->_hashAlgorithm, $data, $key); |
|
| 2864 | + } |
|
| 2687 | 2865 | if(!strcasecmp($this->_hashAlgorithm,'sha1')) |
| 2688 | 2866 | { |
| 2689 | 2867 | $pack = 'H40'; |
@@ -2732,8 +2910,9 @@ discard block |
||
| 2732 | 2910 | public static function renderScriptFiles($files) |
| 2733 | 2911 | { |
| 2734 | 2912 | $str=''; |
| 2735 | - foreach($files as $file) |
|
| 2736 | - $str.= self::renderScriptFile($file); |
|
| 2913 | + foreach($files as $file) { |
|
| 2914 | + $str.= self::renderScriptFile($file); |
|
| 2915 | + } |
|
| 2737 | 2916 | return $str; |
| 2738 | 2917 | } |
| 2739 | 2918 | public static function renderScriptFile($file) |
@@ -2742,17 +2921,19 @@ discard block |
||
| 2742 | 2921 | } |
| 2743 | 2922 | public static function renderScriptBlocks($scripts) |
| 2744 | 2923 | { |
| 2745 | - if(count($scripts)) |
|
| 2746 | - return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n"; |
|
| 2747 | - else |
|
| 2748 | - return ''; |
|
| 2924 | + if(count($scripts)) { |
|
| 2925 | + return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n"; |
|
| 2926 | + } else { |
|
| 2927 | + return ''; |
|
| 2928 | + } |
|
| 2749 | 2929 | } |
| 2750 | 2930 | public static function renderScriptBlocksCallback($scripts) |
| 2751 | 2931 | { |
| 2752 | - if(count($scripts)) |
|
| 2753 | - return implode("\n",$scripts)."\n"; |
|
| 2754 | - else |
|
| 2755 | - return ''; |
|
| 2932 | + if(count($scripts)) { |
|
| 2933 | + return implode("\n",$scripts)."\n"; |
|
| 2934 | + } else { |
|
| 2935 | + return ''; |
|
| 2936 | + } |
|
| 2756 | 2937 | } |
| 2757 | 2938 | public static function renderScriptBlock($script) |
| 2758 | 2939 | { |
@@ -2764,10 +2945,11 @@ discard block |
||
| 2764 | 2945 | } |
| 2765 | 2946 | public static function quoteJsLiteral($js) |
| 2766 | 2947 | { |
| 2767 | - if($js instanceof TJavaScriptLiteral) |
|
| 2768 | - return $js; |
|
| 2769 | - else |
|
| 2770 | - return new TJavaScriptLiteral($js); |
|
| 2948 | + if($js instanceof TJavaScriptLiteral) { |
|
| 2949 | + return $js; |
|
| 2950 | + } else { |
|
| 2951 | + return new TJavaScriptLiteral($js); |
|
| 2952 | + } |
|
| 2771 | 2953 | } |
| 2772 | 2954 | public static function quoteFunction($js) |
| 2773 | 2955 | { |
@@ -2783,11 +2965,11 @@ discard block |
||
| 2783 | 2965 | } |
| 2784 | 2966 | public static function encode($value,$toMap=true,$encodeEmptyStrings=false) |
| 2785 | 2967 | { |
| 2786 | - if(is_string($value)) |
|
| 2787 | - return self::quoteString($value); |
|
| 2788 | - else if(is_bool($value)) |
|
| 2789 | - return $value?'true':'false'; |
|
| 2790 | - else if(is_array($value)) |
|
| 2968 | + if(is_string($value)) { |
|
| 2969 | + return self::quoteString($value); |
|
| 2970 | + } else if(is_bool($value)) { |
|
| 2971 | + return $value?'true':'false'; |
|
| 2972 | + } else if(is_array($value)) |
|
| 2791 | 2973 | { |
| 2792 | 2974 | $results=''; |
| 2793 | 2975 | if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1)) |
@@ -2796,30 +2978,30 @@ discard block |
||
| 2796 | 2978 | { |
| 2797 | 2979 | if($v!=='' || $encodeEmptyStrings) |
| 2798 | 2980 | { |
| 2799 | - if($results!=='') |
|
| 2800 | - $results.=','; |
|
| 2981 | + if($results!=='') { |
|
| 2982 | + $results.=','; |
|
| 2983 | + } |
|
| 2801 | 2984 | $results.="'$k':".self::encode($v,$toMap,$encodeEmptyStrings); |
| 2802 | 2985 | } |
| 2803 | 2986 | } |
| 2804 | 2987 | return '{'.$results.'}'; |
| 2805 | - } |
|
| 2806 | - else |
|
| 2988 | + } else |
|
| 2807 | 2989 | { |
| 2808 | 2990 | foreach($value as $v) |
| 2809 | 2991 | { |
| 2810 | 2992 | if($v!=='' || $encodeEmptyStrings) |
| 2811 | 2993 | { |
| 2812 | - if($results!=='') |
|
| 2813 | - $results.=','; |
|
| 2994 | + if($results!=='') { |
|
| 2995 | + $results.=','; |
|
| 2996 | + } |
|
| 2814 | 2997 | $results.=self::encode($v,$toMap, $encodeEmptyStrings); |
| 2815 | 2998 | } |
| 2816 | 2999 | } |
| 2817 | 3000 | return '['.$results.']'; |
| 2818 | 3001 | } |
| 2819 | - } |
|
| 2820 | - else if(is_integer($value)) |
|
| 2821 | - return "$value"; |
|
| 2822 | - else if(is_float($value)) |
|
| 3002 | + } else if(is_integer($value)) { |
|
| 3003 | + return "$value"; |
|
| 3004 | + } else if(is_float($value)) |
|
| 2823 | 3005 | { |
| 2824 | 3006 | switch($value) |
| 2825 | 3007 | { |
@@ -2831,22 +3013,24 @@ discard block |
||
| 2831 | 3013 | break; |
| 2832 | 3014 | default: |
| 2833 | 3015 | $locale=localeConv(); |
| 2834 | - if($locale['decimal_point']=='.') |
|
| 2835 | - return "$value"; |
|
| 2836 | - else |
|
| 2837 | - return str_replace($locale['decimal_point'], '.', "$value"); |
|
| 3016 | + if($locale['decimal_point']=='.') { |
|
| 3017 | + return "$value"; |
|
| 3018 | + } else { |
|
| 3019 | + return str_replace($locale['decimal_point'], '.', "$value"); |
|
| 3020 | + } |
|
| 2838 | 3021 | break; |
| 2839 | 3022 | } |
| 2840 | - } |
|
| 2841 | - else if(is_object($value)) |
|
| 2842 | - if ($value instanceof TJavaScriptLiteral) |
|
| 3023 | + } else if(is_object($value)) { |
|
| 3024 | + if ($value instanceof TJavaScriptLiteral) |
|
| 2843 | 3025 | return $value->toJavaScriptLiteral(); |
| 2844 | - else |
|
| 2845 | - return self::encode(get_object_vars($value),$toMap); |
|
| 2846 | - else if($value===null) |
|
| 2847 | - return 'null'; |
|
| 2848 | - else |
|
| 2849 | - return ''; |
|
| 3026 | + } else { |
|
| 3027 | + return self::encode(get_object_vars($value),$toMap); |
|
| 3028 | + } |
|
| 3029 | + else if($value===null) { |
|
| 3030 | + return 'null'; |
|
| 3031 | + } else { |
|
| 3032 | + return ''; |
|
| 3033 | + } |
|
| 2850 | 3034 | } |
| 2851 | 3035 | public static function jsonEncode($value, $options = 0) |
| 2852 | 3036 | { |
@@ -2859,12 +3043,13 @@ discard block |
||
| 2859 | 3043 | return $s; |
| 2860 | 3044 | } |
| 2861 | 3045 | private static function convertToUtf8(&$value, $sourceEncoding) { |
| 2862 | - if(is_string($value)) |
|
| 2863 | - $value=iconv($sourceEncoding, 'UTF-8', $value); |
|
| 2864 | - else if (is_array($value)) |
|
| 3046 | + if(is_string($value)) { |
|
| 3047 | + $value=iconv($sourceEncoding, 'UTF-8', $value); |
|
| 3048 | + } else if (is_array($value)) |
|
| 2865 | 3049 | { |
| 2866 | - foreach($value as &$element) |
|
| 2867 | - self::convertToUtf8($element, $sourceEncoding); |
|
| 3050 | + foreach($value as &$element) { |
|
| 3051 | + self::convertToUtf8($element, $sourceEncoding); |
|
| 3052 | + } |
|
| 2868 | 3053 | } |
| 2869 | 3054 | } |
| 2870 | 3055 | public static function jsonDecode($value, $assoc = false, $depth = 512) |
@@ -2923,24 +3108,25 @@ discard block |
||
| 2923 | 3108 | if(is_array($value)) |
| 2924 | 3109 | { |
| 2925 | 3110 | $name=urlencode($name.'[]'); |
| 2926 | - foreach($value as $v) |
|
| 2927 | - $url.=$amp.$name.'='.urlencode($v); |
|
| 3111 | + foreach($value as $v) { |
|
| 3112 | + $url.=$amp.$name.'='.urlencode($v); |
|
| 3113 | + } |
|
| 3114 | + } else { |
|
| 3115 | + $url.=$amp.urlencode($name).'='.urlencode($value); |
|
| 2928 | 3116 | } |
| 2929 | - else |
|
| 2930 | - $url.=$amp.urlencode($name).'='.urlencode($value); |
|
| 2931 | 3117 | } |
| 2932 | - } |
|
| 2933 | - else |
|
| 3118 | + } else |
|
| 2934 | 3119 | { |
| 2935 | 3120 | foreach($getItems as $name=>$value) |
| 2936 | 3121 | { |
| 2937 | 3122 | if(is_array($value)) |
| 2938 | 3123 | { |
| 2939 | - foreach($value as $v) |
|
| 2940 | - $url.=$amp.$name.'[]='.$v; |
|
| 3124 | + foreach($value as $v) { |
|
| 3125 | + $url.=$amp.$name.'[]='.$v; |
|
| 3126 | + } |
|
| 3127 | + } else { |
|
| 3128 | + $url.=$amp.$name.'='.$value; |
|
| 2941 | 3129 | } |
| 2942 | - else |
|
| 2943 | - $url.=$amp.$name.'='.$value; |
|
| 2944 | 3130 | } |
| 2945 | 3131 | } |
| 2946 | 3132 | } |
@@ -2973,19 +3159,20 @@ discard block |
||
| 2973 | 3159 | { |
| 2974 | 3160 | $name=substr($path,0,$pos); |
| 2975 | 3161 | $value=substr($path,$pos+1); |
| 2976 | - if(($pos=strpos($name,'[]'))!==false) |
|
| 2977 | - $getVariables[substr($name,0,$pos)][]=$value; |
|
| 2978 | - else |
|
| 2979 | - $getVariables[$name]=$value; |
|
| 3162 | + if(($pos=strpos($name,'[]'))!==false) { |
|
| 3163 | + $getVariables[substr($name,0,$pos)][]=$value; |
|
| 3164 | + } else { |
|
| 3165 | + $getVariables[$name]=$value; |
|
| 3166 | + } |
|
| 3167 | + } else { |
|
| 3168 | + $getVariables[$path]=''; |
|
| 2980 | 3169 | } |
| 2981 | - else |
|
| 2982 | - $getVariables[$path]=''; |
|
| 2983 | 3170 | } |
| 2984 | 3171 | } |
| 2985 | 3172 | return $getVariables; |
| 3173 | + } else { |
|
| 3174 | + return array(); |
|
| 2986 | 3175 | } |
| 2987 | - else |
|
| 2988 | - return array(); |
|
| 2989 | 3176 | } |
| 2990 | 3177 | } |
| 2991 | 3178 | class THttpRequest extends TApplicationComponent implements IteratorAggregate,ArrayAccess,Countable,IModule |
@@ -3028,27 +3215,34 @@ discard block |
||
| 3028 | 3215 | $_SERVER['SERVER_PORT']=80; |
| 3029 | 3216 | $_SERVER['HTTP_USER_AGENT']=''; |
| 3030 | 3217 | } |
| 3031 | - if(isset($_SERVER['REQUEST_URI'])) |
|
| 3032 | - $this->_requestUri=$_SERVER['REQUEST_URI']; |
|
| 3033 | - else $this->_requestUri=$_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING'])?'':'?'.$_SERVER['QUERY_STRING']); |
|
| 3034 | - if($this->_cgiFix&self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
| 3035 | - $this->_pathInfo=substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
|
| 3036 | - elseif(isset($_SERVER['PATH_INFO'])) |
|
| 3037 | - $this->_pathInfo=$_SERVER['PATH_INFO']; |
|
| 3038 | - else if(strpos($_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) |
|
| 3039 | - $this->_pathInfo=substr($_SERVER['PHP_SELF'],strlen($_SERVER['SCRIPT_NAME'])); |
|
| 3040 | - else |
|
| 3041 | - $this->_pathInfo=''; |
|
| 3218 | + if(isset($_SERVER['REQUEST_URI'])) { |
|
| 3219 | + $this->_requestUri=$_SERVER['REQUEST_URI']; |
|
| 3220 | + } else { |
|
| 3221 | + $this->_requestUri=$_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING'])?'':'?'.$_SERVER['QUERY_STRING']); |
|
| 3222 | + } |
|
| 3223 | + if($this->_cgiFix&self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) { |
|
| 3224 | + $this->_pathInfo=substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
|
| 3225 | + } elseif(isset($_SERVER['PATH_INFO'])) { |
|
| 3226 | + $this->_pathInfo=$_SERVER['PATH_INFO']; |
|
| 3227 | + } else if(strpos($_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) { |
|
| 3228 | + $this->_pathInfo=substr($_SERVER['PHP_SELF'],strlen($_SERVER['SCRIPT_NAME'])); |
|
| 3229 | + } else { |
|
| 3230 | + $this->_pathInfo=''; |
|
| 3231 | + } |
|
| 3042 | 3232 | if(get_magic_quotes_gpc()) |
| 3043 | 3233 | { |
| 3044 | - if(isset($_GET)) |
|
| 3045 | - $_GET=$this->stripSlashes($_GET); |
|
| 3046 | - if(isset($_POST)) |
|
| 3047 | - $_POST=$this->stripSlashes($_POST); |
|
| 3048 | - if(isset($_REQUEST)) |
|
| 3049 | - $_REQUEST=$this->stripSlashes($_REQUEST); |
|
| 3050 | - if(isset($_COOKIE)) |
|
| 3051 | - $_COOKIE=$this->stripSlashes($_COOKIE); |
|
| 3234 | + if(isset($_GET)) { |
|
| 3235 | + $_GET=$this->stripSlashes($_GET); |
|
| 3236 | + } |
|
| 3237 | + if(isset($_POST)) { |
|
| 3238 | + $_POST=$this->stripSlashes($_POST); |
|
| 3239 | + } |
|
| 3240 | + if(isset($_REQUEST)) { |
|
| 3241 | + $_REQUEST=$this->stripSlashes($_REQUEST); |
|
| 3242 | + } |
|
| 3243 | + if(isset($_COOKIE)) { |
|
| 3244 | + $_COOKIE=$this->stripSlashes($_COOKIE); |
|
| 3245 | + } |
|
| 3052 | 3246 | } |
| 3053 | 3247 | $this->getApplication()->setRequest($this); |
| 3054 | 3248 | } |
@@ -3066,11 +3260,12 @@ discard block |
||
| 3066 | 3260 | { |
| 3067 | 3261 | $url.=$_SERVER['SERVER_NAME']; |
| 3068 | 3262 | $port=$_SERVER['SERVER_PORT']; |
| 3069 | - if(($port!=80 && !$secure) || ($port!=443 && $secure)) |
|
| 3070 | - $url.=':'.$port; |
|
| 3263 | + if(($port!=80 && !$secure) || ($port!=443 && $secure)) { |
|
| 3264 | + $url.=':'.$port; |
|
| 3265 | + } |
|
| 3266 | + } else { |
|
| 3267 | + $url.=$_SERVER['HTTP_HOST']; |
|
| 3071 | 3268 | } |
| 3072 | - else |
|
| 3073 | - $url.=$_SERVER['HTTP_HOST']; |
|
| 3074 | 3269 | $url.=$this->getRequestUri(); |
| 3075 | 3270 | $this->_url=new TUri($url); |
| 3076 | 3271 | } |
@@ -3096,10 +3291,11 @@ discard block |
||
| 3096 | 3291 | if($cache !== null) |
| 3097 | 3292 | { |
| 3098 | 3293 | $dependencies = null; |
| 3099 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
| 3100 | - if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
|
| 3294 | + if($this->getApplication()->getMode() !== TApplicationMode::Performance) { |
|
| 3295 | + if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
|
| 3101 | 3296 | { |
| 3102 | 3297 | $fn = Prado::getPathOfNamespace($fn,$this->getApplication()->getConfigurationFileExt()); |
| 3298 | + } |
|
| 3103 | 3299 | $dependencies = new TFileCacheDependency($fn); |
| 3104 | 3300 | } |
| 3105 | 3301 | return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); |
@@ -3115,8 +3311,9 @@ discard block |
||
| 3115 | 3311 | if($cache !== null) |
| 3116 | 3312 | { |
| 3117 | 3313 | $manager = $cache->get($this->getCacheKey()); |
| 3118 | - if($manager instanceof TUrlManager) |
|
| 3119 | - return $manager; |
|
| 3314 | + if($manager instanceof TUrlManager) { |
|
| 3315 | + return $manager; |
|
| 3316 | + } |
|
| 3120 | 3317 | } |
| 3121 | 3318 | } |
| 3122 | 3319 | return null; |
@@ -3139,14 +3336,15 @@ discard block |
||
| 3139 | 3336 | { |
| 3140 | 3337 | $this->_urlManager=new TUrlManager; |
| 3141 | 3338 | $this->_urlManager->init(null); |
| 3142 | - } |
|
| 3143 | - else |
|
| 3339 | + } else |
|
| 3144 | 3340 | { |
| 3145 | 3341 | $this->_urlManager=$this->getApplication()->getModule($this->_urlManagerID); |
| 3146 | - if($this->_urlManager===null) |
|
| 3147 | - throw new TConfigurationException('httprequest_urlmanager_inexist',$this->_urlManagerID); |
|
| 3148 | - if(!($this->_urlManager instanceof TUrlManager)) |
|
| 3149 | - throw new TConfigurationException('httprequest_urlmanager_invalid',$this->_urlManagerID); |
|
| 3342 | + if($this->_urlManager===null) { |
|
| 3343 | + throw new TConfigurationException('httprequest_urlmanager_inexist',$this->_urlManagerID); |
|
| 3344 | + } |
|
| 3345 | + if(!($this->_urlManager instanceof TUrlManager)) { |
|
| 3346 | + throw new TConfigurationException('httprequest_urlmanager_invalid',$this->_urlManagerID); |
|
| 3347 | + } |
|
| 3150 | 3348 | } |
| 3151 | 3349 | $this->cacheUrlManager($this->_urlManager); |
| 3152 | 3350 | } |
@@ -3167,10 +3365,11 @@ discard block |
||
| 3167 | 3365 | } |
| 3168 | 3366 | public function setUrlParamSeparator($value) |
| 3169 | 3367 | { |
| 3170 | - if(strlen($value)===1) |
|
| 3171 | - $this->_separator=$value; |
|
| 3172 | - else |
|
| 3173 | - throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
| 3368 | + if(strlen($value)===1) { |
|
| 3369 | + $this->_separator=$value; |
|
| 3370 | + } else { |
|
| 3371 | + throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
| 3372 | + } |
|
| 3174 | 3373 | } |
| 3175 | 3374 | public function getRequestType() |
| 3176 | 3375 | { |
@@ -3178,10 +3377,12 @@ discard block |
||
| 3178 | 3377 | } |
| 3179 | 3378 | public function getContentType($mimetypeOnly = true) |
| 3180 | 3379 | { |
| 3181 | - if(!isset($_SERVER['CONTENT_TYPE'])) |
|
| 3182 | - return null; |
|
| 3183 | - if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
| 3184 | - return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
|
| 3380 | + if(!isset($_SERVER['CONTENT_TYPE'])) { |
|
| 3381 | + return null; |
|
| 3382 | + } |
|
| 3383 | + if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) { |
|
| 3384 | + return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
|
| 3385 | + } |
|
| 3185 | 3386 | return $_SERVER['CONTENT_TYPE']; |
| 3186 | 3387 | } |
| 3187 | 3388 | public function getIsSecureConnection() |
@@ -3205,17 +3406,19 @@ discard block |
||
| 3205 | 3406 | static $result; |
| 3206 | 3407 | if($result === null && function_exists('apache_request_headers')) { |
| 3207 | 3408 | $result = apache_request_headers(); |
| 3208 | - } |
|
| 3209 | - elseif($result === null) { |
|
| 3409 | + } elseif($result === null) { |
|
| 3210 | 3410 | $result = array(); |
| 3211 | 3411 | foreach($_SERVER as $key=>$value) { |
| 3212 | - if(strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
| 3412 | + if(strncasecmp($key, 'HTTP_', 5) !== 0) { |
|
| 3413 | + continue; |
|
| 3414 | + } |
|
| 3213 | 3415 | $key = str_replace(' ','-', ucwords(strtolower(str_replace('_',' ', substr($key, 5))))); |
| 3214 | 3416 | $result[$key] = $value; |
| 3215 | 3417 | } |
| 3216 | 3418 | } |
| 3217 | - if($case !== null) |
|
| 3218 | - return array_change_key_case($result, $case); |
|
| 3419 | + if($case !== null) { |
|
| 3420 | + return array_change_key_case($result, $case); |
|
| 3421 | + } |
|
| 3219 | 3422 | return $result; |
| 3220 | 3423 | } |
| 3221 | 3424 | public function getRequestUri() |
@@ -3227,13 +3430,16 @@ discard block |
||
| 3227 | 3430 | $url=$this->getUrl(); |
| 3228 | 3431 | $scheme=($forceSecureConnection)?"https": (($forceSecureConnection === null)?$url->getScheme():'http'); |
| 3229 | 3432 | $host=$url->getHost(); |
| 3230 | - if (($port=$url->getPort())) $host.=':'.$port; |
|
| 3433 | + if (($port=$url->getPort())) { |
|
| 3434 | + $host.=':'.$port; |
|
| 3435 | + } |
|
| 3231 | 3436 | return $scheme.'://'.$host; |
| 3232 | 3437 | } |
| 3233 | 3438 | public function getApplicationUrl() |
| 3234 | 3439 | { |
| 3235 | - if($this->_cgiFix&self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
| 3236 | - return $_SERVER['ORIG_SCRIPT_NAME']; |
|
| 3440 | + if($this->_cgiFix&self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) { |
|
| 3441 | + return $_SERVER['ORIG_SCRIPT_NAME']; |
|
| 3442 | + } |
|
| 3237 | 3443 | return isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:null; |
| 3238 | 3444 | } |
| 3239 | 3445 | public function getAbsoluteApplicationUrl($forceSecureConnection=null) |
@@ -3261,8 +3467,7 @@ discard block |
||
| 3261 | 3467 | try |
| 3262 | 3468 | { |
| 3263 | 3469 | return get_browser(); |
| 3264 | - } |
|
| 3265 | - catch(TPhpErrorException $e) |
|
| 3470 | + } catch(TPhpErrorException $e) |
|
| 3266 | 3471 | { |
| 3267 | 3472 | throw new TConfigurationException('httprequest_browscap_required'); |
| 3268 | 3473 | } |
@@ -3313,14 +3518,15 @@ discard block |
||
| 3313 | 3518 | $sm=$this->getApplication()->getSecurityManager(); |
| 3314 | 3519 | foreach($_COOKIE as $key=>$value) |
| 3315 | 3520 | { |
| 3316 | - if(($value=$sm->validateData($value))!==false) |
|
| 3317 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
| 3521 | + if(($value=$sm->validateData($value))!==false) { |
|
| 3522 | + $this->_cookies->add(new THttpCookie($key,$value)); |
|
| 3523 | + } |
|
| 3318 | 3524 | } |
| 3319 | - } |
|
| 3320 | - else |
|
| 3525 | + } else |
|
| 3321 | 3526 | { |
| 3322 | - foreach($_COOKIE as $key=>$value) |
|
| 3323 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
| 3527 | + foreach($_COOKIE as $key=>$value) { |
|
| 3528 | + $this->_cookies->add(new THttpCookie($key,$value)); |
|
| 3529 | + } |
|
| 3324 | 3530 | } |
| 3325 | 3531 | } |
| 3326 | 3532 | return $this->_cookies; |
@@ -3339,13 +3545,15 @@ discard block |
||
| 3339 | 3545 | } |
| 3340 | 3546 | public function constructUrl($serviceID,$serviceParam,$getItems=null,$encodeAmpersand=true,$encodeGetItems=true) |
| 3341 | 3547 | { |
| 3342 | - if ($this->_cookieOnly===null) |
|
| 3343 | - $this->_cookieOnly=(int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
| 3548 | + if ($this->_cookieOnly===null) { |
|
| 3549 | + $this->_cookieOnly=(int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
| 3550 | + } |
|
| 3344 | 3551 | $url=$this->getUrlManagerModule()->constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems); |
| 3345 | - if(defined('SID') && SID != '' && !$this->_cookieOnly) |
|
| 3346 | - return $url . (strpos($url,'?')===false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
| 3347 | - else |
|
| 3348 | - return $url; |
|
| 3552 | + if(defined('SID') && SID != '' && !$this->_cookieOnly) { |
|
| 3553 | + return $url . (strpos($url,'?')===false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
| 3554 | + } else { |
|
| 3555 | + return $url; |
|
| 3556 | + } |
|
| 3349 | 3557 | } |
| 3350 | 3558 | protected function parseUrl() |
| 3351 | 3559 | { |
@@ -3354,8 +3562,9 @@ discard block |
||
| 3354 | 3562 | public function resolveRequest($serviceIDs) |
| 3355 | 3563 | { |
| 3356 | 3564 | $getParams=$this->parseUrl(); |
| 3357 | - foreach($getParams as $name=>$value) |
|
| 3358 | - $_GET[$name]=$value; |
|
| 3565 | + foreach($getParams as $name=>$value) { |
|
| 3566 | + $_GET[$name]=$value; |
|
| 3567 | + } |
|
| 3359 | 3568 | $this->_items=array_merge($_GET,$_POST); |
| 3360 | 3569 | $this->_requestResolved=true; |
| 3361 | 3570 | foreach($serviceIDs as $serviceID) |
@@ -3420,14 +3629,15 @@ discard block |
||
| 3420 | 3629 | $value=$this->_items[$key]; |
| 3421 | 3630 | unset($this->_items[$key]); |
| 3422 | 3631 | return $value; |
| 3632 | + } else { |
|
| 3633 | + return null; |
|
| 3423 | 3634 | } |
| 3424 | - else |
|
| 3425 | - return null; |
|
| 3426 | 3635 | } |
| 3427 | 3636 | public function clear() |
| 3428 | 3637 | { |
| 3429 | - foreach(array_keys($this->_items) as $key) |
|
| 3430 | - $this->remove($key); |
|
| 3638 | + foreach(array_keys($this->_items) as $key) { |
|
| 3639 | + $this->remove($key); |
|
| 3640 | + } |
|
| 3431 | 3641 | } |
| 3432 | 3642 | public function contains($key) |
| 3433 | 3643 | { |
@@ -3466,31 +3676,35 @@ discard block |
||
| 3466 | 3676 | if($item instanceof THttpCookie) |
| 3467 | 3677 | { |
| 3468 | 3678 | parent::insertAt($index,$item); |
| 3469 | - if($this->_o instanceof THttpResponse) |
|
| 3470 | - $this->_o->addCookie($item); |
|
| 3679 | + if($this->_o instanceof THttpResponse) { |
|
| 3680 | + $this->_o->addCookie($item); |
|
| 3681 | + } |
|
| 3682 | + } else { |
|
| 3683 | + throw new TInvalidDataTypeException('httpcookiecollection_httpcookie_required'); |
|
| 3471 | 3684 | } |
| 3472 | - else |
|
| 3473 | - throw new TInvalidDataTypeException('httpcookiecollection_httpcookie_required'); |
|
| 3474 | 3685 | } |
| 3475 | 3686 | public function removeAt($index) |
| 3476 | 3687 | { |
| 3477 | 3688 | $item=parent::removeAt($index); |
| 3478 | - if($this->_o instanceof THttpResponse) |
|
| 3479 | - $this->_o->removeCookie($item); |
|
| 3689 | + if($this->_o instanceof THttpResponse) { |
|
| 3690 | + $this->_o->removeCookie($item); |
|
| 3691 | + } |
|
| 3480 | 3692 | return $item; |
| 3481 | 3693 | } |
| 3482 | 3694 | public function itemAt($index) |
| 3483 | 3695 | { |
| 3484 | - if(is_integer($index)) |
|
| 3485 | - return parent::itemAt($index); |
|
| 3486 | - else |
|
| 3487 | - return $this->findCookieByName($index); |
|
| 3696 | + if(is_integer($index)) { |
|
| 3697 | + return parent::itemAt($index); |
|
| 3698 | + } else { |
|
| 3699 | + return $this->findCookieByName($index); |
|
| 3700 | + } |
|
| 3488 | 3701 | } |
| 3489 | 3702 | public function findCookieByName($name) |
| 3490 | 3703 | { |
| 3491 | - foreach($this as $cookie) |
|
| 3492 | - if($cookie->getName()===$name) |
|
| 3704 | + foreach($this as $cookie) { |
|
| 3705 | + if($cookie->getName()===$name) |
|
| 3493 | 3706 | return $cookie; |
| 3707 | + } |
|
| 3494 | 3708 | return null; |
| 3495 | 3709 | } |
| 3496 | 3710 | } |
@@ -3599,8 +3813,7 @@ discard block |
||
| 3599 | 3813 | $this->_query=isset($ret['query'])?$ret['query']:''; |
| 3600 | 3814 | $this->_fragment=isset($ret['fragment'])?$ret['fragment']:''; |
| 3601 | 3815 | $this->_uri=$uri; |
| 3602 | - } |
|
| 3603 | - else |
|
| 3816 | + } else |
|
| 3604 | 3817 | { |
| 3605 | 3818 | throw new TInvalidDataValueException('uri_format_invalid',$uri); |
| 3606 | 3819 | } |
@@ -3711,8 +3924,9 @@ discard block |
||
| 3711 | 3924 | } |
| 3712 | 3925 | public function init($config) |
| 3713 | 3926 | { |
| 3714 | - if($this->_bufferOutput) |
|
| 3715 | - ob_start(); |
|
| 3927 | + if($this->_bufferOutput) { |
|
| 3928 | + ob_start(); |
|
| 3929 | + } |
|
| 3716 | 3930 | $this->_initialized=true; |
| 3717 | 3931 | $this->getApplication()->setResponse($this); |
| 3718 | 3932 | } |
@@ -3734,8 +3948,9 @@ discard block |
||
| 3734 | 3948 | } |
| 3735 | 3949 | public function setContentType($type) |
| 3736 | 3950 | { |
| 3737 | - if ($this->_contentTypeHeaderSent) |
|
| 3738 | - throw new Exception('Unable to alter content-type as it has been already sent'); |
|
| 3951 | + if ($this->_contentTypeHeaderSent) { |
|
| 3952 | + throw new Exception('Unable to alter content-type as it has been already sent'); |
|
| 3953 | + } |
|
| 3739 | 3954 | $this->_contentType = $type; |
| 3740 | 3955 | } |
| 3741 | 3956 | public function getContentType() |
@@ -3756,10 +3971,11 @@ discard block |
||
| 3756 | 3971 | } |
| 3757 | 3972 | public function setBufferOutput($value) |
| 3758 | 3973 | { |
| 3759 | - if($this->_initialized) |
|
| 3760 | - throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
|
| 3761 | - else |
|
| 3762 | - $this->_bufferOutput=TPropertyValue::ensureBoolean($value); |
|
| 3974 | + if($this->_initialized) { |
|
| 3975 | + throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
|
| 3976 | + } else { |
|
| 3977 | + $this->_bufferOutput=TPropertyValue::ensureBoolean($value); |
|
| 3978 | + } |
|
| 3763 | 3979 | } |
| 3764 | 3980 | public function getStatusCode() |
| 3765 | 3981 | { |
@@ -3767,12 +3983,13 @@ discard block |
||
| 3767 | 3983 | } |
| 3768 | 3984 | public function setStatusCode($status, $reason=null) |
| 3769 | 3985 | { |
| 3770 | - if ($this->_httpHeaderSent) |
|
| 3771 | - throw new Exception('Unable to alter response as HTTP header already sent'); |
|
| 3986 | + if ($this->_httpHeaderSent) { |
|
| 3987 | + throw new Exception('Unable to alter response as HTTP header already sent'); |
|
| 3988 | + } |
|
| 3772 | 3989 | $status=TPropertyValue::ensureInteger($status); |
| 3773 | 3990 | if(isset(self::$HTTP_STATUS_CODES[$status])) { |
| 3774 | 3991 | $this->_reason=self::$HTTP_STATUS_CODES[$status]; |
| 3775 | - }else{ |
|
| 3992 | + } else{ |
|
| 3776 | 3993 | if($reason===null || $reason==='') { |
| 3777 | 3994 | throw new TInvalidDataValueException("response_status_reason_missing"); |
| 3778 | 3995 | } |
@@ -3789,14 +4006,16 @@ discard block |
||
| 3789 | 4006 | } |
| 3790 | 4007 | public function getCookies() |
| 3791 | 4008 | { |
| 3792 | - if($this->_cookies===null) |
|
| 3793 | - $this->_cookies=new THttpCookieCollection($this); |
|
| 4009 | + if($this->_cookies===null) { |
|
| 4010 | + $this->_cookies=new THttpCookieCollection($this); |
|
| 4011 | + } |
|
| 3794 | 4012 | return $this->_cookies; |
| 3795 | 4013 | } |
| 3796 | 4014 | public function write($str) |
| 3797 | 4015 | { |
| 3798 | - if (!$this->_bufferOutput and !$this->_httpHeaderSent) |
|
| 3799 | - $this->ensureHeadersSent(); |
|
| 4016 | + if (!$this->_bufferOutput and !$this->_httpHeaderSent) { |
|
| 4017 | + $this->ensureHeadersSent(); |
|
| 4018 | + } |
|
| 3800 | 4019 | echo $str; |
| 3801 | 4020 | } |
| 3802 | 4021 | public function writeFile($fileName,$content=null,$mimeType=null,$headers=null,$forceDownload=true,$clientFileName=null,$fileSize=null) |
@@ -3816,28 +4035,31 @@ discard block |
||
| 3816 | 4035 | if($mimeType===null) |
| 3817 | 4036 | { |
| 3818 | 4037 | $mimeType='text/plain'; |
| 3819 | - if(function_exists('mime_content_type')) |
|
| 3820 | - $mimeType=mime_content_type($fileName); |
|
| 3821 | - else if(($ext=strrchr($fileName,'.'))!==false) |
|
| 4038 | + if(function_exists('mime_content_type')) { |
|
| 4039 | + $mimeType=mime_content_type($fileName); |
|
| 4040 | + } else if(($ext=strrchr($fileName,'.'))!==false) |
|
| 3822 | 4041 | { |
| 3823 | 4042 | $ext=substr($ext,1); |
| 3824 | - if(isset($defaultMimeTypes[$ext])) |
|
| 3825 | - $mimeType=$defaultMimeTypes[$ext]; |
|
| 4043 | + if(isset($defaultMimeTypes[$ext])) { |
|
| 4044 | + $mimeType=$defaultMimeTypes[$ext]; |
|
| 4045 | + } |
|
| 3826 | 4046 | } |
| 3827 | 4047 | } |
| 3828 | - if($clientFileName===null) |
|
| 3829 | - $clientFileName=basename($fileName); |
|
| 3830 | - else |
|
| 3831 | - $clientFileName=basename($clientFileName); |
|
| 3832 | - if($fileSize===null || $fileSize < 0) |
|
| 3833 | - $fileSize = ($content===null?filesize($fileName):strlen($content)); |
|
| 4048 | + if($clientFileName===null) { |
|
| 4049 | + $clientFileName=basename($fileName); |
|
| 4050 | + } else { |
|
| 4051 | + $clientFileName=basename($clientFileName); |
|
| 4052 | + } |
|
| 4053 | + if($fileSize===null || $fileSize < 0) { |
|
| 4054 | + $fileSize = ($content===null?filesize($fileName):strlen($content)); |
|
| 4055 | + } |
|
| 3834 | 4056 | $this->sendHttpHeader(); |
| 3835 | 4057 | if(is_array($headers)) |
| 3836 | 4058 | { |
| 3837 | - foreach($headers as $h) |
|
| 3838 | - header($h); |
|
| 3839 | - } |
|
| 3840 | - else |
|
| 4059 | + foreach($headers as $h) { |
|
| 4060 | + header($h); |
|
| 4061 | + } |
|
| 4062 | + } else |
|
| 3841 | 4063 | { |
| 3842 | 4064 | header('Pragma: public'); |
| 3843 | 4065 | header('Expires: 0'); |
@@ -3848,29 +4070,34 @@ discard block |
||
| 3848 | 4070 | header('Content-Length: '.$fileSize); |
| 3849 | 4071 | header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
| 3850 | 4072 | header('Content-Transfer-Encoding: binary'); |
| 3851 | - if($content===null) |
|
| 3852 | - readfile($fileName); |
|
| 3853 | - else |
|
| 3854 | - echo $content; |
|
| 4073 | + if($content===null) { |
|
| 4074 | + readfile($fileName); |
|
| 4075 | + } else { |
|
| 4076 | + echo $content; |
|
| 4077 | + } |
|
| 3855 | 4078 | } |
| 3856 | 4079 | public function redirect($url) |
| 3857 | 4080 | { |
| 3858 | - if($this->getHasAdapter()) |
|
| 3859 | - $this->_adapter->httpRedirect($url); |
|
| 3860 | - else |
|
| 3861 | - $this->httpRedirect($url); |
|
| 4081 | + if($this->getHasAdapter()) { |
|
| 4082 | + $this->_adapter->httpRedirect($url); |
|
| 4083 | + } else { |
|
| 4084 | + $this->httpRedirect($url); |
|
| 4085 | + } |
|
| 3862 | 4086 | } |
| 3863 | 4087 | public function httpRedirect($url) |
| 3864 | 4088 | { |
| 3865 | 4089 | $this->ensureHeadersSent(); |
| 3866 | - if($url[0]==='/') |
|
| 3867 | - $url=$this->getRequest()->getBaseUrl().$url; |
|
| 3868 | - if ($this->_status >= 300 && $this->_status < 400) |
|
| 3869 | - header('Location: '.str_replace('&','&',$url), true, $this->_status); |
|
| 3870 | - else |
|
| 3871 | - header('Location: '.str_replace('&','&',$url)); |
|
| 3872 | - if(!$this->getApplication()->getRequestCompleted()) |
|
| 3873 | - $this->getApplication()->onEndRequest(); |
|
| 4090 | + if($url[0]==='/') { |
|
| 4091 | + $url=$this->getRequest()->getBaseUrl().$url; |
|
| 4092 | + } |
|
| 4093 | + if ($this->_status >= 300 && $this->_status < 400) { |
|
| 4094 | + header('Location: '.str_replace('&','&',$url), true, $this->_status); |
|
| 4095 | + } else { |
|
| 4096 | + header('Location: '.str_replace('&','&',$url)); |
|
| 4097 | + } |
|
| 4098 | + if(!$this->getApplication()->getRequestCompleted()) { |
|
| 4099 | + $this->getApplication()->onEndRequest(); |
|
| 4100 | + } |
|
| 3874 | 4101 | exit(); |
| 3875 | 4102 | } |
| 3876 | 4103 | public function reload() |
@@ -3879,10 +4106,11 @@ discard block |
||
| 3879 | 4106 | } |
| 3880 | 4107 | public function flush($continueBuffering = true) |
| 3881 | 4108 | { |
| 3882 | - if($this->getHasAdapter()) |
|
| 3883 | - $this->_adapter->flushContent($continueBuffering); |
|
| 3884 | - else |
|
| 3885 | - $this->flushContent($continueBuffering); |
|
| 4109 | + if($this->getHasAdapter()) { |
|
| 4110 | + $this->_adapter->flushContent($continueBuffering); |
|
| 4111 | + } else { |
|
| 4112 | + $this->flushContent($continueBuffering); |
|
| 4113 | + } |
|
| 3886 | 4114 | } |
| 3887 | 4115 | public function ensureHeadersSent() |
| 3888 | 4116 | { |
@@ -3900,25 +4128,27 @@ discard block |
||
| 3900 | 4128 | { |
| 3901 | 4129 | $this->_bufferOutput = false; |
| 3902 | 4130 | ob_end_flush(); |
| 4131 | + } else { |
|
| 4132 | + ob_flush(); |
|
| 3903 | 4133 | } |
| 3904 | - else |
|
| 3905 | - ob_flush(); |
|
| 3906 | 4134 | flush(); |
| 3907 | 4135 | } |
| 4136 | + } else { |
|
| 4137 | + flush(); |
|
| 3908 | 4138 | } |
| 3909 | - else |
|
| 3910 | - flush(); |
|
| 3911 | 4139 | } |
| 3912 | 4140 | protected function ensureHttpHeaderSent() |
| 3913 | 4141 | { |
| 3914 | - if (!$this->_httpHeaderSent) |
|
| 3915 | - $this->sendHttpHeader(); |
|
| 4142 | + if (!$this->_httpHeaderSent) { |
|
| 4143 | + $this->sendHttpHeader(); |
|
| 4144 | + } |
|
| 3916 | 4145 | } |
| 3917 | 4146 | protected function sendHttpHeader() |
| 3918 | 4147 | { |
| 3919 | 4148 | $protocol=$this->getRequest()->getHttpProtocolVersion(); |
| 3920 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
| 3921 | - $protocol='HTTP/1.1'; |
|
| 4149 | + if($this->getRequest()->getHttpProtocolVersion() === null) { |
|
| 4150 | + $protocol='HTTP/1.1'; |
|
| 4151 | + } |
|
| 3922 | 4152 | $phpSapiName = substr(php_sapi_name(), 0, 3); |
| 3923 | 4153 | $cgi = $phpSapiName == 'cgi' || $phpSapiName == 'fpm'; |
| 3924 | 4154 | header(($cgi ? 'Status:' : $protocol).' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
@@ -3926,8 +4156,9 @@ discard block |
||
| 3926 | 4156 | } |
| 3927 | 4157 | protected function ensureContentTypeHeaderSent() |
| 3928 | 4158 | { |
| 3929 | - if (!$this->_contentTypeHeaderSent) |
|
| 3930 | - $this->sendContentTypeHeader(); |
|
| 4159 | + if (!$this->_contentTypeHeaderSent) { |
|
| 4160 | + $this->sendContentTypeHeader(); |
|
| 4161 | + } |
|
| 3931 | 4162 | } |
| 3932 | 4163 | protected function sendContentTypeHeader() |
| 3933 | 4164 | { |
@@ -3937,9 +4168,12 @@ discard block |
||
| 3937 | 4168 | $this->appendHeader('Content-Type: '.$contentType); |
| 3938 | 4169 | return; |
| 3939 | 4170 | } |
| 3940 | - if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null) |
|
| 3941 | - $charset=$globalization->getCharset(); |
|
| 3942 | - if($charset==='') $charset = self::DEFAULT_CHARSET; |
|
| 4171 | + if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null) { |
|
| 4172 | + $charset=$globalization->getCharset(); |
|
| 4173 | + } |
|
| 4174 | + if($charset==='') { |
|
| 4175 | + $charset = self::DEFAULT_CHARSET; |
|
| 4176 | + } |
|
| 3943 | 4177 | $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset); |
| 3944 | 4178 | $this->_contentTypeHeaderSent = true; |
| 3945 | 4179 | } |
@@ -3949,8 +4183,9 @@ discard block |
||
| 3949 | 4183 | } |
| 3950 | 4184 | public function clear() |
| 3951 | 4185 | { |
| 3952 | - if($this->_bufferOutput) |
|
| 3953 | - ob_clean(); |
|
| 4186 | + if($this->_bufferOutput) { |
|
| 4187 | + ob_clean(); |
|
| 4188 | + } |
|
| 3954 | 4189 | } |
| 3955 | 4190 | public function getHeaders($case=null) |
| 3956 | 4191 | { |
@@ -3960,13 +4195,15 @@ discard block |
||
| 3960 | 4195 | $tmp = explode(':', $header); |
| 3961 | 4196 | $key = trim(array_shift($tmp)); |
| 3962 | 4197 | $value = trim(implode(':', $tmp)); |
| 3963 | - if(isset($result[$key])) |
|
| 3964 | - $result[$key] .= ', ' . $value; |
|
| 3965 | - else |
|
| 3966 | - $result[$key] = $value; |
|
| 4198 | + if(isset($result[$key])) { |
|
| 4199 | + $result[$key] .= ', ' . $value; |
|
| 4200 | + } else { |
|
| 4201 | + $result[$key] = $value; |
|
| 4202 | + } |
|
| 4203 | + } |
|
| 4204 | + if($case !== null) { |
|
| 4205 | + return array_change_key_case($result, $case); |
|
| 3967 | 4206 | } |
| 3968 | - if($case !== null) |
|
| 3969 | - return array_change_key_case($result, $case); |
|
| 3970 | 4207 | return $result; |
| 3971 | 4208 | } |
| 3972 | 4209 | public function appendHeader($value, $replace=true) |
@@ -3992,8 +4229,7 @@ discard block |
||
| 3992 | 4229 | $cookie->getSecure(), |
| 3993 | 4230 | $cookie->getHttpOnly() |
| 3994 | 4231 | ); |
| 3995 | - } |
|
| 3996 | - else { |
|
| 4232 | + } else { |
|
| 3997 | 4233 | setcookie( |
| 3998 | 4234 | $cookie->getName(), |
| 3999 | 4235 | $cookie->getValue(), |
@@ -4027,12 +4263,14 @@ discard block |
||
| 4027 | 4263 | } |
| 4028 | 4264 | public function createHtmlWriter($type=null) |
| 4029 | 4265 | { |
| 4030 | - if($type===null) |
|
| 4031 | - $type=$this->getHtmlWriterType(); |
|
| 4032 | - if($this->getHasAdapter()) |
|
| 4033 | - return $this->_adapter->createNewHtmlWriter($type, $this); |
|
| 4034 | - else |
|
| 4035 | - return $this->createNewHtmlWriter($type, $this); |
|
| 4266 | + if($type===null) { |
|
| 4267 | + $type=$this->getHtmlWriterType(); |
|
| 4268 | + } |
|
| 4269 | + if($this->getHasAdapter()) { |
|
| 4270 | + return $this->_adapter->createNewHtmlWriter($type, $this); |
|
| 4271 | + } else { |
|
| 4272 | + return $this->createNewHtmlWriter($type, $this); |
|
| 4273 | + } |
|
| 4036 | 4274 | } |
| 4037 | 4275 | public function createNewHtmlWriter($type, $writer) |
| 4038 | 4276 | { |
@@ -4057,8 +4295,9 @@ discard block |
||
| 4057 | 4295 | } |
| 4058 | 4296 | public function init($config) |
| 4059 | 4297 | { |
| 4060 | - if($this->_autoStart) |
|
| 4061 | - $this->open(); |
|
| 4298 | + if($this->_autoStart) { |
|
| 4299 | + $this->open(); |
|
| 4300 | + } |
|
| 4062 | 4301 | $this->_initialized=true; |
| 4063 | 4302 | $this->getApplication()->setSession($this); |
| 4064 | 4303 | register_shutdown_function(array($this, "close")); |
@@ -4067,12 +4306,15 @@ discard block |
||
| 4067 | 4306 | { |
| 4068 | 4307 | if(!$this->_started) |
| 4069 | 4308 | { |
| 4070 | - if($this->_customStorage) |
|
| 4071 | - session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc')); |
|
| 4072 | - if($this->_cookie!==null) |
|
| 4073 | - session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure(),$this->_cookie->getHttpOnly()); |
|
| 4074 | - if(ini_get('session.auto_start')!=='1') |
|
| 4075 | - session_start(); |
|
| 4309 | + if($this->_customStorage) { |
|
| 4310 | + session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc')); |
|
| 4311 | + } |
|
| 4312 | + if($this->_cookie!==null) { |
|
| 4313 | + session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure(),$this->_cookie->getHttpOnly()); |
|
| 4314 | + } |
|
| 4315 | + if(ini_get('session.auto_start')!=='1') { |
|
| 4316 | + session_start(); |
|
| 4317 | + } |
|
| 4076 | 4318 | $this->_started=true; |
| 4077 | 4319 | } |
| 4078 | 4320 | } |
@@ -4108,10 +4350,11 @@ discard block |
||
| 4108 | 4350 | } |
| 4109 | 4351 | public function setSessionID($value) |
| 4110 | 4352 | { |
| 4111 | - if($this->_started) |
|
| 4112 | - throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
|
| 4113 | - else |
|
| 4114 | - session_id($value); |
|
| 4353 | + if($this->_started) { |
|
| 4354 | + throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
|
| 4355 | + } else { |
|
| 4356 | + session_id($value); |
|
| 4357 | + } |
|
| 4115 | 4358 | } |
| 4116 | 4359 | public function getSessionName() |
| 4117 | 4360 | { |
@@ -4119,12 +4362,13 @@ discard block |
||
| 4119 | 4362 | } |
| 4120 | 4363 | public function setSessionName($value) |
| 4121 | 4364 | { |
| 4122 | - if($this->_started) |
|
| 4123 | - throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
|
| 4124 | - else if(ctype_alnum($value)) |
|
| 4125 | - session_name($value); |
|
| 4126 | - else |
|
| 4127 | - throw new TInvalidDataValueException('httpsession_sessionname_invalid',$value); |
|
| 4365 | + if($this->_started) { |
|
| 4366 | + throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
|
| 4367 | + } else if(ctype_alnum($value)) { |
|
| 4368 | + session_name($value); |
|
| 4369 | + } else { |
|
| 4370 | + throw new TInvalidDataValueException('httpsession_sessionname_invalid',$value); |
|
| 4371 | + } |
|
| 4128 | 4372 | } |
| 4129 | 4373 | public function getSavePath() |
| 4130 | 4374 | { |
@@ -4132,12 +4376,13 @@ discard block |
||
| 4132 | 4376 | } |
| 4133 | 4377 | public function setSavePath($value) |
| 4134 | 4378 | { |
| 4135 | - if($this->_started) |
|
| 4136 | - throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
|
| 4137 | - else if(is_dir($value)) |
|
| 4138 | - session_save_path($value); |
|
| 4139 | - else |
|
| 4140 | - throw new TInvalidDataValueException('httpsession_savepath_invalid',$value); |
|
| 4379 | + if($this->_started) { |
|
| 4380 | + throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
|
| 4381 | + } else if(is_dir($value)) { |
|
| 4382 | + session_save_path($value); |
|
| 4383 | + } else { |
|
| 4384 | + throw new TInvalidDataValueException('httpsession_savepath_invalid',$value); |
|
| 4385 | + } |
|
| 4141 | 4386 | } |
| 4142 | 4387 | public function getUseCustomStorage() |
| 4143 | 4388 | { |
@@ -4149,37 +4394,37 @@ discard block |
||
| 4149 | 4394 | } |
| 4150 | 4395 | public function getCookie() |
| 4151 | 4396 | { |
| 4152 | - if($this->_cookie===null) |
|
| 4153 | - $this->_cookie=new THttpCookie($this->getSessionName(),$this->getSessionID()); |
|
| 4397 | + if($this->_cookie===null) { |
|
| 4398 | + $this->_cookie=new THttpCookie($this->getSessionName(),$this->getSessionID()); |
|
| 4399 | + } |
|
| 4154 | 4400 | return $this->_cookie; |
| 4155 | 4401 | } |
| 4156 | 4402 | public function getCookieMode() |
| 4157 | 4403 | { |
| 4158 | - if(ini_get('session.use_cookies')==='0') |
|
| 4159 | - return THttpSessionCookieMode::None; |
|
| 4160 | - else if(ini_get('session.use_only_cookies')==='0') |
|
| 4161 | - return THttpSessionCookieMode::Allow; |
|
| 4162 | - else |
|
| 4163 | - return THttpSessionCookieMode::Only; |
|
| 4404 | + if(ini_get('session.use_cookies')==='0') { |
|
| 4405 | + return THttpSessionCookieMode::None; |
|
| 4406 | + } else if(ini_get('session.use_only_cookies')==='0') { |
|
| 4407 | + return THttpSessionCookieMode::Allow; |
|
| 4408 | + } else { |
|
| 4409 | + return THttpSessionCookieMode::Only; |
|
| 4410 | + } |
|
| 4164 | 4411 | } |
| 4165 | 4412 | public function setCookieMode($value) |
| 4166 | 4413 | { |
| 4167 | - if($this->_started) |
|
| 4168 | - throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
|
| 4169 | - else |
|
| 4414 | + if($this->_started) { |
|
| 4415 | + throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
|
| 4416 | + } else |
|
| 4170 | 4417 | { |
| 4171 | 4418 | $value=TPropertyValue::ensureEnum($value,'THttpSessionCookieMode'); |
| 4172 | 4419 | if($value===THttpSessionCookieMode::None) |
| 4173 | 4420 | { |
| 4174 | 4421 | ini_set('session.use_cookies','0'); |
| 4175 | 4422 | ini_set('session.use_only_cookies','0'); |
| 4176 | - } |
|
| 4177 | - else if($value===THttpSessionCookieMode::Allow) |
|
| 4423 | + } else if($value===THttpSessionCookieMode::Allow) |
|
| 4178 | 4424 | { |
| 4179 | 4425 | ini_set('session.use_cookies','1'); |
| 4180 | 4426 | ini_set('session.use_only_cookies','0'); |
| 4181 | - } |
|
| 4182 | - else |
|
| 4427 | + } else |
|
| 4183 | 4428 | { |
| 4184 | 4429 | ini_set('session.use_cookies','1'); |
| 4185 | 4430 | ini_set('session.use_only_cookies','1'); |
@@ -4193,10 +4438,11 @@ discard block |
||
| 4193 | 4438 | } |
| 4194 | 4439 | public function setAutoStart($value) |
| 4195 | 4440 | { |
| 4196 | - if($this->_initialized) |
|
| 4197 | - throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
|
| 4198 | - else |
|
| 4199 | - $this->_autoStart=TPropertyValue::ensureBoolean($value); |
|
| 4441 | + if($this->_initialized) { |
|
| 4442 | + throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
|
| 4443 | + } else { |
|
| 4444 | + $this->_autoStart=TPropertyValue::ensureBoolean($value); |
|
| 4445 | + } |
|
| 4200 | 4446 | } |
| 4201 | 4447 | public function getGCProbability() |
| 4202 | 4448 | { |
@@ -4204,18 +4450,18 @@ discard block |
||
| 4204 | 4450 | } |
| 4205 | 4451 | public function setGCProbability($value) |
| 4206 | 4452 | { |
| 4207 | - if($this->_started) |
|
| 4208 | - throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
|
| 4209 | - else |
|
| 4453 | + if($this->_started) { |
|
| 4454 | + throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
|
| 4455 | + } else |
|
| 4210 | 4456 | { |
| 4211 | 4457 | $value=TPropertyValue::ensureInteger($value); |
| 4212 | 4458 | if($value>=0 && $value<=100) |
| 4213 | 4459 | { |
| 4214 | 4460 | ini_set('session.gc_probability',$value); |
| 4215 | 4461 | ini_set('session.gc_divisor','100'); |
| 4462 | + } else { |
|
| 4463 | + throw new TInvalidDataValueException('httpsession_gcprobability_invalid',$value); |
|
| 4216 | 4464 | } |
| 4217 | - else |
|
| 4218 | - throw new TInvalidDataValueException('httpsession_gcprobability_invalid',$value); |
|
| 4219 | 4465 | } |
| 4220 | 4466 | } |
| 4221 | 4467 | public function getUseTransparentSessionID() |
@@ -4224,13 +4470,14 @@ discard block |
||
| 4224 | 4470 | } |
| 4225 | 4471 | public function setUseTransparentSessionID($value) |
| 4226 | 4472 | { |
| 4227 | - if($this->_started) |
|
| 4228 | - throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
|
| 4229 | - else |
|
| 4473 | + if($this->_started) { |
|
| 4474 | + throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
|
| 4475 | + } else |
|
| 4230 | 4476 | { |
| 4231 | 4477 | $value=TPropertyValue::ensureBoolean($value); |
| 4232 | - if ($value && $this->getCookieMode()==THttpSessionCookieMode::Only) |
|
| 4233 | - throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
|
| 4478 | + if ($value && $this->getCookieMode()==THttpSessionCookieMode::Only) { |
|
| 4479 | + throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
|
| 4480 | + } |
|
| 4234 | 4481 | ini_set('session.use_trans_sid',$value?'1':'0'); |
| 4235 | 4482 | } |
| 4236 | 4483 | } |
@@ -4240,10 +4487,11 @@ discard block |
||
| 4240 | 4487 | } |
| 4241 | 4488 | public function setTimeout($value) |
| 4242 | 4489 | { |
| 4243 | - if($this->_started) |
|
| 4244 | - throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
|
| 4245 | - else |
|
| 4246 | - ini_set('session.gc_maxlifetime',$value); |
|
| 4490 | + if($this->_started) { |
|
| 4491 | + throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
|
| 4492 | + } else { |
|
| 4493 | + ini_set('session.gc_maxlifetime',$value); |
|
| 4494 | + } |
|
| 4247 | 4495 | } |
| 4248 | 4496 | public function _open($savePath,$sessionName) |
| 4249 | 4497 | { |
@@ -4300,14 +4548,15 @@ discard block |
||
| 4300 | 4548 | $value=$_SESSION[$key]; |
| 4301 | 4549 | unset($_SESSION[$key]); |
| 4302 | 4550 | return $value; |
| 4551 | + } else { |
|
| 4552 | + return null; |
|
| 4303 | 4553 | } |
| 4304 | - else |
|
| 4305 | - return null; |
|
| 4306 | 4554 | } |
| 4307 | 4555 | public function clear() |
| 4308 | 4556 | { |
| 4309 | - foreach(array_keys($_SESSION) as $key) |
|
| 4310 | - unset($_SESSION[$key]); |
|
| 4557 | + foreach(array_keys($_SESSION) as $key) { |
|
| 4558 | + unset($_SESSION[$key]); |
|
| 4559 | + } |
|
| 4311 | 4560 | } |
| 4312 | 4561 | public function contains($key) |
| 4313 | 4562 | { |
@@ -4380,8 +4629,9 @@ discard block |
||
| 4380 | 4629 | protected function __getZappableSleepProps(&$exprops) |
| 4381 | 4630 | { |
| 4382 | 4631 | parent::__getZappableSleepProps($exprops); |
| 4383 | - if ($this->_caseSensitive===false) |
|
| 4384 | - $exprops[] = "\0TAttributeCollection\0_caseSensitive"; |
|
| 4632 | + if ($this->_caseSensitive===false) { |
|
| 4633 | + $exprops[] = "\0TAttributeCollection\0_caseSensitive"; |
|
| 4634 | + } |
|
| 4385 | 4635 | } |
| 4386 | 4636 | public function __get($name) |
| 4387 | 4637 | { |
@@ -4514,10 +4764,11 @@ discard block |
||
| 4514 | 4764 | private $_rf=array(); |
| 4515 | 4765 | public function __get($name) |
| 4516 | 4766 | { |
| 4517 | - if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name])) |
|
| 4518 | - return $this->_rf[self::RF_NAMED_OBJECTS][$name]; |
|
| 4519 | - else |
|
| 4520 | - return parent::__get($name); |
|
| 4767 | + if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name])) { |
|
| 4768 | + return $this->_rf[self::RF_NAMED_OBJECTS][$name]; |
|
| 4769 | + } else { |
|
| 4770 | + return parent::__get($name); |
|
| 4771 | + } |
|
| 4521 | 4772 | } |
| 4522 | 4773 | public function getHasAdapter() |
| 4523 | 4774 | { |
@@ -4539,10 +4790,11 @@ discard block |
||
| 4539 | 4790 | { |
| 4540 | 4791 | if(!$this->_namingContainer && $this->_parent) |
| 4541 | 4792 | { |
| 4542 | - if($this->_parent instanceof INamingContainer) |
|
| 4543 | - $this->_namingContainer=$this->_parent; |
|
| 4544 | - else |
|
| 4545 | - $this->_namingContainer=$this->_parent->getNamingContainer(); |
|
| 4793 | + if($this->_parent instanceof INamingContainer) { |
|
| 4794 | + $this->_namingContainer=$this->_parent; |
|
| 4795 | + } else { |
|
| 4796 | + $this->_namingContainer=$this->_parent->getNamingContainer(); |
|
| 4797 | + } |
|
| 4546 | 4798 | } |
| 4547 | 4799 | return $this->_namingContainer; |
| 4548 | 4800 | } |
@@ -4550,10 +4802,11 @@ discard block |
||
| 4550 | 4802 | { |
| 4551 | 4803 | if(!$this->_page) |
| 4552 | 4804 | { |
| 4553 | - if($this->_parent) |
|
| 4554 | - $this->_page=$this->_parent->getPage(); |
|
| 4555 | - else if($this->_tplControl) |
|
| 4556 | - $this->_page=$this->_tplControl->getPage(); |
|
| 4805 | + if($this->_parent) { |
|
| 4806 | + $this->_page=$this->_parent->getPage(); |
|
| 4807 | + } else if($this->_tplControl) { |
|
| 4808 | + $this->_page=$this->_tplControl->getPage(); |
|
| 4809 | + } |
|
| 4557 | 4810 | } |
| 4558 | 4811 | return $this->_page; |
| 4559 | 4812 | } |
@@ -4567,8 +4820,9 @@ discard block |
||
| 4567 | 4820 | } |
| 4568 | 4821 | public function getTemplateControl() |
| 4569 | 4822 | { |
| 4570 | - if(!$this->_tplControl && $this->_parent) |
|
| 4571 | - $this->_tplControl=$this->_parent->getTemplateControl(); |
|
| 4823 | + if(!$this->_tplControl && $this->_parent) { |
|
| 4824 | + $this->_tplControl=$this->_parent->getTemplateControl(); |
|
| 4825 | + } |
|
| 4572 | 4826 | return $this->_tplControl; |
| 4573 | 4827 | } |
| 4574 | 4828 | public function getSourceTemplateControl() |
@@ -4576,8 +4830,9 @@ discard block |
||
| 4576 | 4830 | $control=$this; |
| 4577 | 4831 | while(($control instanceof TControl) && ($control=$control->getTemplateControl())!==null) |
| 4578 | 4832 | { |
| 4579 | - if(($control instanceof TTemplateControl) && $control->getIsSourceTemplateControl()) |
|
| 4580 | - return $control; |
|
| 4833 | + if(($control instanceof TTemplateControl) && $control->getIsSourceTemplateControl()) { |
|
| 4834 | + return $control; |
|
| 4835 | + } |
|
| 4581 | 4836 | } |
| 4582 | 4837 | return $this->getPage(); |
| 4583 | 4838 | } |
@@ -4591,37 +4846,42 @@ discard block |
||
| 4591 | 4846 | } |
| 4592 | 4847 | public function getID($hideAutoID=true) |
| 4593 | 4848 | { |
| 4594 | - if($hideAutoID) |
|
| 4595 | - return ($this->_flags & self::IS_ID_SET) ? $this->_id : ''; |
|
| 4596 | - else |
|
| 4597 | - return $this->_id; |
|
| 4849 | + if($hideAutoID) { |
|
| 4850 | + return ($this->_flags & self::IS_ID_SET) ? $this->_id : ''; |
|
| 4851 | + } else { |
|
| 4852 | + return $this->_id; |
|
| 4853 | + } |
|
| 4598 | 4854 | } |
| 4599 | 4855 | public function setID($id) |
| 4600 | 4856 | { |
| 4601 | - if(!preg_match(self::ID_FORMAT,$id)) |
|
| 4602 | - throw new TInvalidDataValueException('control_id_invalid',get_class($this),$id); |
|
| 4857 | + if(!preg_match(self::ID_FORMAT,$id)) { |
|
| 4858 | + throw new TInvalidDataValueException('control_id_invalid',get_class($this),$id); |
|
| 4859 | + } |
|
| 4603 | 4860 | $this->_id=$id; |
| 4604 | 4861 | $this->_flags |= self::IS_ID_SET; |
| 4605 | 4862 | $this->clearCachedUniqueID($this instanceof INamingContainer); |
| 4606 | - if($this->_namingContainer) |
|
| 4607 | - $this->_namingContainer->clearNameTable(); |
|
| 4863 | + if($this->_namingContainer) { |
|
| 4864 | + $this->_namingContainer->clearNameTable(); |
|
| 4865 | + } |
|
| 4608 | 4866 | } |
| 4609 | 4867 | public function getUniqueID() |
| 4610 | 4868 | { |
| 4611 | 4869 | if($this->_uid==='' || $this->_uid===null) { |
| 4612 | 4870 | $this->_uid=''; if($namingContainer=$this->getNamingContainer()) |
| 4613 | 4871 | { |
| 4614 | - if($this->getPage()===$namingContainer) |
|
| 4615 | - return ($this->_uid=$this->_id); |
|
| 4616 | - else if(($prefix=$namingContainer->getUniqueID())==='') |
|
| 4617 | - return $this->_id; |
|
| 4618 | - else |
|
| 4619 | - return ($this->_uid=$prefix.self::ID_SEPARATOR.$this->_id); |
|
| 4872 | + if($this->getPage()===$namingContainer) { |
|
| 4873 | + return ($this->_uid=$this->_id); |
|
| 4874 | + } else if(($prefix=$namingContainer->getUniqueID())==='') { |
|
| 4875 | + return $this->_id; |
|
| 4876 | + } else { |
|
| 4877 | + return ($this->_uid=$prefix.self::ID_SEPARATOR.$this->_id); |
|
| 4878 | + } |
|
| 4879 | + } else { |
|
| 4880 | + return $this->_id; |
|
| 4620 | 4881 | } |
| 4621 | - else return $this->_id; |
|
| 4882 | + } else { |
|
| 4883 | + return $this->_uid; |
|
| 4622 | 4884 | } |
| 4623 | - else |
|
| 4624 | - return $this->_uid; |
|
| 4625 | 4885 | } |
| 4626 | 4886 | public function focus() |
| 4627 | 4887 | { |
@@ -4641,10 +4901,11 @@ discard block |
||
| 4641 | 4901 | } |
| 4642 | 4902 | public function setSkinID($value) |
| 4643 | 4903 | { |
| 4644 | - if(($this->_flags & self::IS_SKIN_APPLIED) || $this->_stage>=self::CS_CHILD_INITIALIZED) |
|
| 4645 | - throw new TInvalidOperationException('control_skinid_unchangeable',get_class($this)); |
|
| 4646 | - else |
|
| 4647 | - $this->_rf[self::RF_SKIN_ID]=$value; |
|
| 4904 | + if(($this->_flags & self::IS_SKIN_APPLIED) || $this->_stage>=self::CS_CHILD_INITIALIZED) { |
|
| 4905 | + throw new TInvalidOperationException('control_skinid_unchangeable',get_class($this)); |
|
| 4906 | + } else { |
|
| 4907 | + $this->_rf[self::RF_SKIN_ID]=$value; |
|
| 4908 | + } |
|
| 4648 | 4909 | } |
| 4649 | 4910 | public function getIsSkinApplied() |
| 4650 | 4911 | { |
@@ -4652,19 +4913,21 @@ discard block |
||
| 4652 | 4913 | } |
| 4653 | 4914 | public function getEnableTheming() |
| 4654 | 4915 | { |
| 4655 | - if($this->_flags & self::IS_DISABLE_THEMING) |
|
| 4656 | - return false; |
|
| 4657 | - else |
|
| 4658 | - return $this->_parent?$this->_parent->getEnableTheming():true; |
|
| 4916 | + if($this->_flags & self::IS_DISABLE_THEMING) { |
|
| 4917 | + return false; |
|
| 4918 | + } else { |
|
| 4919 | + return $this->_parent?$this->_parent->getEnableTheming():true; |
|
| 4920 | + } |
|
| 4659 | 4921 | } |
| 4660 | 4922 | public function setEnableTheming($value) |
| 4661 | 4923 | { |
| 4662 | - if($this->_stage>=self::CS_CHILD_INITIALIZED) |
|
| 4663 | - throw new TInvalidOperationException('control_enabletheming_unchangeable',get_class($this),$this->getUniqueID()); |
|
| 4664 | - else if(TPropertyValue::ensureBoolean($value)) |
|
| 4665 | - $this->_flags &= ~self::IS_DISABLE_THEMING; |
|
| 4666 | - else |
|
| 4667 | - $this->_flags |= self::IS_DISABLE_THEMING; |
|
| 4924 | + if($this->_stage>=self::CS_CHILD_INITIALIZED) { |
|
| 4925 | + throw new TInvalidOperationException('control_enabletheming_unchangeable',get_class($this),$this->getUniqueID()); |
|
| 4926 | + } else if(TPropertyValue::ensureBoolean($value)) { |
|
| 4927 | + $this->_flags &= ~self::IS_DISABLE_THEMING; |
|
| 4928 | + } else { |
|
| 4929 | + $this->_flags |= self::IS_DISABLE_THEMING; |
|
| 4930 | + } |
|
| 4668 | 4931 | } |
| 4669 | 4932 | public function getCustomData() |
| 4670 | 4933 | { |
@@ -4680,8 +4943,9 @@ discard block |
||
| 4680 | 4943 | } |
| 4681 | 4944 | public function getControls() |
| 4682 | 4945 | { |
| 4683 | - if(!isset($this->_rf[self::RF_CONTROLS])) |
|
| 4684 | - $this->_rf[self::RF_CONTROLS]=$this->createControlCollection(); |
|
| 4946 | + if(!isset($this->_rf[self::RF_CONTROLS])) { |
|
| 4947 | + $this->_rf[self::RF_CONTROLS]=$this->createControlCollection(); |
|
| 4948 | + } |
|
| 4685 | 4949 | return $this->_rf[self::RF_CONTROLS]; |
| 4686 | 4950 | } |
| 4687 | 4951 | protected function createControlCollection() |
@@ -4692,13 +4956,14 @@ discard block |
||
| 4692 | 4956 | { |
| 4693 | 4957 | if($checkParents) |
| 4694 | 4958 | { |
| 4695 | - for($control=$this;$control;$control=$control->_parent) |
|
| 4696 | - if(!$control->getVisible(false)) |
|
| 4959 | + for($control=$this;$control;$control=$control->_parent) { |
|
| 4960 | + if(!$control->getVisible(false)) |
|
| 4697 | 4961 | return false; |
| 4962 | + } |
|
| 4698 | 4963 | return true; |
| 4964 | + } else { |
|
| 4965 | + return $this->getViewState('Visible',true); |
|
| 4699 | 4966 | } |
| 4700 | - else |
|
| 4701 | - return $this->getViewState('Visible',true); |
|
| 4702 | 4967 | } |
| 4703 | 4968 | public function setVisible($value) |
| 4704 | 4969 | { |
@@ -4708,13 +4973,14 @@ discard block |
||
| 4708 | 4973 | { |
| 4709 | 4974 | if($checkParents) |
| 4710 | 4975 | { |
| 4711 | - for($control=$this;$control;$control=$control->_parent) |
|
| 4712 | - if(!$control->getViewState('Enabled',true)) |
|
| 4976 | + for($control=$this;$control;$control=$control->_parent) { |
|
| 4977 | + if(!$control->getViewState('Enabled',true)) |
|
| 4713 | 4978 | return false; |
| 4979 | + } |
|
| 4714 | 4980 | return true; |
| 4981 | + } else { |
|
| 4982 | + return $this->getViewState('Enabled',true); |
|
| 4715 | 4983 | } |
| 4716 | - else |
|
| 4717 | - return $this->getViewState('Enabled',true); |
|
| 4718 | 4984 | } |
| 4719 | 4985 | public function setEnabled($value) |
| 4720 | 4986 | { |
@@ -4722,16 +4988,17 @@ discard block |
||
| 4722 | 4988 | } |
| 4723 | 4989 | public function getHasAttributes() |
| 4724 | 4990 | { |
| 4725 | - if($attributes=$this->getViewState('Attributes',null)) |
|
| 4726 | - return $attributes->getCount()>0; |
|
| 4727 | - else |
|
| 4728 | - return false; |
|
| 4991 | + if($attributes=$this->getViewState('Attributes',null)) { |
|
| 4992 | + return $attributes->getCount()>0; |
|
| 4993 | + } else { |
|
| 4994 | + return false; |
|
| 4995 | + } |
|
| 4729 | 4996 | } |
| 4730 | 4997 | public function getAttributes() |
| 4731 | 4998 | { |
| 4732 | - if($attributes=$this->getViewState('Attributes',null)) |
|
| 4733 | - return $attributes; |
|
| 4734 | - else |
|
| 4999 | + if($attributes=$this->getViewState('Attributes',null)) { |
|
| 5000 | + return $attributes; |
|
| 5001 | + } else |
|
| 4735 | 5002 | { |
| 4736 | 5003 | $attributes=new TAttributeCollection; |
| 4737 | 5004 | $this->setViewState('Attributes',$attributes,null); |
@@ -4740,17 +5007,19 @@ discard block |
||
| 4740 | 5007 | } |
| 4741 | 5008 | public function hasAttribute($name) |
| 4742 | 5009 | { |
| 4743 | - if($attributes=$this->getViewState('Attributes',null)) |
|
| 4744 | - return $attributes->contains($name); |
|
| 4745 | - else |
|
| 4746 | - return false; |
|
| 5010 | + if($attributes=$this->getViewState('Attributes',null)) { |
|
| 5011 | + return $attributes->contains($name); |
|
| 5012 | + } else { |
|
| 5013 | + return false; |
|
| 5014 | + } |
|
| 4747 | 5015 | } |
| 4748 | 5016 | public function getAttribute($name) |
| 4749 | 5017 | { |
| 4750 | - if($attributes=$this->getViewState('Attributes',null)) |
|
| 4751 | - return $attributes->itemAt($name); |
|
| 4752 | - else |
|
| 4753 | - return null; |
|
| 5018 | + if($attributes=$this->getViewState('Attributes',null)) { |
|
| 5019 | + return $attributes->itemAt($name); |
|
| 5020 | + } else { |
|
| 5021 | + return null; |
|
| 5022 | + } |
|
| 4754 | 5023 | } |
| 4755 | 5024 | public function setAttribute($name,$value) |
| 4756 | 5025 | { |
@@ -4758,29 +5027,32 @@ discard block |
||
| 4758 | 5027 | } |
| 4759 | 5028 | public function removeAttribute($name) |
| 4760 | 5029 | { |
| 4761 | - if($attributes=$this->getViewState('Attributes',null)) |
|
| 4762 | - return $attributes->remove($name); |
|
| 4763 | - else |
|
| 4764 | - return null; |
|
| 5030 | + if($attributes=$this->getViewState('Attributes',null)) { |
|
| 5031 | + return $attributes->remove($name); |
|
| 5032 | + } else { |
|
| 5033 | + return null; |
|
| 5034 | + } |
|
| 4765 | 5035 | } |
| 4766 | 5036 | public function getEnableViewState($checkParents=false) |
| 4767 | 5037 | { |
| 4768 | 5038 | if($checkParents) |
| 4769 | 5039 | { |
| 4770 | - for($control=$this;$control!==null;$control=$control->getParent()) |
|
| 4771 | - if($control->_flags & self::IS_DISABLE_VIEWSTATE) |
|
| 5040 | + for($control=$this;$control!==null;$control=$control->getParent()) { |
|
| 5041 | + if($control->_flags & self::IS_DISABLE_VIEWSTATE) |
|
| 4772 | 5042 | return false; |
| 5043 | + } |
|
| 4773 | 5044 | return true; |
| 5045 | + } else { |
|
| 5046 | + return !($this->_flags & self::IS_DISABLE_VIEWSTATE); |
|
| 4774 | 5047 | } |
| 4775 | - else |
|
| 4776 | - return !($this->_flags & self::IS_DISABLE_VIEWSTATE); |
|
| 4777 | 5048 | } |
| 4778 | 5049 | public function setEnableViewState($value) |
| 4779 | 5050 | { |
| 4780 | - if(TPropertyValue::ensureBoolean($value)) |
|
| 4781 | - $this->_flags &= ~self::IS_DISABLE_VIEWSTATE; |
|
| 4782 | - else |
|
| 4783 | - $this->_flags |= self::IS_DISABLE_VIEWSTATE; |
|
| 5051 | + if(TPropertyValue::ensureBoolean($value)) { |
|
| 5052 | + $this->_flags &= ~self::IS_DISABLE_VIEWSTATE; |
|
| 5053 | + } else { |
|
| 5054 | + $this->_flags |= self::IS_DISABLE_VIEWSTATE; |
|
| 5055 | + } |
|
| 4784 | 5056 | } |
| 4785 | 5057 | protected function getControlState($key,$defaultValue=null) |
| 4786 | 5058 | { |
@@ -4788,10 +5060,11 @@ discard block |
||
| 4788 | 5060 | } |
| 4789 | 5061 | protected function setControlState($key,$value,$defaultValue=null) |
| 4790 | 5062 | { |
| 4791 | - if($value===$defaultValue) |
|
| 4792 | - unset($this->_rf[self::RF_CONTROLSTATE][$key]); |
|
| 4793 | - else |
|
| 4794 | - $this->_rf[self::RF_CONTROLSTATE][$key]=$value; |
|
| 5063 | + if($value===$defaultValue) { |
|
| 5064 | + unset($this->_rf[self::RF_CONTROLSTATE][$key]); |
|
| 5065 | + } else { |
|
| 5066 | + $this->_rf[self::RF_CONTROLSTATE][$key]=$value; |
|
| 5067 | + } |
|
| 4795 | 5068 | } |
| 4796 | 5069 | protected function clearControlState($key) |
| 4797 | 5070 | { |
@@ -4803,34 +5076,36 @@ discard block |
||
| 4803 | 5076 | } |
| 4804 | 5077 | public function getViewState($key,$defaultValue=null) |
| 4805 | 5078 | { |
| 4806 | - if(isset($this->_viewState[$key])) |
|
| 4807 | - return $this->_viewState[$key]!==null?$this->_viewState[$key]:$defaultValue; |
|
| 4808 | - else if(isset($this->_tempState[$key])) |
|
| 5079 | + if(isset($this->_viewState[$key])) { |
|
| 5080 | + return $this->_viewState[$key]!==null?$this->_viewState[$key]:$defaultValue; |
|
| 5081 | + } else if(isset($this->_tempState[$key])) |
|
| 4809 | 5082 | { |
| 4810 | - if(is_object($this->_tempState[$key]) && $this->_trackViewState) |
|
| 4811 | - $this->_viewState[$key]=$this->_tempState[$key]; |
|
| 5083 | + if(is_object($this->_tempState[$key]) && $this->_trackViewState) { |
|
| 5084 | + $this->_viewState[$key]=$this->_tempState[$key]; |
|
| 5085 | + } |
|
| 4812 | 5086 | return $this->_tempState[$key]; |
| 5087 | + } else { |
|
| 5088 | + return $defaultValue; |
|
| 4813 | 5089 | } |
| 4814 | - else |
|
| 4815 | - return $defaultValue; |
|
| 4816 | 5090 | } |
| 4817 | 5091 | public function setViewState($key,$value,$defaultValue=null) |
| 4818 | 5092 | { |
| 4819 | 5093 | if($this->_trackViewState) |
| 4820 | 5094 | { |
| 4821 | 5095 | unset($this->_tempState[$key]); |
| 4822 | - if($value===$defaultValue) |
|
| 4823 | - unset($this->_viewState[$key]); |
|
| 4824 | - else |
|
| 4825 | - $this->_viewState[$key]=$value; |
|
| 4826 | - } |
|
| 4827 | - else |
|
| 5096 | + if($value===$defaultValue) { |
|
| 5097 | + unset($this->_viewState[$key]); |
|
| 5098 | + } else { |
|
| 5099 | + $this->_viewState[$key]=$value; |
|
| 5100 | + } |
|
| 5101 | + } else |
|
| 4828 | 5102 | { |
| 4829 | 5103 | unset($this->_viewState[$key]); |
| 4830 | - if($value===$defaultValue) |
|
| 4831 | - unset($this->_tempState[$key]); |
|
| 4832 | - else |
|
| 4833 | - $this->_tempState[$key]=$value; |
|
| 5104 | + if($value===$defaultValue) { |
|
| 5105 | + unset($this->_tempState[$key]); |
|
| 5106 | + } else { |
|
| 5107 | + $this->_tempState[$key]=$value; |
|
| 5108 | + } |
|
| 4834 | 5109 | } |
| 4835 | 5110 | } |
| 4836 | 5111 | public function clearViewState($key) |
@@ -4860,29 +5135,34 @@ discard block |
||
| 4860 | 5135 | { |
| 4861 | 5136 | if(isset($this->_rf[self::RF_DATA_BINDINGS])) |
| 4862 | 5137 | { |
| 4863 | - if(($context=$this->getTemplateControl())===null) |
|
| 4864 | - $context=$this; |
|
| 4865 | - foreach($this->_rf[self::RF_DATA_BINDINGS] as $property=>$expression) |
|
| 4866 | - $this->setSubProperty($property,$context->evaluateExpression($expression)); |
|
| 5138 | + if(($context=$this->getTemplateControl())===null) { |
|
| 5139 | + $context=$this; |
|
| 5140 | + } |
|
| 5141 | + foreach($this->_rf[self::RF_DATA_BINDINGS] as $property=>$expression) { |
|
| 5142 | + $this->setSubProperty($property,$context->evaluateExpression($expression)); |
|
| 5143 | + } |
|
| 4867 | 5144 | } |
| 4868 | 5145 | } |
| 4869 | 5146 | protected function autoDataBindProperties() |
| 4870 | 5147 | { |
| 4871 | 5148 | if(isset($this->_rf[self::RF_AUTO_BINDINGS])) |
| 4872 | 5149 | { |
| 4873 | - if(($context=$this->getTemplateControl())===null) |
|
| 4874 | - $context=$this; |
|
| 4875 | - foreach($this->_rf[self::RF_AUTO_BINDINGS] as $property=>$expression) |
|
| 4876 | - $this->setSubProperty($property,$context->evaluateExpression($expression)); |
|
| 5150 | + if(($context=$this->getTemplateControl())===null) { |
|
| 5151 | + $context=$this; |
|
| 5152 | + } |
|
| 5153 | + foreach($this->_rf[self::RF_AUTO_BINDINGS] as $property=>$expression) { |
|
| 5154 | + $this->setSubProperty($property,$context->evaluateExpression($expression)); |
|
| 5155 | + } |
|
| 4877 | 5156 | } |
| 4878 | 5157 | } |
| 4879 | 5158 | protected function dataBindChildren() |
| 4880 | 5159 | { |
| 4881 | 5160 | if(isset($this->_rf[self::RF_CONTROLS])) |
| 4882 | 5161 | { |
| 4883 | - foreach($this->_rf[self::RF_CONTROLS] as $control) |
|
| 4884 | - if($control instanceof IBindable) |
|
| 5162 | + foreach($this->_rf[self::RF_CONTROLS] as $control) { |
|
| 5163 | + if($control instanceof IBindable) |
|
| 4885 | 5164 | $control->dataBind(); |
| 5165 | + } |
|
| 4886 | 5166 | } |
| 4887 | 5167 | } |
| 4888 | 5168 | final protected function getChildControlsCreated() |
@@ -4891,12 +5171,13 @@ discard block |
||
| 4891 | 5171 | } |
| 4892 | 5172 | final protected function setChildControlsCreated($value) |
| 4893 | 5173 | { |
| 4894 | - if($value) |
|
| 4895 | - $this->_flags |= self::IS_CHILD_CREATED; |
|
| 4896 | - else |
|
| 5174 | + if($value) { |
|
| 5175 | + $this->_flags |= self::IS_CHILD_CREATED; |
|
| 5176 | + } else |
|
| 4897 | 5177 | { |
| 4898 | - if($this->getHasControls() && ($this->_flags & self::IS_CHILD_CREATED)) |
|
| 4899 | - $this->getControls()->clear(); |
|
| 5178 | + if($this->getHasControls() && ($this->_flags & self::IS_CHILD_CREATED)) { |
|
| 5179 | + $this->getControls()->clear(); |
|
| 5180 | + } |
|
| 4900 | 5181 | $this->_flags &= ~self::IS_CHILD_CREATED; |
| 4901 | 5182 | } |
| 4902 | 5183 | } |
@@ -4907,14 +5188,14 @@ discard block |
||
| 4907 | 5188 | try |
| 4908 | 5189 | { |
| 4909 | 5190 | $this->_flags |= self::IS_CREATING_CHILD; |
| 4910 | - if(isset($this->_rf[self::RF_ADAPTER])) |
|
| 4911 | - $this->_rf[self::RF_ADAPTER]->createChildControls(); |
|
| 4912 | - else |
|
| 4913 | - $this->createChildControls(); |
|
| 5191 | + if(isset($this->_rf[self::RF_ADAPTER])) { |
|
| 5192 | + $this->_rf[self::RF_ADAPTER]->createChildControls(); |
|
| 5193 | + } else { |
|
| 5194 | + $this->createChildControls(); |
|
| 5195 | + } |
|
| 4914 | 5196 | $this->_flags &= ~self::IS_CREATING_CHILD; |
| 4915 | 5197 | $this->_flags |= self::IS_CHILD_CREATED; |
| 4916 | - } |
|
| 4917 | - catch(Exception $e) |
|
| 5198 | + } catch(Exception $e) |
|
| 4918 | 5199 | { |
| 4919 | 5200 | $this->_flags &= ~self::IS_CREATING_CHILD; |
| 4920 | 5201 | $this->_flags |= self::IS_CHILD_CREATED; |
@@ -4929,23 +5210,25 @@ discard block |
||
| 4929 | 5210 | { |
| 4930 | 5211 | $id=strtr($id,'.',self::ID_SEPARATOR); |
| 4931 | 5212 | $container=($this instanceof INamingContainer)?$this:$this->getNamingContainer(); |
| 4932 | - if(!$container || !$container->getHasControls()) |
|
| 4933 | - return null; |
|
| 5213 | + if(!$container || !$container->getHasControls()) { |
|
| 5214 | + return null; |
|
| 5215 | + } |
|
| 4934 | 5216 | if(!isset($container->_rf[self::RF_NAMED_CONTROLS])) |
| 4935 | 5217 | { |
| 4936 | 5218 | $container->_rf[self::RF_NAMED_CONTROLS]=array(); |
| 4937 | 5219 | $container->fillNameTable($container,$container->_rf[self::RF_CONTROLS]); |
| 4938 | 5220 | } |
| 4939 | - if(($pos=strpos($id,self::ID_SEPARATOR))===false) |
|
| 4940 | - return isset($container->_rf[self::RF_NAMED_CONTROLS][$id])?$container->_rf[self::RF_NAMED_CONTROLS][$id]:null; |
|
| 4941 | - else |
|
| 5221 | + if(($pos=strpos($id,self::ID_SEPARATOR))===false) { |
|
| 5222 | + return isset($container->_rf[self::RF_NAMED_CONTROLS][$id])?$container->_rf[self::RF_NAMED_CONTROLS][$id]:null; |
|
| 5223 | + } else |
|
| 4942 | 5224 | { |
| 4943 | 5225 | $cid=substr($id,0,$pos); |
| 4944 | 5226 | $sid=substr($id,$pos+1); |
| 4945 | - if(isset($container->_rf[self::RF_NAMED_CONTROLS][$cid])) |
|
| 4946 | - return $container->_rf[self::RF_NAMED_CONTROLS][$cid]->findControl($sid); |
|
| 4947 | - else |
|
| 4948 | - return null; |
|
| 5227 | + if(isset($container->_rf[self::RF_NAMED_CONTROLS][$cid])) { |
|
| 5228 | + return $container->_rf[self::RF_NAMED_CONTROLS][$cid]->findControl($sid); |
|
| 5229 | + } else { |
|
| 5230 | + return null; |
|
| 5231 | + } |
|
| 4949 | 5232 | } |
| 4950 | 5233 | } |
| 4951 | 5234 | public function findControlsByType($type,$strict=true) |
@@ -4955,10 +5238,12 @@ discard block |
||
| 4955 | 5238 | { |
| 4956 | 5239 | foreach($this->_rf[self::RF_CONTROLS] as $control) |
| 4957 | 5240 | { |
| 4958 | - if(is_object($control) && (get_class($control)===$type || (!$strict && ($control instanceof $type)))) |
|
| 4959 | - $controls[]=$control; |
|
| 4960 | - if(($control instanceof TControl) && $control->getHasControls()) |
|
| 4961 | - $controls=array_merge($controls,$control->findControlsByType($type,$strict)); |
|
| 5241 | + if(is_object($control) && (get_class($control)===$type || (!$strict && ($control instanceof $type)))) { |
|
| 5242 | + $controls[]=$control; |
|
| 5243 | + } |
|
| 5244 | + if(($control instanceof TControl) && $control->getHasControls()) { |
|
| 5245 | + $controls=array_merge($controls,$control->findControlsByType($type,$strict)); |
|
| 5246 | + } |
|
| 4962 | 5247 | } |
| 4963 | 5248 | } |
| 4964 | 5249 | return $controls; |
@@ -4972,8 +5257,9 @@ discard block |
||
| 4972 | 5257 | { |
| 4973 | 5258 | if($control instanceof TControl) |
| 4974 | 5259 | { |
| 4975 | - if($control->_id===$id) |
|
| 4976 | - $controls[]=$control; |
|
| 5260 | + if($control->_id===$id) { |
|
| 5261 | + $controls[]=$control; |
|
| 5262 | + } |
|
| 4977 | 5263 | $controls=array_merge($controls,$control->findControlsByID($id)); |
| 4978 | 5264 | } |
| 4979 | 5265 | } |
@@ -4987,8 +5273,9 @@ discard block |
||
| 4987 | 5273 | } |
| 4988 | 5274 | public function registerObject($name,$object) |
| 4989 | 5275 | { |
| 4990 | - if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name])) |
|
| 4991 | - throw new TInvalidOperationException('control_object_reregistered',$name); |
|
| 5276 | + if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name])) { |
|
| 5277 | + throw new TInvalidOperationException('control_object_reregistered',$name); |
|
| 5278 | + } |
|
| 4992 | 5279 | $this->_rf[self::RF_NAMED_OBJECTS][$name]=$object; |
| 4993 | 5280 | } |
| 4994 | 5281 | public function unregisterObject($name) |
@@ -5038,24 +5325,27 @@ discard block |
||
| 5038 | 5325 | final protected function isDescendentOf($ancestor) |
| 5039 | 5326 | { |
| 5040 | 5327 | $control=$this; |
| 5041 | - while($control!==$ancestor && $control->_parent) |
|
| 5042 | - $control=$control->_parent; |
|
| 5328 | + while($control!==$ancestor && $control->_parent) { |
|
| 5329 | + $control=$control->_parent; |
|
| 5330 | + } |
|
| 5043 | 5331 | return $control===$ancestor; |
| 5044 | 5332 | } |
| 5045 | 5333 | public function addedControl($control) |
| 5046 | 5334 | { |
| 5047 | - if($control->_parent) |
|
| 5048 | - $control->_parent->getControls()->remove($control); |
|
| 5335 | + if($control->_parent) { |
|
| 5336 | + $control->_parent->getControls()->remove($control); |
|
| 5337 | + } |
|
| 5049 | 5338 | $control->_parent=$this; |
| 5050 | 5339 | $control->_page=$this->getPage(); |
| 5051 | 5340 | $namingContainer=($this instanceof INamingContainer)?$this:$this->_namingContainer; |
| 5052 | 5341 | if($namingContainer) |
| 5053 | 5342 | { |
| 5054 | 5343 | $control->_namingContainer=$namingContainer; |
| 5055 | - if($control->_id==='') |
|
| 5056 | - $control->generateAutomaticID(); |
|
| 5057 | - else |
|
| 5058 | - $namingContainer->clearNameTable(); |
|
| 5344 | + if($control->_id==='') { |
|
| 5345 | + $control->generateAutomaticID(); |
|
| 5346 | + } else { |
|
| 5347 | + $namingContainer->clearNameTable(); |
|
| 5348 | + } |
|
| 5059 | 5349 | $control->clearCachedUniqueID($control instanceof INamingContainer); |
| 5060 | 5350 | } |
| 5061 | 5351 | if($this->_stage>=self::CS_CHILD_INITIALIZED) |
@@ -5067,32 +5357,35 @@ discard block |
||
| 5067 | 5357 | { |
| 5068 | 5358 | $state=$this->_rf[self::RF_CHILD_STATE][$control->_id]; |
| 5069 | 5359 | unset($this->_rf[self::RF_CHILD_STATE][$control->_id]); |
| 5360 | + } else { |
|
| 5361 | + $state=null; |
|
| 5070 | 5362 | } |
| 5071 | - else |
|
| 5072 | - $state=null; |
|
| 5073 | 5363 | $control->loadStateRecursive($state,!($this->_flags & self::IS_DISABLE_VIEWSTATE)); |
| 5074 | 5364 | if($this->_stage>=self::CS_LOADED) |
| 5075 | 5365 | { |
| 5076 | 5366 | $control->loadRecursive(); |
| 5077 | - if($this->_stage>=self::CS_PRERENDERED) |
|
| 5078 | - $control->preRenderRecursive(); |
|
| 5367 | + if($this->_stage>=self::CS_PRERENDERED) { |
|
| 5368 | + $control->preRenderRecursive(); |
|
| 5369 | + } |
|
| 5079 | 5370 | } |
| 5080 | 5371 | } |
| 5081 | 5372 | } |
| 5082 | 5373 | } |
| 5083 | 5374 | public function removedControl($control) |
| 5084 | 5375 | { |
| 5085 | - if($this->_namingContainer) |
|
| 5086 | - $this->_namingContainer->clearNameTable(); |
|
| 5376 | + if($this->_namingContainer) { |
|
| 5377 | + $this->_namingContainer->clearNameTable(); |
|
| 5378 | + } |
|
| 5087 | 5379 | $control->unloadRecursive(); |
| 5088 | 5380 | $control->_parent=null; |
| 5089 | 5381 | $control->_page=null; |
| 5090 | 5382 | $control->_namingContainer=null; |
| 5091 | 5383 | $control->_tplControl=null; |
| 5092 | - if(!($control->_flags & self::IS_ID_SET)) |
|
| 5093 | - $control->_id=''; |
|
| 5094 | - else |
|
| 5095 | - unset($this->_rf[self::RF_NAMED_OBJECTS][$control->_id]); |
|
| 5384 | + if(!($control->_flags & self::IS_ID_SET)) { |
|
| 5385 | + $control->_id=''; |
|
| 5386 | + } else { |
|
| 5387 | + unset($this->_rf[self::RF_NAMED_OBJECTS][$control->_id]); |
|
| 5388 | + } |
|
| 5096 | 5389 | $control->clearCachedUniqueID(true); |
| 5097 | 5390 | } |
| 5098 | 5391 | protected function initRecursive($namingContainer=null) |
@@ -5100,8 +5393,9 @@ discard block |
||
| 5100 | 5393 | $this->ensureChildControls(); |
| 5101 | 5394 | if($this->getHasControls()) |
| 5102 | 5395 | { |
| 5103 | - if($this instanceof INamingContainer) |
|
| 5104 | - $namingContainer=$this; |
|
| 5396 | + if($this instanceof INamingContainer) { |
|
| 5397 | + $namingContainer=$this; |
|
| 5398 | + } |
|
| 5105 | 5399 | $page=$this->getPage(); |
| 5106 | 5400 | foreach($this->_rf[self::RF_CONTROLS] as $control) |
| 5107 | 5401 | { |
@@ -5109,8 +5403,9 @@ discard block |
||
| 5109 | 5403 | { |
| 5110 | 5404 | $control->_namingContainer=$namingContainer; |
| 5111 | 5405 | $control->_page=$page; |
| 5112 | - if($control->_id==='' && $namingContainer) |
|
| 5113 | - $control->generateAutomaticID(); |
|
| 5406 | + if($control->_id==='' && $namingContainer) { |
|
| 5407 | + $control->generateAutomaticID(); |
|
| 5408 | + } |
|
| 5114 | 5409 | $control->initRecursive($namingContainer); |
| 5115 | 5410 | } |
| 5116 | 5411 | } |
@@ -5123,10 +5418,11 @@ discard block |
||
| 5123 | 5418 | $page->applyControlSkin($this); |
| 5124 | 5419 | $this->_flags |= self::IS_SKIN_APPLIED; |
| 5125 | 5420 | } |
| 5126 | - if(isset($this->_rf[self::RF_ADAPTER])) |
|
| 5127 | - $this->_rf[self::RF_ADAPTER]->onInit(null); |
|
| 5128 | - else |
|
| 5129 | - $this->onInit(null); |
|
| 5421 | + if(isset($this->_rf[self::RF_ADAPTER])) { |
|
| 5422 | + $this->_rf[self::RF_ADAPTER]->onInit(null); |
|
| 5423 | + } else { |
|
| 5424 | + $this->onInit(null); |
|
| 5425 | + } |
|
| 5130 | 5426 | $this->_stage=self::CS_INITIALIZED; |
| 5131 | 5427 | } |
| 5132 | 5428 | } |
@@ -5134,39 +5430,44 @@ discard block |
||
| 5134 | 5430 | { |
| 5135 | 5431 | if($this->_stage<self::CS_LOADED) |
| 5136 | 5432 | { |
| 5137 | - if(isset($this->_rf[self::RF_ADAPTER])) |
|
| 5138 | - $this->_rf[self::RF_ADAPTER]->onLoad(null); |
|
| 5139 | - else |
|
| 5140 | - $this->onLoad(null); |
|
| 5433 | + if(isset($this->_rf[self::RF_ADAPTER])) { |
|
| 5434 | + $this->_rf[self::RF_ADAPTER]->onLoad(null); |
|
| 5435 | + } else { |
|
| 5436 | + $this->onLoad(null); |
|
| 5437 | + } |
|
| 5141 | 5438 | } |
| 5142 | 5439 | if($this->getHasControls()) |
| 5143 | 5440 | { |
| 5144 | 5441 | foreach($this->_rf[self::RF_CONTROLS] as $control) |
| 5145 | 5442 | { |
| 5146 | - if($control instanceof TControl) |
|
| 5147 | - $control->loadRecursive(); |
|
| 5443 | + if($control instanceof TControl) { |
|
| 5444 | + $control->loadRecursive(); |
|
| 5445 | + } |
|
| 5148 | 5446 | } |
| 5149 | 5447 | } |
| 5150 | - if($this->_stage<self::CS_LOADED) |
|
| 5151 | - $this->_stage=self::CS_LOADED; |
|
| 5448 | + if($this->_stage<self::CS_LOADED) { |
|
| 5449 | + $this->_stage=self::CS_LOADED; |
|
| 5450 | + } |
|
| 5152 | 5451 | } |
| 5153 | 5452 | protected function preRenderRecursive() |
| 5154 | 5453 | { |
| 5155 | 5454 | $this->autoDataBindProperties(); |
| 5156 | 5455 | if($this->getVisible(false)) |
| 5157 | 5456 | { |
| 5158 | - if(isset($this->_rf[self::RF_ADAPTER])) |
|
| 5159 | - $this->_rf[self::RF_ADAPTER]->onPreRender(null); |
|
| 5160 | - else |
|
| 5161 | - $this->onPreRender(null); |
|
| 5457 | + if(isset($this->_rf[self::RF_ADAPTER])) { |
|
| 5458 | + $this->_rf[self::RF_ADAPTER]->onPreRender(null); |
|
| 5459 | + } else { |
|
| 5460 | + $this->onPreRender(null); |
|
| 5461 | + } |
|
| 5162 | 5462 | if($this->getHasControls()) |
| 5163 | 5463 | { |
| 5164 | 5464 | foreach($this->_rf[self::RF_CONTROLS] as $control) |
| 5165 | 5465 | { |
| 5166 | - if($control instanceof TControl) |
|
| 5167 | - $control->preRenderRecursive(); |
|
| 5168 | - else if($control instanceof TCompositeLiteral) |
|
| 5169 | - $control->evaluateDynamicContent(); |
|
| 5466 | + if($control instanceof TControl) { |
|
| 5467 | + $control->preRenderRecursive(); |
|
| 5468 | + } else if($control instanceof TCompositeLiteral) { |
|
| 5469 | + $control->evaluateDynamicContent(); |
|
| 5470 | + } |
|
| 5170 | 5471 | } |
| 5171 | 5472 | } |
| 5172 | 5473 | } |
@@ -5174,18 +5475,21 @@ discard block |
||
| 5174 | 5475 | } |
| 5175 | 5476 | protected function unloadRecursive() |
| 5176 | 5477 | { |
| 5177 | - if(!($this->_flags & self::IS_ID_SET)) |
|
| 5178 | - $this->_id=''; |
|
| 5478 | + if(!($this->_flags & self::IS_ID_SET)) { |
|
| 5479 | + $this->_id=''; |
|
| 5480 | + } |
|
| 5179 | 5481 | if($this->getHasControls()) |
| 5180 | 5482 | { |
| 5181 | - foreach($this->_rf[self::RF_CONTROLS] as $control) |
|
| 5182 | - if($control instanceof TControl) |
|
| 5483 | + foreach($this->_rf[self::RF_CONTROLS] as $control) { |
|
| 5484 | + if($control instanceof TControl) |
|
| 5183 | 5485 | $control->unloadRecursive(); |
| 5486 | + } |
|
| 5487 | + } |
|
| 5488 | + if(isset($this->_rf[self::RF_ADAPTER])) { |
|
| 5489 | + $this->_rf[self::RF_ADAPTER]->onUnload(null); |
|
| 5490 | + } else { |
|
| 5491 | + $this->onUnload(null); |
|
| 5184 | 5492 | } |
| 5185 | - if(isset($this->_rf[self::RF_ADAPTER])) |
|
| 5186 | - $this->_rf[self::RF_ADAPTER]->onUnload(null); |
|
| 5187 | - else |
|
| 5188 | - $this->onUnload(null); |
|
| 5189 | 5493 | } |
| 5190 | 5494 | public function onInit($param) |
| 5191 | 5495 | { |
@@ -5212,8 +5516,9 @@ discard block |
||
| 5212 | 5516 | $control=$this; |
| 5213 | 5517 | while($control=$control->_parent) |
| 5214 | 5518 | { |
| 5215 | - if($control->bubbleEvent($sender,$param)) |
|
| 5216 | - break; |
|
| 5519 | + if($control->bubbleEvent($sender,$param)) { |
|
| 5520 | + break; |
|
| 5521 | + } |
|
| 5217 | 5522 | } |
| 5218 | 5523 | } |
| 5219 | 5524 | public function bubbleEvent($sender,$param) |
@@ -5227,23 +5532,27 @@ discard block |
||
| 5227 | 5532 | } |
| 5228 | 5533 | private function broadcastEventInternal($name,$sender,$param) |
| 5229 | 5534 | { |
| 5230 | - if($this->hasEvent($name)) |
|
| 5231 | - $this->raiseEvent($name,$sender,$param->getParameter()); |
|
| 5232 | - if($this instanceof IBroadcastEventReceiver) |
|
| 5233 | - $this->broadcastEventReceived($sender,$param); |
|
| 5535 | + if($this->hasEvent($name)) { |
|
| 5536 | + $this->raiseEvent($name,$sender,$param->getParameter()); |
|
| 5537 | + } |
|
| 5538 | + if($this instanceof IBroadcastEventReceiver) { |
|
| 5539 | + $this->broadcastEventReceived($sender,$param); |
|
| 5540 | + } |
|
| 5234 | 5541 | if($this->getHasControls()) |
| 5235 | 5542 | { |
| 5236 | 5543 | foreach($this->_rf[self::RF_CONTROLS] as $control) |
| 5237 | 5544 | { |
| 5238 | - if($control instanceof TControl) |
|
| 5239 | - $control->broadcastEventInternal($name,$sender,$param); |
|
| 5545 | + if($control instanceof TControl) { |
|
| 5546 | + $control->broadcastEventInternal($name,$sender,$param); |
|
| 5547 | + } |
|
| 5240 | 5548 | } |
| 5241 | 5549 | } |
| 5242 | 5550 | } |
| 5243 | 5551 | protected function traverseChildControls($param,$preCallback=null,$postCallback=null) |
| 5244 | 5552 | { |
| 5245 | - if($preCallback!==null) |
|
| 5246 | - call_user_func($preCallback,$this,$param); |
|
| 5553 | + if($preCallback!==null) { |
|
| 5554 | + call_user_func($preCallback,$this,$param); |
|
| 5555 | + } |
|
| 5247 | 5556 | if($this->getHasControls()) |
| 5248 | 5557 | { |
| 5249 | 5558 | foreach($this->_rf[self::RF_CONTROLS] as $control) |
@@ -5254,17 +5563,19 @@ discard block |
||
| 5254 | 5563 | } |
| 5255 | 5564 | } |
| 5256 | 5565 | } |
| 5257 | - if($postCallback!==null) |
|
| 5258 | - call_user_func($postCallback,$this,$param); |
|
| 5566 | + if($postCallback!==null) { |
|
| 5567 | + call_user_func($postCallback,$this,$param); |
|
| 5568 | + } |
|
| 5259 | 5569 | } |
| 5260 | 5570 | public function renderControl($writer) |
| 5261 | 5571 | { |
| 5262 | 5572 | if($this instanceof IActiveControl || $this->getVisible(false)) |
| 5263 | 5573 | { |
| 5264 | - if(isset($this->_rf[self::RF_ADAPTER])) |
|
| 5265 | - $this->_rf[self::RF_ADAPTER]->render($writer); |
|
| 5266 | - else |
|
| 5267 | - $this->render($writer); |
|
| 5574 | + if(isset($this->_rf[self::RF_ADAPTER])) { |
|
| 5575 | + $this->_rf[self::RF_ADAPTER]->render($writer); |
|
| 5576 | + } else { |
|
| 5577 | + $this->render($writer); |
|
| 5578 | + } |
|
| 5268 | 5579 | } |
| 5269 | 5580 | } |
| 5270 | 5581 | public function render($writer) |
@@ -5277,12 +5588,13 @@ discard block |
||
| 5277 | 5588 | { |
| 5278 | 5589 | foreach($this->_rf[self::RF_CONTROLS] as $control) |
| 5279 | 5590 | { |
| 5280 | - if(is_string($control)) |
|
| 5281 | - $writer->write($control); |
|
| 5282 | - else if($control instanceof TControl) |
|
| 5283 | - $control->renderControl($writer); |
|
| 5284 | - else if($control instanceof IRenderable) |
|
| 5285 | - $control->render($writer); |
|
| 5591 | + if(is_string($control)) { |
|
| 5592 | + $writer->write($control); |
|
| 5593 | + } else if($control instanceof TControl) { |
|
| 5594 | + $control->renderControl($writer); |
|
| 5595 | + } else if($control instanceof IRenderable) { |
|
| 5596 | + $control->render($writer); |
|
| 5597 | + } |
|
| 5286 | 5598 | } |
| 5287 | 5599 | } |
| 5288 | 5600 | } |
@@ -5301,15 +5613,16 @@ discard block |
||
| 5301 | 5613 | { |
| 5302 | 5614 | $this->_rf[self::RF_CONTROLSTATE]=&$state[1]; |
| 5303 | 5615 | unset($state[1]); |
| 5616 | + } else { |
|
| 5617 | + unset($this->_rf[self::RF_CONTROLSTATE]); |
|
| 5304 | 5618 | } |
| 5305 | - else |
|
| 5306 | - unset($this->_rf[self::RF_CONTROLSTATE]); |
|
| 5307 | 5619 | if($needViewState) |
| 5308 | 5620 | { |
| 5309 | - if(isset($state[0])) |
|
| 5310 | - $this->_viewState=&$state[0]; |
|
| 5311 | - else |
|
| 5312 | - $this->_viewState=array(); |
|
| 5621 | + if(isset($state[0])) { |
|
| 5622 | + $this->_viewState=&$state[0]; |
|
| 5623 | + } else { |
|
| 5624 | + $this->_viewState=array(); |
|
| 5625 | + } |
|
| 5313 | 5626 | } |
| 5314 | 5627 | unset($state[0]); |
| 5315 | 5628 | if($this->getHasControls()) |
@@ -5326,21 +5639,24 @@ discard block |
||
| 5326 | 5639 | } |
| 5327 | 5640 | } |
| 5328 | 5641 | } |
| 5329 | - if(!empty($state)) |
|
| 5330 | - $this->_rf[self::RF_CHILD_STATE]=&$state; |
|
| 5642 | + if(!empty($state)) { |
|
| 5643 | + $this->_rf[self::RF_CHILD_STATE]=&$state; |
|
| 5644 | + } |
|
| 5331 | 5645 | } |
| 5332 | 5646 | $this->_stage=self::CS_STATE_LOADED; |
| 5333 | - if(isset($this->_rf[self::RF_ADAPTER])) |
|
| 5334 | - $this->_rf[self::RF_ADAPTER]->loadState(); |
|
| 5335 | - else |
|
| 5336 | - $this->loadState(); |
|
| 5647 | + if(isset($this->_rf[self::RF_ADAPTER])) { |
|
| 5648 | + $this->_rf[self::RF_ADAPTER]->loadState(); |
|
| 5649 | + } else { |
|
| 5650 | + $this->loadState(); |
|
| 5651 | + } |
|
| 5337 | 5652 | } |
| 5338 | 5653 | protected function &saveStateRecursive($needViewState=true) |
| 5339 | 5654 | { |
| 5340 | - if(isset($this->_rf[self::RF_ADAPTER])) |
|
| 5341 | - $this->_rf[self::RF_ADAPTER]->saveState(); |
|
| 5342 | - else |
|
| 5343 | - $this->saveState(); |
|
| 5655 | + if(isset($this->_rf[self::RF_ADAPTER])) { |
|
| 5656 | + $this->_rf[self::RF_ADAPTER]->saveState(); |
|
| 5657 | + } else { |
|
| 5658 | + $this->saveState(); |
|
| 5659 | + } |
|
| 5344 | 5660 | $needViewState=($needViewState && !($this->_flags & self::IS_DISABLE_VIEWSTATE)); |
| 5345 | 5661 | $state=array(); |
| 5346 | 5662 | if($this->getHasControls()) |
@@ -5349,15 +5665,18 @@ discard block |
||
| 5349 | 5665 | { |
| 5350 | 5666 | if($control instanceof TControl) |
| 5351 | 5667 | { |
| 5352 | - if(count($tmp = &$control->saveStateRecursive($needViewState))) |
|
| 5353 | - $state[$control->_id]=$tmp; |
|
| 5668 | + if(count($tmp = &$control->saveStateRecursive($needViewState))) { |
|
| 5669 | + $state[$control->_id]=$tmp; |
|
| 5670 | + } |
|
| 5354 | 5671 | } |
| 5355 | 5672 | } |
| 5356 | 5673 | } |
| 5357 | - if($needViewState && !empty($this->_viewState)) |
|
| 5358 | - $state[0]=&$this->_viewState; |
|
| 5359 | - if(isset($this->_rf[self::RF_CONTROLSTATE])) |
|
| 5360 | - $state[1]=&$this->_rf[self::RF_CONTROLSTATE]; |
|
| 5674 | + if($needViewState && !empty($this->_viewState)) { |
|
| 5675 | + $state[0]=&$this->_viewState; |
|
| 5676 | + } |
|
| 5677 | + if(isset($this->_rf[self::RF_CONTROLSTATE])) { |
|
| 5678 | + $state[1]=&$this->_rf[self::RF_CONTROLSTATE]; |
|
| 5679 | + } |
|
| 5361 | 5680 | return $state; |
| 5362 | 5681 | } |
| 5363 | 5682 | public function applyStyleSheetSkin($page) |
@@ -5366,25 +5685,27 @@ discard block |
||
| 5366 | 5685 | { |
| 5367 | 5686 | $page->applyControlStyleSheet($this); |
| 5368 | 5687 | $this->_flags |= self::IS_STYLESHEET_APPLIED; |
| 5688 | + } else if($this->_flags & self::IS_STYLESHEET_APPLIED) { |
|
| 5689 | + throw new TInvalidOperationException('control_stylesheet_applied',get_class($this)); |
|
| 5369 | 5690 | } |
| 5370 | - else if($this->_flags & self::IS_STYLESHEET_APPLIED) |
|
| 5371 | - throw new TInvalidOperationException('control_stylesheet_applied',get_class($this)); |
|
| 5372 | 5691 | } |
| 5373 | 5692 | private function clearCachedUniqueID($recursive) |
| 5374 | 5693 | { |
| 5375 | 5694 | if($recursive && $this->_uid!==null && isset($this->_rf[self::RF_CONTROLS])) |
| 5376 | 5695 | { |
| 5377 | - foreach($this->_rf[self::RF_CONTROLS] as $control) |
|
| 5378 | - if($control instanceof TControl) |
|
| 5696 | + foreach($this->_rf[self::RF_CONTROLS] as $control) { |
|
| 5697 | + if($control instanceof TControl) |
|
| 5379 | 5698 | $control->clearCachedUniqueID($recursive); |
| 5699 | + } |
|
| 5380 | 5700 | } |
| 5381 | 5701 | $this->_uid=null; |
| 5382 | 5702 | } |
| 5383 | 5703 | private function generateAutomaticID() |
| 5384 | 5704 | { |
| 5385 | 5705 | $this->_flags &= ~self::IS_ID_SET; |
| 5386 | - if(!isset($this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID])) |
|
| 5387 | - $this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]=0; |
|
| 5706 | + if(!isset($this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID])) { |
|
| 5707 | + $this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]=0; |
|
| 5708 | + } |
|
| 5388 | 5709 | $id=$this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]++; |
| 5389 | 5710 | $this->_id=self::AUTOMATIC_ID_PREFIX . $id; |
| 5390 | 5711 | $this->_namingContainer->clearNameTable(); |
@@ -5401,13 +5722,15 @@ discard block |
||
| 5401 | 5722 | { |
| 5402 | 5723 | if($control->_id!=='') |
| 5403 | 5724 | { |
| 5404 | - if(isset($container->_rf[self::RF_NAMED_CONTROLS][$control->_id])) |
|
| 5405 | - throw new TInvalidDataValueException('control_id_nonunique',get_class($control),$control->_id); |
|
| 5406 | - else |
|
| 5407 | - $container->_rf[self::RF_NAMED_CONTROLS][$control->_id]=$control; |
|
| 5725 | + if(isset($container->_rf[self::RF_NAMED_CONTROLS][$control->_id])) { |
|
| 5726 | + throw new TInvalidDataValueException('control_id_nonunique',get_class($control),$control->_id); |
|
| 5727 | + } else { |
|
| 5728 | + $container->_rf[self::RF_NAMED_CONTROLS][$control->_id]=$control; |
|
| 5729 | + } |
|
| 5730 | + } |
|
| 5731 | + if(!($control instanceof INamingContainer) && $control->getHasControls()) { |
|
| 5732 | + $this->fillNameTable($container,$control->_rf[self::RF_CONTROLS]); |
|
| 5408 | 5733 | } |
| 5409 | - if(!($control instanceof INamingContainer) && $control->getHasControls()) |
|
| 5410 | - $this->fillNameTable($container,$control->_rf[self::RF_CONTROLS]); |
|
| 5411 | 5734 | } |
| 5412 | 5735 | } |
| 5413 | 5736 | } |
@@ -5430,24 +5753,26 @@ discard block |
||
| 5430 | 5753 | { |
| 5431 | 5754 | parent::insertAt($index,$item); |
| 5432 | 5755 | $this->_o->addedControl($item); |
| 5756 | + } else if(is_string($item) || ($item instanceof IRenderable)) { |
|
| 5757 | + parent::insertAt($index,$item); |
|
| 5758 | + } else { |
|
| 5759 | + throw new TInvalidDataTypeException('controlcollection_control_required'); |
|
| 5433 | 5760 | } |
| 5434 | - else if(is_string($item) || ($item instanceof IRenderable)) |
|
| 5435 | - parent::insertAt($index,$item); |
|
| 5436 | - else |
|
| 5437 | - throw new TInvalidDataTypeException('controlcollection_control_required'); |
|
| 5438 | 5761 | } |
| 5439 | 5762 | public function removeAt($index) |
| 5440 | 5763 | { |
| 5441 | 5764 | $item=parent::removeAt($index); |
| 5442 | - if($item instanceof TControl) |
|
| 5443 | - $this->_o->removedControl($item); |
|
| 5765 | + if($item instanceof TControl) { |
|
| 5766 | + $this->_o->removedControl($item); |
|
| 5767 | + } |
|
| 5444 | 5768 | return $item; |
| 5445 | 5769 | } |
| 5446 | 5770 | public function clear() |
| 5447 | 5771 | { |
| 5448 | 5772 | parent::clear(); |
| 5449 | - if($this->_o instanceof INamingContainer) |
|
| 5450 | - $this->_o->clearNamingContainer(); |
|
| 5773 | + if($this->_o instanceof INamingContainer) { |
|
| 5774 | + $this->_o->clearNamingContainer(); |
|
| 5775 | + } |
|
| 5451 | 5776 | } |
| 5452 | 5777 | } |
| 5453 | 5778 | class TEmptyControlCollection extends TControlCollection |
@@ -5458,7 +5783,10 @@ discard block |
||
| 5458 | 5783 | } |
| 5459 | 5784 | public function insertAt($index,$item) |
| 5460 | 5785 | { |
| 5461 | - if(!is_string($item)) parent::insertAt($index,$item); } |
|
| 5786 | + if(!is_string($item)) { |
|
| 5787 | + parent::insertAt($index,$item); |
|
| 5788 | + } |
|
| 5789 | + } |
|
| 5462 | 5790 | } |
| 5463 | 5791 | interface INamingContainer |
| 5464 | 5792 | { |
@@ -5584,16 +5912,17 @@ discard block |
||
| 5584 | 5912 | { |
| 5585 | 5913 | if(is_array($item)) |
| 5586 | 5914 | { |
| 5587 | - if($item[0]===self::TYPE_EXPRESSION) |
|
| 5588 | - $this->_expressions[$id]=$item[1]; |
|
| 5589 | - else if($item[0]===self::TYPE_STATEMENTS) |
|
| 5590 | - $this->_statements[$id]=$item[1]; |
|
| 5591 | - else if($item[0]===self::TYPE_DATABINDING) |
|
| 5592 | - $this->_bindings[$id]=$item[1]; |
|
| 5915 | + if($item[0]===self::TYPE_EXPRESSION) { |
|
| 5916 | + $this->_expressions[$id]=$item[1]; |
|
| 5917 | + } else if($item[0]===self::TYPE_STATEMENTS) { |
|
| 5918 | + $this->_statements[$id]=$item[1]; |
|
| 5919 | + } else if($item[0]===self::TYPE_DATABINDING) { |
|
| 5920 | + $this->_bindings[$id]=$item[1]; |
|
| 5921 | + } |
|
| 5593 | 5922 | $this->_items[$id]=''; |
| 5923 | + } else { |
|
| 5924 | + $this->_items[$id]=$item; |
|
| 5594 | 5925 | } |
| 5595 | - else |
|
| 5596 | - $this->_items[$id]=$item; |
|
| 5597 | 5926 | } |
| 5598 | 5927 | } |
| 5599 | 5928 | public function getContainer() |
@@ -5607,16 +5936,19 @@ discard block |
||
| 5607 | 5936 | public function evaluateDynamicContent() |
| 5608 | 5937 | { |
| 5609 | 5938 | $context=$this->_container===null?$this:$this->_container; |
| 5610 | - foreach($this->_expressions as $id=>$expression) |
|
| 5611 | - $this->_items[$id]=$context->evaluateExpression($expression); |
|
| 5612 | - foreach($this->_statements as $id=>$statement) |
|
| 5613 | - $this->_items[$id]=$context->evaluateStatements($statement); |
|
| 5939 | + foreach($this->_expressions as $id=>$expression) { |
|
| 5940 | + $this->_items[$id]=$context->evaluateExpression($expression); |
|
| 5941 | + } |
|
| 5942 | + foreach($this->_statements as $id=>$statement) { |
|
| 5943 | + $this->_items[$id]=$context->evaluateStatements($statement); |
|
| 5944 | + } |
|
| 5614 | 5945 | } |
| 5615 | 5946 | public function dataBind() |
| 5616 | 5947 | { |
| 5617 | 5948 | $context=$this->_container===null?$this:$this->_container; |
| 5618 | - foreach($this->_bindings as $id=>$binding) |
|
| 5619 | - $this->_items[$id]=$context->evaluateExpression($binding); |
|
| 5949 | + foreach($this->_bindings as $id=>$binding) { |
|
| 5950 | + $this->_items[$id]=$context->evaluateExpression($binding); |
|
| 5951 | + } |
|
| 5620 | 5952 | } |
| 5621 | 5953 | public function render($writer) |
| 5622 | 5954 | { |
@@ -5643,12 +5975,15 @@ discard block |
||
| 5643 | 5975 | protected function __getZappableSleepProps(&$exprops) |
| 5644 | 5976 | { |
| 5645 | 5977 | parent::__getZappableSleepProps($exprops); |
| 5646 | - if ($this->_flags===0) |
|
| 5647 | - $exprops[] = "\0TFont\0_flags"; |
|
| 5648 | - if ($this->_name==='') |
|
| 5649 | - $exprops[] = "\0TFont\0_name"; |
|
| 5650 | - if ($this->_size==='') |
|
| 5651 | - $exprops[] = "\0TFont\0_size"; |
|
| 5978 | + if ($this->_flags===0) { |
|
| 5979 | + $exprops[] = "\0TFont\0_flags"; |
|
| 5980 | + } |
|
| 5981 | + if ($this->_name==='') { |
|
| 5982 | + $exprops[] = "\0TFont\0_name"; |
|
| 5983 | + } |
|
| 5984 | + if ($this->_size==='') { |
|
| 5985 | + $exprops[] = "\0TFont\0_size"; |
|
| 5986 | + } |
|
| 5652 | 5987 | } |
| 5653 | 5988 | public function getBold() |
| 5654 | 5989 | { |
@@ -5657,10 +5992,11 @@ discard block |
||
| 5657 | 5992 | public function setBold($value) |
| 5658 | 5993 | { |
| 5659 | 5994 | $this->_flags |= self::IS_SET_BOLD; |
| 5660 | - if(TPropertyValue::ensureBoolean($value)) |
|
| 5661 | - $this->_flags |= self::IS_BOLD; |
|
| 5662 | - else |
|
| 5663 | - $this->_flags &= ~self::IS_BOLD; |
|
| 5995 | + if(TPropertyValue::ensureBoolean($value)) { |
|
| 5996 | + $this->_flags |= self::IS_BOLD; |
|
| 5997 | + } else { |
|
| 5998 | + $this->_flags &= ~self::IS_BOLD; |
|
| 5999 | + } |
|
| 5664 | 6000 | } |
| 5665 | 6001 | public function getItalic() |
| 5666 | 6002 | { |
@@ -5669,10 +6005,11 @@ discard block |
||
| 5669 | 6005 | public function setItalic($value) |
| 5670 | 6006 | { |
| 5671 | 6007 | $this->_flags |= self::IS_SET_ITALIC; |
| 5672 | - if(TPropertyValue::ensureBoolean($value)) |
|
| 5673 | - $this->_flags |= self::IS_ITALIC; |
|
| 5674 | - else |
|
| 5675 | - $this->_flags &= ~self::IS_ITALIC; |
|
| 6008 | + if(TPropertyValue::ensureBoolean($value)) { |
|
| 6009 | + $this->_flags |= self::IS_ITALIC; |
|
| 6010 | + } else { |
|
| 6011 | + $this->_flags &= ~self::IS_ITALIC; |
|
| 6012 | + } |
|
| 5676 | 6013 | } |
| 5677 | 6014 | public function getOverline() |
| 5678 | 6015 | { |
@@ -5681,10 +6018,11 @@ discard block |
||
| 5681 | 6018 | public function setOverline($value) |
| 5682 | 6019 | { |
| 5683 | 6020 | $this->_flags |= self::IS_SET_OVERLINE; |
| 5684 | - if(TPropertyValue::ensureBoolean($value)) |
|
| 5685 | - $this->_flags |= self::IS_OVERLINE; |
|
| 5686 | - else |
|
| 5687 | - $this->_flags &= ~self::IS_OVERLINE; |
|
| 6021 | + if(TPropertyValue::ensureBoolean($value)) { |
|
| 6022 | + $this->_flags |= self::IS_OVERLINE; |
|
| 6023 | + } else { |
|
| 6024 | + $this->_flags &= ~self::IS_OVERLINE; |
|
| 6025 | + } |
|
| 5688 | 6026 | } |
| 5689 | 6027 | public function getSize() |
| 5690 | 6028 | { |
@@ -5702,10 +6040,11 @@ discard block |
||
| 5702 | 6040 | public function setStrikeout($value) |
| 5703 | 6041 | { |
| 5704 | 6042 | $this->_flags |= self::IS_SET_STRIKEOUT; |
| 5705 | - if(TPropertyValue::ensureBoolean($value)) |
|
| 5706 | - $this->_flags |= self::IS_STRIKEOUT; |
|
| 5707 | - else |
|
| 5708 | - $this->_flags &= ~self::IS_STRIKEOUT; |
|
| 6043 | + if(TPropertyValue::ensureBoolean($value)) { |
|
| 6044 | + $this->_flags |= self::IS_STRIKEOUT; |
|
| 6045 | + } else { |
|
| 6046 | + $this->_flags &= ~self::IS_STRIKEOUT; |
|
| 6047 | + } |
|
| 5709 | 6048 | } |
| 5710 | 6049 | public function getUnderline() |
| 5711 | 6050 | { |
@@ -5714,10 +6053,11 @@ discard block |
||
| 5714 | 6053 | public function setUnderline($value) |
| 5715 | 6054 | { |
| 5716 | 6055 | $this->_flags |= self::IS_SET_UNDERLINE; |
| 5717 | - if(TPropertyValue::ensureBoolean($value)) |
|
| 5718 | - $this->_flags |= self::IS_UNDERLINE; |
|
| 5719 | - else |
|
| 5720 | - $this->_flags &= ~self::IS_UNDERLINE; |
|
| 6056 | + if(TPropertyValue::ensureBoolean($value)) { |
|
| 6057 | + $this->_flags |= self::IS_UNDERLINE; |
|
| 6058 | + } else { |
|
| 6059 | + $this->_flags &= ~self::IS_UNDERLINE; |
|
| 6060 | + } |
|
| 5721 | 6061 | } |
| 5722 | 6062 | public function getName() |
| 5723 | 6063 | { |
@@ -5740,89 +6080,123 @@ discard block |
||
| 5740 | 6080 | } |
| 5741 | 6081 | public function mergeWith($font) |
| 5742 | 6082 | { |
| 5743 | - if($font===null || $font->_flags===0) |
|
| 5744 | - return; |
|
| 5745 | - if(!($this->_flags & self::IS_SET_BOLD) && ($font->_flags & self::IS_SET_BOLD)) |
|
| 5746 | - $this->setBold($font->getBold()); |
|
| 5747 | - if(!($this->_flags & self::IS_SET_ITALIC) && ($font->_flags & self::IS_SET_ITALIC)) |
|
| 5748 | - $this->setItalic($font->getItalic()); |
|
| 5749 | - if(!($this->_flags & self::IS_SET_OVERLINE) && ($font->_flags & self::IS_SET_OVERLINE)) |
|
| 5750 | - $this->setOverline($font->getOverline()); |
|
| 5751 | - if(!($this->_flags & self::IS_SET_STRIKEOUT) && ($font->_flags & self::IS_SET_STRIKEOUT)) |
|
| 5752 | - $this->setStrikeout($font->getStrikeout()); |
|
| 5753 | - if(!($this->_flags & self::IS_SET_UNDERLINE) && ($font->_flags & self::IS_SET_UNDERLINE)) |
|
| 5754 | - $this->setUnderline($font->getUnderline()); |
|
| 5755 | - if(!($this->_flags & self::IS_SET_SIZE) && ($font->_flags & self::IS_SET_SIZE)) |
|
| 5756 | - $this->setSize($font->getSize()); |
|
| 5757 | - if(!($this->_flags & self::IS_SET_NAME) && ($font->_flags & self::IS_SET_NAME)) |
|
| 5758 | - $this->setName($font->getName()); |
|
| 6083 | + if($font===null || $font->_flags===0) { |
|
| 6084 | + return; |
|
| 6085 | + } |
|
| 6086 | + if(!($this->_flags & self::IS_SET_BOLD) && ($font->_flags & self::IS_SET_BOLD)) { |
|
| 6087 | + $this->setBold($font->getBold()); |
|
| 6088 | + } |
|
| 6089 | + if(!($this->_flags & self::IS_SET_ITALIC) && ($font->_flags & self::IS_SET_ITALIC)) { |
|
| 6090 | + $this->setItalic($font->getItalic()); |
|
| 6091 | + } |
|
| 6092 | + if(!($this->_flags & self::IS_SET_OVERLINE) && ($font->_flags & self::IS_SET_OVERLINE)) { |
|
| 6093 | + $this->setOverline($font->getOverline()); |
|
| 6094 | + } |
|
| 6095 | + if(!($this->_flags & self::IS_SET_STRIKEOUT) && ($font->_flags & self::IS_SET_STRIKEOUT)) { |
|
| 6096 | + $this->setStrikeout($font->getStrikeout()); |
|
| 6097 | + } |
|
| 6098 | + if(!($this->_flags & self::IS_SET_UNDERLINE) && ($font->_flags & self::IS_SET_UNDERLINE)) { |
|
| 6099 | + $this->setUnderline($font->getUnderline()); |
|
| 6100 | + } |
|
| 6101 | + if(!($this->_flags & self::IS_SET_SIZE) && ($font->_flags & self::IS_SET_SIZE)) { |
|
| 6102 | + $this->setSize($font->getSize()); |
|
| 6103 | + } |
|
| 6104 | + if(!($this->_flags & self::IS_SET_NAME) && ($font->_flags & self::IS_SET_NAME)) { |
|
| 6105 | + $this->setName($font->getName()); |
|
| 6106 | + } |
|
| 5759 | 6107 | } |
| 5760 | 6108 | public function copyFrom($font) |
| 5761 | 6109 | { |
| 5762 | - if($font===null || $font->_flags===0) |
|
| 5763 | - return; |
|
| 5764 | - if($font->_flags & self::IS_SET_BOLD) |
|
| 5765 | - $this->setBold($font->getBold()); |
|
| 5766 | - if($font->_flags & self::IS_SET_ITALIC) |
|
| 5767 | - $this->setItalic($font->getItalic()); |
|
| 5768 | - if($font->_flags & self::IS_SET_OVERLINE) |
|
| 5769 | - $this->setOverline($font->getOverline()); |
|
| 5770 | - if($font->_flags & self::IS_SET_STRIKEOUT) |
|
| 5771 | - $this->setStrikeout($font->getStrikeout()); |
|
| 5772 | - if($font->_flags & self::IS_SET_UNDERLINE) |
|
| 5773 | - $this->setUnderline($font->getUnderline()); |
|
| 5774 | - if($font->_flags & self::IS_SET_SIZE) |
|
| 5775 | - $this->setSize($font->getSize()); |
|
| 5776 | - if($font->_flags & self::IS_SET_NAME) |
|
| 5777 | - $this->setName($font->getName()); |
|
| 6110 | + if($font===null || $font->_flags===0) { |
|
| 6111 | + return; |
|
| 6112 | + } |
|
| 6113 | + if($font->_flags & self::IS_SET_BOLD) { |
|
| 6114 | + $this->setBold($font->getBold()); |
|
| 6115 | + } |
|
| 6116 | + if($font->_flags & self::IS_SET_ITALIC) { |
|
| 6117 | + $this->setItalic($font->getItalic()); |
|
| 6118 | + } |
|
| 6119 | + if($font->_flags & self::IS_SET_OVERLINE) { |
|
| 6120 | + $this->setOverline($font->getOverline()); |
|
| 6121 | + } |
|
| 6122 | + if($font->_flags & self::IS_SET_STRIKEOUT) { |
|
| 6123 | + $this->setStrikeout($font->getStrikeout()); |
|
| 6124 | + } |
|
| 6125 | + if($font->_flags & self::IS_SET_UNDERLINE) { |
|
| 6126 | + $this->setUnderline($font->getUnderline()); |
|
| 6127 | + } |
|
| 6128 | + if($font->_flags & self::IS_SET_SIZE) { |
|
| 6129 | + $this->setSize($font->getSize()); |
|
| 6130 | + } |
|
| 6131 | + if($font->_flags & self::IS_SET_NAME) { |
|
| 6132 | + $this->setName($font->getName()); |
|
| 6133 | + } |
|
| 5778 | 6134 | } |
| 5779 | 6135 | public function toString() |
| 5780 | 6136 | { |
| 5781 | - if($this->_flags===0) |
|
| 5782 | - return ''; |
|
| 6137 | + if($this->_flags===0) { |
|
| 6138 | + return ''; |
|
| 6139 | + } |
|
| 5783 | 6140 | $str=''; |
| 5784 | - if($this->_flags & self::IS_SET_BOLD) |
|
| 5785 | - $str.='font-weight:'.(($this->_flags & self::IS_BOLD)?'bold;':'normal;'); |
|
| 5786 | - if($this->_flags & self::IS_SET_ITALIC) |
|
| 5787 | - $str.='font-style:'.(($this->_flags & self::IS_ITALIC)?'italic;':'normal;'); |
|
| 6141 | + if($this->_flags & self::IS_SET_BOLD) { |
|
| 6142 | + $str.='font-weight:'.(($this->_flags & self::IS_BOLD)?'bold;':'normal;'); |
|
| 6143 | + } |
|
| 6144 | + if($this->_flags & self::IS_SET_ITALIC) { |
|
| 6145 | + $str.='font-style:'.(($this->_flags & self::IS_ITALIC)?'italic;':'normal;'); |
|
| 6146 | + } |
|
| 5788 | 6147 | $textDec=''; |
| 5789 | - if($this->_flags & self::IS_UNDERLINE) |
|
| 5790 | - $textDec.='underline'; |
|
| 5791 | - if($this->_flags & self::IS_OVERLINE) |
|
| 5792 | - $textDec.=' overline'; |
|
| 5793 | - if($this->_flags & self::IS_STRIKEOUT) |
|
| 5794 | - $textDec.=' line-through'; |
|
| 6148 | + if($this->_flags & self::IS_UNDERLINE) { |
|
| 6149 | + $textDec.='underline'; |
|
| 6150 | + } |
|
| 6151 | + if($this->_flags & self::IS_OVERLINE) { |
|
| 6152 | + $textDec.=' overline'; |
|
| 6153 | + } |
|
| 6154 | + if($this->_flags & self::IS_STRIKEOUT) { |
|
| 6155 | + $textDec.=' line-through'; |
|
| 6156 | + } |
|
| 5795 | 6157 | $textDec=ltrim($textDec); |
| 5796 | - if($textDec!=='') |
|
| 5797 | - $str.='text-decoration:'.$textDec.';'; |
|
| 5798 | - if($this->_size!=='') |
|
| 5799 | - $str.='font-size:'.$this->_size.';'; |
|
| 5800 | - if($this->_name!=='') |
|
| 5801 | - $str.='font-family:'.$this->_name.';'; |
|
| 6158 | + if($textDec!=='') { |
|
| 6159 | + $str.='text-decoration:'.$textDec.';'; |
|
| 6160 | + } |
|
| 6161 | + if($this->_size!=='') { |
|
| 6162 | + $str.='font-size:'.$this->_size.';'; |
|
| 6163 | + } |
|
| 6164 | + if($this->_name!=='') { |
|
| 6165 | + $str.='font-family:'.$this->_name.';'; |
|
| 6166 | + } |
|
| 5802 | 6167 | return $str; |
| 5803 | 6168 | } |
| 5804 | 6169 | public function addAttributesToRender($writer) |
| 5805 | 6170 | { |
| 5806 | - if($this->_flags===0) |
|
| 5807 | - return; |
|
| 5808 | - if($this->_flags & self::IS_SET_BOLD) |
|
| 5809 | - $writer->addStyleAttribute('font-weight',(($this->_flags & self::IS_BOLD)?'bold':'normal')); |
|
| 5810 | - if($this->_flags & self::IS_SET_ITALIC) |
|
| 5811 | - $writer->addStyleAttribute('font-style',(($this->_flags & self::IS_ITALIC)?'italic':'normal')); |
|
| 6171 | + if($this->_flags===0) { |
|
| 6172 | + return; |
|
| 6173 | + } |
|
| 6174 | + if($this->_flags & self::IS_SET_BOLD) { |
|
| 6175 | + $writer->addStyleAttribute('font-weight',(($this->_flags & self::IS_BOLD)?'bold':'normal')); |
|
| 6176 | + } |
|
| 6177 | + if($this->_flags & self::IS_SET_ITALIC) { |
|
| 6178 | + $writer->addStyleAttribute('font-style',(($this->_flags & self::IS_ITALIC)?'italic':'normal')); |
|
| 6179 | + } |
|
| 5812 | 6180 | $textDec=''; |
| 5813 | - if($this->_flags & self::IS_UNDERLINE) |
|
| 5814 | - $textDec.='underline'; |
|
| 5815 | - if($this->_flags & self::IS_OVERLINE) |
|
| 5816 | - $textDec.=' overline'; |
|
| 5817 | - if($this->_flags & self::IS_STRIKEOUT) |
|
| 5818 | - $textDec.=' line-through'; |
|
| 6181 | + if($this->_flags & self::IS_UNDERLINE) { |
|
| 6182 | + $textDec.='underline'; |
|
| 6183 | + } |
|
| 6184 | + if($this->_flags & self::IS_OVERLINE) { |
|
| 6185 | + $textDec.=' overline'; |
|
| 6186 | + } |
|
| 6187 | + if($this->_flags & self::IS_STRIKEOUT) { |
|
| 6188 | + $textDec.=' line-through'; |
|
| 6189 | + } |
|
| 5819 | 6190 | $textDec=ltrim($textDec); |
| 5820 | - if($textDec!=='') |
|
| 5821 | - $writer->addStyleAttribute('text-decoration',$textDec); |
|
| 5822 | - if($this->_size!=='') |
|
| 5823 | - $writer->addStyleAttribute('font-size',$this->_size); |
|
| 5824 | - if($this->_name!=='') |
|
| 5825 | - $writer->addStyleAttribute('font-family',$this->_name); |
|
| 6191 | + if($textDec!=='') { |
|
| 6192 | + $writer->addStyleAttribute('text-decoration',$textDec); |
|
| 6193 | + } |
|
| 6194 | + if($this->_size!=='') { |
|
| 6195 | + $writer->addStyleAttribute('font-size',$this->_size); |
|
| 6196 | + } |
|
| 6197 | + if($this->_name!=='') { |
|
| 6198 | + $writer->addStyleAttribute('font-family',$this->_name); |
|
| 6199 | + } |
|
| 5826 | 6200 | } |
| 5827 | 6201 | } |
| 5828 | 6202 | class TStyle extends TComponent |
@@ -5835,26 +6209,33 @@ discard block |
||
| 5835 | 6209 | protected function __getZappableSleepProps(&$exprops) |
| 5836 | 6210 | { |
| 5837 | 6211 | parent::__getZappableSleepProps($exprops); |
| 5838 | - if ($this->_fields===array()) |
|
| 5839 | - $exprops[] = "\0TStyle\0_fields"; |
|
| 5840 | - if($this->_font===null) |
|
| 5841 | - $exprops[] = "\0TStyle\0_font"; |
|
| 5842 | - if($this->_class===null) |
|
| 5843 | - $exprops[] = "\0TStyle\0_class"; |
|
| 5844 | - if ($this->_customStyle===null) |
|
| 5845 | - $exprops[] = "\0TStyle\0_customStyle"; |
|
| 5846 | - if ($this->_displayStyle==='Fixed') |
|
| 5847 | - $exprops[] = "\0TStyle\0_displayStyle"; |
|
| 6212 | + if ($this->_fields===array()) { |
|
| 6213 | + $exprops[] = "\0TStyle\0_fields"; |
|
| 6214 | + } |
|
| 6215 | + if($this->_font===null) { |
|
| 6216 | + $exprops[] = "\0TStyle\0_font"; |
|
| 6217 | + } |
|
| 6218 | + if($this->_class===null) { |
|
| 6219 | + $exprops[] = "\0TStyle\0_class"; |
|
| 6220 | + } |
|
| 6221 | + if ($this->_customStyle===null) { |
|
| 6222 | + $exprops[] = "\0TStyle\0_customStyle"; |
|
| 6223 | + } |
|
| 6224 | + if ($this->_displayStyle==='Fixed') { |
|
| 6225 | + $exprops[] = "\0TStyle\0_displayStyle"; |
|
| 6226 | + } |
|
| 5848 | 6227 | } |
| 5849 | 6228 | public function __construct($style=null) |
| 5850 | 6229 | { |
| 5851 | - if($style!==null) |
|
| 5852 | - $this->copyFrom($style); |
|
| 6230 | + if($style!==null) { |
|
| 6231 | + $this->copyFrom($style); |
|
| 6232 | + } |
|
| 5853 | 6233 | } |
| 5854 | 6234 | public function __clone() |
| 5855 | 6235 | { |
| 5856 | - if($this->_font!==null) |
|
| 5857 | - $this->_font = clone($this->_font); |
|
| 6236 | + if($this->_font!==null) { |
|
| 6237 | + $this->_font = clone($this->_font); |
|
| 6238 | + } |
|
| 5858 | 6239 | } |
| 5859 | 6240 | public function getBackColor() |
| 5860 | 6241 | { |
@@ -5862,10 +6243,11 @@ discard block |
||
| 5862 | 6243 | } |
| 5863 | 6244 | public function setBackColor($value) |
| 5864 | 6245 | { |
| 5865 | - if(trim($value)==='') |
|
| 5866 | - unset($this->_fields['background-color']); |
|
| 5867 | - else |
|
| 5868 | - $this->_fields['background-color']=$value; |
|
| 6246 | + if(trim($value)==='') { |
|
| 6247 | + unset($this->_fields['background-color']); |
|
| 6248 | + } else { |
|
| 6249 | + $this->_fields['background-color']=$value; |
|
| 6250 | + } |
|
| 5869 | 6251 | } |
| 5870 | 6252 | public function getBorderColor() |
| 5871 | 6253 | { |
@@ -5873,10 +6255,11 @@ discard block |
||
| 5873 | 6255 | } |
| 5874 | 6256 | public function setBorderColor($value) |
| 5875 | 6257 | { |
| 5876 | - if(trim($value)==='') |
|
| 5877 | - unset($this->_fields['border-color']); |
|
| 5878 | - else |
|
| 5879 | - $this->_fields['border-color']=$value; |
|
| 6258 | + if(trim($value)==='') { |
|
| 6259 | + unset($this->_fields['border-color']); |
|
| 6260 | + } else { |
|
| 6261 | + $this->_fields['border-color']=$value; |
|
| 6262 | + } |
|
| 5880 | 6263 | } |
| 5881 | 6264 | public function getBorderStyle() |
| 5882 | 6265 | { |
@@ -5884,10 +6267,11 @@ discard block |
||
| 5884 | 6267 | } |
| 5885 | 6268 | public function setBorderStyle($value) |
| 5886 | 6269 | { |
| 5887 | - if(trim($value)==='') |
|
| 5888 | - unset($this->_fields['border-style']); |
|
| 5889 | - else |
|
| 5890 | - $this->_fields['border-style']=$value; |
|
| 6270 | + if(trim($value)==='') { |
|
| 6271 | + unset($this->_fields['border-style']); |
|
| 6272 | + } else { |
|
| 6273 | + $this->_fields['border-style']=$value; |
|
| 6274 | + } |
|
| 5891 | 6275 | } |
| 5892 | 6276 | public function getBorderWidth() |
| 5893 | 6277 | { |
@@ -5895,10 +6279,11 @@ discard block |
||
| 5895 | 6279 | } |
| 5896 | 6280 | public function setBorderWidth($value) |
| 5897 | 6281 | { |
| 5898 | - if(trim($value)==='') |
|
| 5899 | - unset($this->_fields['border-width']); |
|
| 5900 | - else |
|
| 5901 | - $this->_fields['border-width']=$value; |
|
| 6282 | + if(trim($value)==='') { |
|
| 6283 | + unset($this->_fields['border-width']); |
|
| 6284 | + } else { |
|
| 6285 | + $this->_fields['border-width']=$value; |
|
| 6286 | + } |
|
| 5902 | 6287 | } |
| 5903 | 6288 | public function getCssClass() |
| 5904 | 6289 | { |
@@ -5914,8 +6299,9 @@ discard block |
||
| 5914 | 6299 | } |
| 5915 | 6300 | public function getFont() |
| 5916 | 6301 | { |
| 5917 | - if($this->_font===null) |
|
| 5918 | - $this->_font=new TFont; |
|
| 6302 | + if($this->_font===null) { |
|
| 6303 | + $this->_font=new TFont; |
|
| 6304 | + } |
|
| 5919 | 6305 | return $this->_font; |
| 5920 | 6306 | } |
| 5921 | 6307 | public function hasFont() |
@@ -5950,10 +6336,11 @@ discard block |
||
| 5950 | 6336 | } |
| 5951 | 6337 | public function setForeColor($value) |
| 5952 | 6338 | { |
| 5953 | - if(trim($value)==='') |
|
| 5954 | - unset($this->_fields['color']); |
|
| 5955 | - else |
|
| 5956 | - $this->_fields['color']=$value; |
|
| 6339 | + if(trim($value)==='') { |
|
| 6340 | + unset($this->_fields['color']); |
|
| 6341 | + } else { |
|
| 6342 | + $this->_fields['color']=$value; |
|
| 6343 | + } |
|
| 5957 | 6344 | } |
| 5958 | 6345 | public function getHeight() |
| 5959 | 6346 | { |
@@ -5961,10 +6348,11 @@ discard block |
||
| 5961 | 6348 | } |
| 5962 | 6349 | public function setHeight($value) |
| 5963 | 6350 | { |
| 5964 | - if(trim($value)==='') |
|
| 5965 | - unset($this->_fields['height']); |
|
| 5966 | - else |
|
| 5967 | - $this->_fields['height']=$value; |
|
| 6351 | + if(trim($value)==='') { |
|
| 6352 | + unset($this->_fields['height']); |
|
| 6353 | + } else { |
|
| 6354 | + $this->_fields['height']=$value; |
|
| 6355 | + } |
|
| 5968 | 6356 | } |
| 5969 | 6357 | public function getCustomStyle() |
| 5970 | 6358 | { |
@@ -6010,12 +6398,15 @@ discard block |
||
| 6010 | 6398 | if($style instanceof TStyle) |
| 6011 | 6399 | { |
| 6012 | 6400 | $this->_fields=array_merge($this->_fields,$style->_fields); |
| 6013 | - if($style->_class!==null) |
|
| 6014 | - $this->_class=$style->_class; |
|
| 6015 | - if($style->_customStyle!==null) |
|
| 6016 | - $this->_customStyle=$style->_customStyle; |
|
| 6017 | - if($style->_font!==null) |
|
| 6018 | - $this->getFont()->copyFrom($style->_font); |
|
| 6401 | + if($style->_class!==null) { |
|
| 6402 | + $this->_class=$style->_class; |
|
| 6403 | + } |
|
| 6404 | + if($style->_customStyle!==null) { |
|
| 6405 | + $this->_customStyle=$style->_customStyle; |
|
| 6406 | + } |
|
| 6407 | + if($style->_font!==null) { |
|
| 6408 | + $this->getFont()->copyFrom($style->_font); |
|
| 6409 | + } |
|
| 6019 | 6410 | } |
| 6020 | 6411 | } |
| 6021 | 6412 | public function mergeWith($style) |
@@ -6023,12 +6414,15 @@ discard block |
||
| 6023 | 6414 | if($style instanceof TStyle) |
| 6024 | 6415 | { |
| 6025 | 6416 | $this->_fields=array_merge($style->_fields,$this->_fields); |
| 6026 | - if($this->_class===null) |
|
| 6027 | - $this->_class=$style->_class; |
|
| 6028 | - if($this->_customStyle===null) |
|
| 6029 | - $this->_customStyle=$style->_customStyle; |
|
| 6030 | - if($style->_font!==null) |
|
| 6031 | - $this->getFont()->mergeWith($style->_font); |
|
| 6417 | + if($this->_class===null) { |
|
| 6418 | + $this->_class=$style->_class; |
|
| 6419 | + } |
|
| 6420 | + if($this->_customStyle===null) { |
|
| 6421 | + $this->_customStyle=$style->_customStyle; |
|
| 6422 | + } |
|
| 6423 | + if($style->_font!==null) { |
|
| 6424 | + $this->getFont()->mergeWith($style->_font); |
|
| 6425 | + } |
|
| 6032 | 6426 | } |
| 6033 | 6427 | } |
| 6034 | 6428 | public function addAttributesToRender($writer) |
@@ -6038,15 +6432,18 @@ discard block |
||
| 6038 | 6432 | foreach(explode(';',$this->_customStyle) as $style) |
| 6039 | 6433 | { |
| 6040 | 6434 | $arr=explode(':',$style,2); |
| 6041 | - if(isset($arr[1]) && trim($arr[0])!=='') |
|
| 6042 | - $writer->addStyleAttribute(trim($arr[0]),trim($arr[1])); |
|
| 6435 | + if(isset($arr[1]) && trim($arr[0])!=='') { |
|
| 6436 | + $writer->addStyleAttribute(trim($arr[0]),trim($arr[1])); |
|
| 6437 | + } |
|
| 6043 | 6438 | } |
| 6044 | 6439 | } |
| 6045 | 6440 | $writer->addStyleAttributes($this->_fields); |
| 6046 | - if($this->_font!==null) |
|
| 6047 | - $this->_font->addAttributesToRender($writer); |
|
| 6048 | - if($this->_class!==null) |
|
| 6049 | - $writer->addAttribute('class',$this->_class); |
|
| 6441 | + if($this->_font!==null) { |
|
| 6442 | + $this->_font->addAttributesToRender($writer); |
|
| 6443 | + } |
|
| 6444 | + if($this->_class!==null) { |
|
| 6445 | + $writer->addAttribute('class',$this->_class); |
|
| 6446 | + } |
|
| 6050 | 6447 | } |
| 6051 | 6448 | public function getStyleFields() |
| 6052 | 6449 | { |
@@ -6071,18 +6468,24 @@ discard block |
||
| 6071 | 6468 | protected function __getZappableSleepProps(&$exprops) |
| 6072 | 6469 | { |
| 6073 | 6470 | parent::__getZappableSleepProps($exprops); |
| 6074 | - if ($this->_backImageUrl===null) |
|
| 6075 | - $exprops[] = "\0TTableStyle\0_backImageUrl"; |
|
| 6076 | - if ($this->_horizontalAlign===null) |
|
| 6077 | - $exprops[] = "\0TTableStyle\0_horizontalAlign"; |
|
| 6078 | - if ($this->_cellPadding===null) |
|
| 6079 | - $exprops[] = "\0TTableStyle\0_cellPadding"; |
|
| 6080 | - if ($this->_cellSpacing===null) |
|
| 6081 | - $exprops[] = "\0TTableStyle\0_cellSpacing"; |
|
| 6082 | - if ($this->_gridLines===null) |
|
| 6083 | - $exprops[] = "\0TTableStyle\0_gridLines"; |
|
| 6084 | - if ($this->_borderCollapse===null) |
|
| 6085 | - $exprops[] = "\0TTableStyle\0_borderCollapse"; |
|
| 6471 | + if ($this->_backImageUrl===null) { |
|
| 6472 | + $exprops[] = "\0TTableStyle\0_backImageUrl"; |
|
| 6473 | + } |
|
| 6474 | + if ($this->_horizontalAlign===null) { |
|
| 6475 | + $exprops[] = "\0TTableStyle\0_horizontalAlign"; |
|
| 6476 | + } |
|
| 6477 | + if ($this->_cellPadding===null) { |
|
| 6478 | + $exprops[] = "\0TTableStyle\0_cellPadding"; |
|
| 6479 | + } |
|
| 6480 | + if ($this->_cellSpacing===null) { |
|
| 6481 | + $exprops[] = "\0TTableStyle\0_cellSpacing"; |
|
| 6482 | + } |
|
| 6483 | + if ($this->_gridLines===null) { |
|
| 6484 | + $exprops[] = "\0TTableStyle\0_gridLines"; |
|
| 6485 | + } |
|
| 6486 | + if ($this->_borderCollapse===null) { |
|
| 6487 | + $exprops[] = "\0TTableStyle\0_borderCollapse"; |
|
| 6488 | + } |
|
| 6086 | 6489 | } |
| 6087 | 6490 | public function reset() |
| 6088 | 6491 | { |
@@ -6098,18 +6501,24 @@ discard block |
||
| 6098 | 6501 | parent::copyFrom($style); |
| 6099 | 6502 | if($style instanceof TTableStyle) |
| 6100 | 6503 | { |
| 6101 | - if($style->_backImageUrl!==null) |
|
| 6102 | - $this->_backImageUrl=$style->_backImageUrl; |
|
| 6103 | - if($style->_horizontalAlign!==null) |
|
| 6104 | - $this->_horizontalAlign=$style->_horizontalAlign; |
|
| 6105 | - if($style->_cellPadding!==null) |
|
| 6106 | - $this->_cellPadding=$style->_cellPadding; |
|
| 6107 | - if($style->_cellSpacing!==null) |
|
| 6108 | - $this->_cellSpacing=$style->_cellSpacing; |
|
| 6109 | - if($style->_gridLines!==null) |
|
| 6110 | - $this->_gridLines=$style->_gridLines; |
|
| 6111 | - if($style->_borderCollapse!==null) |
|
| 6112 | - $this->_borderCollapse=$style->_borderCollapse; |
|
| 6504 | + if($style->_backImageUrl!==null) { |
|
| 6505 | + $this->_backImageUrl=$style->_backImageUrl; |
|
| 6506 | + } |
|
| 6507 | + if($style->_horizontalAlign!==null) { |
|
| 6508 | + $this->_horizontalAlign=$style->_horizontalAlign; |
|
| 6509 | + } |
|
| 6510 | + if($style->_cellPadding!==null) { |
|
| 6511 | + $this->_cellPadding=$style->_cellPadding; |
|
| 6512 | + } |
|
| 6513 | + if($style->_cellSpacing!==null) { |
|
| 6514 | + $this->_cellSpacing=$style->_cellSpacing; |
|
| 6515 | + } |
|
| 6516 | + if($style->_gridLines!==null) { |
|
| 6517 | + $this->_gridLines=$style->_gridLines; |
|
| 6518 | + } |
|
| 6519 | + if($style->_borderCollapse!==null) { |
|
| 6520 | + $this->_borderCollapse=$style->_borderCollapse; |
|
| 6521 | + } |
|
| 6113 | 6522 | } |
| 6114 | 6523 | } |
| 6115 | 6524 | public function mergeWith($style) |
@@ -6117,32 +6526,43 @@ discard block |
||
| 6117 | 6526 | parent::mergeWith($style); |
| 6118 | 6527 | if($style instanceof TTableStyle) |
| 6119 | 6528 | { |
| 6120 | - if($this->_backImageUrl===null && $style->_backImageUrl!==null) |
|
| 6121 | - $this->_backImageUrl=$style->_backImageUrl; |
|
| 6122 | - if($this->_horizontalAlign===null && $style->_horizontalAlign!==null) |
|
| 6123 | - $this->_horizontalAlign=$style->_horizontalAlign; |
|
| 6124 | - if($this->_cellPadding===null && $style->_cellPadding!==null) |
|
| 6125 | - $this->_cellPadding=$style->_cellPadding; |
|
| 6126 | - if($this->_cellSpacing===null && $style->_cellSpacing!==null) |
|
| 6127 | - $this->_cellSpacing=$style->_cellSpacing; |
|
| 6128 | - if($this->_gridLines===null && $style->_gridLines!==null) |
|
| 6129 | - $this->_gridLines=$style->_gridLines; |
|
| 6130 | - if($this->_borderCollapse===null && $style->_borderCollapse!==null) |
|
| 6131 | - $this->_borderCollapse=$style->_borderCollapse; |
|
| 6529 | + if($this->_backImageUrl===null && $style->_backImageUrl!==null) { |
|
| 6530 | + $this->_backImageUrl=$style->_backImageUrl; |
|
| 6531 | + } |
|
| 6532 | + if($this->_horizontalAlign===null && $style->_horizontalAlign!==null) { |
|
| 6533 | + $this->_horizontalAlign=$style->_horizontalAlign; |
|
| 6534 | + } |
|
| 6535 | + if($this->_cellPadding===null && $style->_cellPadding!==null) { |
|
| 6536 | + $this->_cellPadding=$style->_cellPadding; |
|
| 6537 | + } |
|
| 6538 | + if($this->_cellSpacing===null && $style->_cellSpacing!==null) { |
|
| 6539 | + $this->_cellSpacing=$style->_cellSpacing; |
|
| 6540 | + } |
|
| 6541 | + if($this->_gridLines===null && $style->_gridLines!==null) { |
|
| 6542 | + $this->_gridLines=$style->_gridLines; |
|
| 6543 | + } |
|
| 6544 | + if($this->_borderCollapse===null && $style->_borderCollapse!==null) { |
|
| 6545 | + $this->_borderCollapse=$style->_borderCollapse; |
|
| 6546 | + } |
|
| 6132 | 6547 | } |
| 6133 | 6548 | } |
| 6134 | 6549 | public function addAttributesToRender($writer) |
| 6135 | 6550 | { |
| 6136 | - if(($url=trim($this->getBackImageUrl()))!=='') |
|
| 6137 | - $writer->addStyleAttribute('background-image','url('.$url.')'); |
|
| 6138 | - if(($horizontalAlign=$this->getHorizontalAlign())!==THorizontalAlign::NotSet) |
|
| 6139 | - $writer->addStyleAttribute('text-align',strtolower($horizontalAlign)); |
|
| 6140 | - if(($cellPadding=$this->getCellPadding())>=0) |
|
| 6141 | - $writer->addAttribute('cellpadding',"$cellPadding"); |
|
| 6142 | - if(($cellSpacing=$this->getCellSpacing())>=0) |
|
| 6143 | - $writer->addAttribute('cellspacing',"$cellSpacing"); |
|
| 6144 | - if($this->getBorderCollapse()) |
|
| 6145 | - $writer->addStyleAttribute('border-collapse','collapse'); |
|
| 6551 | + if(($url=trim($this->getBackImageUrl()))!=='') { |
|
| 6552 | + $writer->addStyleAttribute('background-image','url('.$url.')'); |
|
| 6553 | + } |
|
| 6554 | + if(($horizontalAlign=$this->getHorizontalAlign())!==THorizontalAlign::NotSet) { |
|
| 6555 | + $writer->addStyleAttribute('text-align',strtolower($horizontalAlign)); |
|
| 6556 | + } |
|
| 6557 | + if(($cellPadding=$this->getCellPadding())>=0) { |
|
| 6558 | + $writer->addAttribute('cellpadding',"$cellPadding"); |
|
| 6559 | + } |
|
| 6560 | + if(($cellSpacing=$this->getCellSpacing())>=0) { |
|
| 6561 | + $writer->addAttribute('cellspacing',"$cellSpacing"); |
|
| 6562 | + } |
|
| 6563 | + if($this->getBorderCollapse()) { |
|
| 6564 | + $writer->addStyleAttribute('border-collapse','collapse'); |
|
| 6565 | + } |
|
| 6146 | 6566 | switch($this->getGridLines()) |
| 6147 | 6567 | { |
| 6148 | 6568 | case TTableGridLines::Horizontal : $writer->addAttribute('rules','rows'); break; |
@@ -6173,8 +6593,9 @@ discard block |
||
| 6173 | 6593 | } |
| 6174 | 6594 | public function setCellPadding($value) |
| 6175 | 6595 | { |
| 6176 | - if(($this->_cellPadding=TPropertyValue::ensureInteger($value))<-1) |
|
| 6177 | - throw new TInvalidDataValueException('tablestyle_cellpadding_invalid'); |
|
| 6596 | + if(($this->_cellPadding=TPropertyValue::ensureInteger($value))<-1) { |
|
| 6597 | + throw new TInvalidDataValueException('tablestyle_cellpadding_invalid'); |
|
| 6598 | + } |
|
| 6178 | 6599 | } |
| 6179 | 6600 | public function getCellSpacing() |
| 6180 | 6601 | { |
@@ -6182,8 +6603,9 @@ discard block |
||
| 6182 | 6603 | } |
| 6183 | 6604 | public function setCellSpacing($value) |
| 6184 | 6605 | { |
| 6185 | - if(($this->_cellSpacing=TPropertyValue::ensureInteger($value))<-1) |
|
| 6186 | - throw new TInvalidDataValueException('tablestyle_cellspacing_invalid'); |
|
| 6606 | + if(($this->_cellSpacing=TPropertyValue::ensureInteger($value))<-1) { |
|
| 6607 | + throw new TInvalidDataValueException('tablestyle_cellspacing_invalid'); |
|
| 6608 | + } |
|
| 6187 | 6609 | } |
| 6188 | 6610 | public function getGridLines() |
| 6189 | 6611 | { |
@@ -6210,12 +6632,15 @@ discard block |
||
| 6210 | 6632 | protected function __getZappableSleepProps(&$exprops) |
| 6211 | 6633 | { |
| 6212 | 6634 | parent::__getZappableSleepProps($exprops); |
| 6213 | - if ($this->_horizontalAlign===null) |
|
| 6214 | - $exprops[] = "\0TTableItemStyle\0_horizontalAlign"; |
|
| 6215 | - if ($this->_verticalAlign===null) |
|
| 6216 | - $exprops[] = "\0TTableItemStyle\0_verticalAlign"; |
|
| 6217 | - if ($this->_wrap===null) |
|
| 6218 | - $exprops[] = "\0TTableItemStyle\0_wrap"; |
|
| 6635 | + if ($this->_horizontalAlign===null) { |
|
| 6636 | + $exprops[] = "\0TTableItemStyle\0_horizontalAlign"; |
|
| 6637 | + } |
|
| 6638 | + if ($this->_verticalAlign===null) { |
|
| 6639 | + $exprops[] = "\0TTableItemStyle\0_verticalAlign"; |
|
| 6640 | + } |
|
| 6641 | + if ($this->_wrap===null) { |
|
| 6642 | + $exprops[] = "\0TTableItemStyle\0_wrap"; |
|
| 6643 | + } |
|
| 6219 | 6644 | } |
| 6220 | 6645 | public function reset() |
| 6221 | 6646 | { |
@@ -6229,12 +6654,15 @@ discard block |
||
| 6229 | 6654 | parent::copyFrom($style); |
| 6230 | 6655 | if($style instanceof TTableItemStyle) |
| 6231 | 6656 | { |
| 6232 | - if($this->_verticalAlign===null && $style->_verticalAlign!==null) |
|
| 6233 | - $this->_verticalAlign=$style->_verticalAlign; |
|
| 6234 | - if($this->_horizontalAlign===null && $style->_horizontalAlign!==null) |
|
| 6235 | - $this->_horizontalAlign=$style->_horizontalAlign; |
|
| 6236 | - if($this->_wrap===null && $style->_wrap!==null) |
|
| 6237 | - $this->_wrap=$style->_wrap; |
|
| 6657 | + if($this->_verticalAlign===null && $style->_verticalAlign!==null) { |
|
| 6658 | + $this->_verticalAlign=$style->_verticalAlign; |
|
| 6659 | + } |
|
| 6660 | + if($this->_horizontalAlign===null && $style->_horizontalAlign!==null) { |
|
| 6661 | + $this->_horizontalAlign=$style->_horizontalAlign; |
|
| 6662 | + } |
|
| 6663 | + if($this->_wrap===null && $style->_wrap!==null) { |
|
| 6664 | + $this->_wrap=$style->_wrap; |
|
| 6665 | + } |
|
| 6238 | 6666 | } |
| 6239 | 6667 | } |
| 6240 | 6668 | public function mergeWith($style) |
@@ -6242,22 +6670,28 @@ discard block |
||
| 6242 | 6670 | parent::mergeWith($style); |
| 6243 | 6671 | if($style instanceof TTableItemStyle) |
| 6244 | 6672 | { |
| 6245 | - if($style->_verticalAlign!==null) |
|
| 6246 | - $this->_verticalAlign=$style->_verticalAlign; |
|
| 6247 | - if($style->_horizontalAlign!==null) |
|
| 6248 | - $this->_horizontalAlign=$style->_horizontalAlign; |
|
| 6249 | - if($style->_wrap!==null) |
|
| 6250 | - $this->_wrap=$style->_wrap; |
|
| 6673 | + if($style->_verticalAlign!==null) { |
|
| 6674 | + $this->_verticalAlign=$style->_verticalAlign; |
|
| 6675 | + } |
|
| 6676 | + if($style->_horizontalAlign!==null) { |
|
| 6677 | + $this->_horizontalAlign=$style->_horizontalAlign; |
|
| 6678 | + } |
|
| 6679 | + if($style->_wrap!==null) { |
|
| 6680 | + $this->_wrap=$style->_wrap; |
|
| 6681 | + } |
|
| 6251 | 6682 | } |
| 6252 | 6683 | } |
| 6253 | 6684 | public function addAttributesToRender($writer) |
| 6254 | 6685 | { |
| 6255 | - if(!$this->getWrap()) |
|
| 6256 | - $writer->addStyleAttribute('white-space','nowrap'); |
|
| 6257 | - if(($horizontalAlign=$this->getHorizontalAlign())!==THorizontalAlign::NotSet) |
|
| 6258 | - $writer->addAttribute('align',strtolower($horizontalAlign)); |
|
| 6259 | - if(($verticalAlign=$this->getVerticalAlign())!==TVerticalAlign::NotSet) |
|
| 6260 | - $writer->addAttribute('valign',strtolower($verticalAlign)); |
|
| 6686 | + if(!$this->getWrap()) { |
|
| 6687 | + $writer->addStyleAttribute('white-space','nowrap'); |
|
| 6688 | + } |
|
| 6689 | + if(($horizontalAlign=$this->getHorizontalAlign())!==THorizontalAlign::NotSet) { |
|
| 6690 | + $writer->addAttribute('align',strtolower($horizontalAlign)); |
|
| 6691 | + } |
|
| 6692 | + if(($verticalAlign=$this->getVerticalAlign())!==TVerticalAlign::NotSet) { |
|
| 6693 | + $writer->addAttribute('valign',strtolower($verticalAlign)); |
|
| 6694 | + } |
|
| 6261 | 6695 | parent::addAttributesToRender($writer); |
| 6262 | 6696 | } |
| 6263 | 6697 | public function getHorizontalAlign() |
@@ -6358,75 +6792,86 @@ discard block |
||
| 6358 | 6792 | return $this->_pretagtext; |
| 6359 | 6793 | } |
| 6360 | 6794 | public function setPreTagText($value) { |
| 6361 | - if(!$this->_internalonly && !$this->_control->getIsSkinApplied()) |
|
| 6362 | - $this->_pretagtext = TPropertyValue::ensureString($value); |
|
| 6795 | + if(!$this->_internalonly && !$this->_control->getIsSkinApplied()) { |
|
| 6796 | + $this->_pretagtext = TPropertyValue::ensureString($value); |
|
| 6797 | + } |
|
| 6363 | 6798 | } |
| 6364 | 6799 | public function getPreContentsText() { |
| 6365 | 6800 | return $this->_precontentstext; |
| 6366 | 6801 | } |
| 6367 | 6802 | public function setPreContentsText($value) { |
| 6368 | - if(!$this->_control->getIsSkinApplied()) |
|
| 6369 | - $this->_precontentstext = TPropertyValue::ensureString($value); |
|
| 6803 | + if(!$this->_control->getIsSkinApplied()) { |
|
| 6804 | + $this->_precontentstext = TPropertyValue::ensureString($value); |
|
| 6805 | + } |
|
| 6370 | 6806 | } |
| 6371 | 6807 | public function getPostContentsText() { |
| 6372 | 6808 | return $this->_postcontentstext; |
| 6373 | 6809 | } |
| 6374 | 6810 | public function setPostContentsText($value) { |
| 6375 | - if(!$this->_control->getIsSkinApplied()) |
|
| 6376 | - $this->_postcontentstext = TPropertyValue::ensureString($value); |
|
| 6811 | + if(!$this->_control->getIsSkinApplied()) { |
|
| 6812 | + $this->_postcontentstext = TPropertyValue::ensureString($value); |
|
| 6813 | + } |
|
| 6377 | 6814 | } |
| 6378 | 6815 | public function getPostTagText() { |
| 6379 | 6816 | return $this->_posttagtext; |
| 6380 | 6817 | } |
| 6381 | 6818 | public function setPostTagText($value) { |
| 6382 | - if(!$this->_internalonly && !$this->_control->getIsSkinApplied()) |
|
| 6383 | - $this->_posttagtext = TPropertyValue::ensureString($value); |
|
| 6819 | + if(!$this->_internalonly && !$this->_control->getIsSkinApplied()) { |
|
| 6820 | + $this->_posttagtext = TPropertyValue::ensureString($value); |
|
| 6821 | + } |
|
| 6384 | 6822 | } |
| 6385 | 6823 | public function getPreTagTemplate() { |
| 6386 | 6824 | return $this->_pretagtemplate; |
| 6387 | 6825 | } |
| 6388 | 6826 | public function setPreTagTemplate($value) { |
| 6389 | - if(!$this->_internalonly && !$this->_control->getIsSkinApplied()) |
|
| 6390 | - $this->_pretagtemplate = $value; |
|
| 6827 | + if(!$this->_internalonly && !$this->_control->getIsSkinApplied()) { |
|
| 6828 | + $this->_pretagtemplate = $value; |
|
| 6829 | + } |
|
| 6391 | 6830 | } |
| 6392 | 6831 | public function getPreContentsTemplate() { |
| 6393 | 6832 | return $this->_precontentstemplate; |
| 6394 | 6833 | } |
| 6395 | 6834 | public function setPreContentsTemplate($value) { |
| 6396 | - if(!$this->_control->getIsSkinApplied()) |
|
| 6397 | - $this->_precontentstemplate = $value; |
|
| 6835 | + if(!$this->_control->getIsSkinApplied()) { |
|
| 6836 | + $this->_precontentstemplate = $value; |
|
| 6837 | + } |
|
| 6398 | 6838 | } |
| 6399 | 6839 | public function getPostContentsTemplate() { |
| 6400 | 6840 | return $this->_postcontentstemplate; |
| 6401 | 6841 | } |
| 6402 | 6842 | public function setPostContentsTemplate($value) { |
| 6403 | - if(!$this->_control->getIsSkinApplied()) |
|
| 6404 | - $this->_postcontentstemplate = $value; |
|
| 6843 | + if(!$this->_control->getIsSkinApplied()) { |
|
| 6844 | + $this->_postcontentstemplate = $value; |
|
| 6845 | + } |
|
| 6405 | 6846 | } |
| 6406 | 6847 | public function getPostTagTemplate() { |
| 6407 | 6848 | return $this->_posttagtemplate; |
| 6408 | 6849 | } |
| 6409 | 6850 | public function setPostTagTemplate($value) { |
| 6410 | - if(!$this->_internalonly && !$this->_control->getIsSkinApplied()) |
|
| 6411 | - $this->_posttagtemplate = $value; |
|
| 6851 | + if(!$this->_internalonly && !$this->_control->getIsSkinApplied()) { |
|
| 6852 | + $this->_posttagtemplate = $value; |
|
| 6853 | + } |
|
| 6412 | 6854 | } |
| 6413 | 6855 | public function instantiate($outercontrol = null) { |
| 6414 | 6856 | if($this->getPreTagTemplate() || $this->getPreContentsTemplate() || |
| 6415 | 6857 | $this->getPostContentsTemplate() || $this->getPostTagTemplate()) { |
| 6416 | 6858 | $this->_outercontrol = $outercontrol; |
| 6417 | - if($this->getUseState()) |
|
| 6418 | - $this->ensureTemplateDecoration(); |
|
| 6419 | - else |
|
| 6420 | - $this->_control->getPage()->onSaveStateComplete[] = array($this, 'ensureTemplateDecoration'); |
|
| 6859 | + if($this->getUseState()) { |
|
| 6860 | + $this->ensureTemplateDecoration(); |
|
| 6861 | + } else { |
|
| 6862 | + $this->_control->getPage()->onSaveStateComplete[] = array($this, 'ensureTemplateDecoration'); |
|
| 6863 | + } |
|
| 6421 | 6864 | } |
| 6422 | 6865 | } |
| 6423 | 6866 | public function ensureTemplateDecoration($sender=null, $param=null) { |
| 6424 | 6867 | $control = $this->_control; |
| 6425 | 6868 | $outercontrol = $this->_outercontrol; |
| 6426 | - if($outercontrol === null) |
|
| 6427 | - $outercontrol = $control; |
|
| 6428 | - if($this->_addedTemplateDecoration) |
|
| 6429 | - return $this->_addedTemplateDecoration; |
|
| 6869 | + if($outercontrol === null) { |
|
| 6870 | + $outercontrol = $control; |
|
| 6871 | + } |
|
| 6872 | + if($this->_addedTemplateDecoration) { |
|
| 6873 | + return $this->_addedTemplateDecoration; |
|
| 6874 | + } |
|
| 6430 | 6875 | $this->_addedTemplateDecoration = true; |
| 6431 | 6876 | if($this->getPreContentsTemplate()) |
| 6432 | 6877 | { |
@@ -6440,8 +6885,9 @@ discard block |
||
| 6440 | 6885 | $this->getPostContentsTemplate()->instantiateIn($postcontents); |
| 6441 | 6886 | $control->getControls()->add($postcontents); |
| 6442 | 6887 | } |
| 6443 | - if(!$outercontrol->getParent()) |
|
| 6444 | - return $this->_addedTemplateDecoration; |
|
| 6888 | + if(!$outercontrol->getParent()) { |
|
| 6889 | + return $this->_addedTemplateDecoration; |
|
| 6890 | + } |
|
| 6445 | 6891 | if($this->getPreTagTemplate()) |
| 6446 | 6892 | { |
| 6447 | 6893 | $pretag = Prado::createComponent('TCompositeControl'); |
@@ -6483,8 +6929,9 @@ discard block |
||
| 6483 | 6929 | } |
| 6484 | 6930 | public function getDecorator($create=true) |
| 6485 | 6931 | { |
| 6486 | - if($create && !$this->_decorator) |
|
| 6487 | - $this->_decorator = Prado::createComponent('TWebControlDecorator', $this); |
|
| 6932 | + if($create && !$this->_decorator) { |
|
| 6933 | + $this->_decorator = Prado::createComponent('TWebControlDecorator', $this); |
|
| 6934 | + } |
|
| 6488 | 6935 | return $this->_decorator; |
| 6489 | 6936 | } |
| 6490 | 6937 | public function copyBaseAttributes(TWebControl $control) |
@@ -6492,10 +6939,12 @@ discard block |
||
| 6492 | 6939 | $this->setAccessKey($control->getAccessKey()); |
| 6493 | 6940 | $this->setToolTip($control->getToolTip()); |
| 6494 | 6941 | $this->setTabIndex($control->getTabIndex()); |
| 6495 | - if(!$control->getEnabled()) |
|
| 6496 | - $this->setEnabled(false); |
|
| 6497 | - if($control->getHasAttributes()) |
|
| 6498 | - $this->getAttributes()->copyFrom($control->getAttributes()); |
|
| 6942 | + if(!$control->getEnabled()) { |
|
| 6943 | + $this->setEnabled(false); |
|
| 6944 | + } |
|
| 6945 | + if($control->getHasAttributes()) { |
|
| 6946 | + $this->getAttributes()->copyFrom($control->getAttributes()); |
|
| 6947 | + } |
|
| 6499 | 6948 | } |
| 6500 | 6949 | public function getAccessKey() |
| 6501 | 6950 | { |
@@ -6503,16 +6952,18 @@ discard block |
||
| 6503 | 6952 | } |
| 6504 | 6953 | public function setAccessKey($value) |
| 6505 | 6954 | { |
| 6506 | - if(strlen($value)>1) |
|
| 6507 | - throw new TInvalidDataValueException('webcontrol_accesskey_invalid',get_class($this),$value); |
|
| 6955 | + if(strlen($value)>1) { |
|
| 6956 | + throw new TInvalidDataValueException('webcontrol_accesskey_invalid',get_class($this),$value); |
|
| 6957 | + } |
|
| 6508 | 6958 | $this->setViewState('AccessKey',$value,''); |
| 6509 | 6959 | } |
| 6510 | 6960 | public function getBackColor() |
| 6511 | 6961 | { |
| 6512 | - if($style=$this->getViewState('Style',null)) |
|
| 6513 | - return $style->getBackColor(); |
|
| 6514 | - else |
|
| 6515 | - return ''; |
|
| 6962 | + if($style=$this->getViewState('Style',null)) { |
|
| 6963 | + return $style->getBackColor(); |
|
| 6964 | + } else { |
|
| 6965 | + return ''; |
|
| 6966 | + } |
|
| 6516 | 6967 | } |
| 6517 | 6968 | public function setBackColor($value) |
| 6518 | 6969 | { |
@@ -6520,10 +6971,11 @@ discard block |
||
| 6520 | 6971 | } |
| 6521 | 6972 | public function getBorderColor() |
| 6522 | 6973 | { |
| 6523 | - if($style=$this->getViewState('Style',null)) |
|
| 6524 | - return $style->getBorderColor(); |
|
| 6525 | - else |
|
| 6526 | - return ''; |
|
| 6974 | + if($style=$this->getViewState('Style',null)) { |
|
| 6975 | + return $style->getBorderColor(); |
|
| 6976 | + } else { |
|
| 6977 | + return ''; |
|
| 6978 | + } |
|
| 6527 | 6979 | } |
| 6528 | 6980 | public function setBorderColor($value) |
| 6529 | 6981 | { |
@@ -6531,10 +6983,11 @@ discard block |
||
| 6531 | 6983 | } |
| 6532 | 6984 | public function getBorderStyle() |
| 6533 | 6985 | { |
| 6534 | - if($style=$this->getViewState('Style',null)) |
|
| 6535 | - return $style->getBorderStyle(); |
|
| 6536 | - else |
|
| 6537 | - return ''; |
|
| 6986 | + if($style=$this->getViewState('Style',null)) { |
|
| 6987 | + return $style->getBorderStyle(); |
|
| 6988 | + } else { |
|
| 6989 | + return ''; |
|
| 6990 | + } |
|
| 6538 | 6991 | } |
| 6539 | 6992 | public function setBorderStyle($value) |
| 6540 | 6993 | { |
@@ -6542,10 +6995,11 @@ discard block |
||
| 6542 | 6995 | } |
| 6543 | 6996 | public function getBorderWidth() |
| 6544 | 6997 | { |
| 6545 | - if($style=$this->getViewState('Style',null)) |
|
| 6546 | - return $style->getBorderWidth(); |
|
| 6547 | - else |
|
| 6548 | - return ''; |
|
| 6998 | + if($style=$this->getViewState('Style',null)) { |
|
| 6999 | + return $style->getBorderWidth(); |
|
| 7000 | + } else { |
|
| 7001 | + return ''; |
|
| 7002 | + } |
|
| 6549 | 7003 | } |
| 6550 | 7004 | public function setBorderWidth($value) |
| 6551 | 7005 | { |
@@ -6557,10 +7011,11 @@ discard block |
||
| 6557 | 7011 | } |
| 6558 | 7012 | public function getForeColor() |
| 6559 | 7013 | { |
| 6560 | - if($style=$this->getViewState('Style',null)) |
|
| 6561 | - return $style->getForeColor(); |
|
| 6562 | - else |
|
| 6563 | - return ''; |
|
| 7014 | + if($style=$this->getViewState('Style',null)) { |
|
| 7015 | + return $style->getForeColor(); |
|
| 7016 | + } else { |
|
| 7017 | + return ''; |
|
| 7018 | + } |
|
| 6564 | 7019 | } |
| 6565 | 7020 | public function setForeColor($value) |
| 6566 | 7021 | { |
@@ -6568,10 +7023,11 @@ discard block |
||
| 6568 | 7023 | } |
| 6569 | 7024 | public function getHeight() |
| 6570 | 7025 | { |
| 6571 | - if($style=$this->getViewState('Style',null)) |
|
| 6572 | - return $style->getHeight(); |
|
| 6573 | - else |
|
| 6574 | - return ''; |
|
| 7026 | + if($style=$this->getViewState('Style',null)) { |
|
| 7027 | + return $style->getHeight(); |
|
| 7028 | + } else { |
|
| 7029 | + return ''; |
|
| 7030 | + } |
|
| 6575 | 7031 | } |
| 6576 | 7032 | public function setDisplay($value) |
| 6577 | 7033 | { |
@@ -6587,10 +7043,11 @@ discard block |
||
| 6587 | 7043 | } |
| 6588 | 7044 | public function getCssClass() |
| 6589 | 7045 | { |
| 6590 | - if($style=$this->getViewState('Style',null)) |
|
| 6591 | - return $style->getCssClass(); |
|
| 6592 | - else |
|
| 6593 | - return ''; |
|
| 7046 | + if($style=$this->getViewState('Style',null)) { |
|
| 7047 | + return $style->getCssClass(); |
|
| 7048 | + } else { |
|
| 7049 | + return ''; |
|
| 7050 | + } |
|
| 6594 | 7051 | } |
| 6595 | 7052 | public function setHeight($value) |
| 6596 | 7053 | { |
@@ -6606,9 +7063,9 @@ discard block |
||
| 6606 | 7063 | } |
| 6607 | 7064 | public function getStyle() |
| 6608 | 7065 | { |
| 6609 | - if($style=$this->getViewState('Style',null)) |
|
| 6610 | - return $style; |
|
| 6611 | - else |
|
| 7066 | + if($style=$this->getViewState('Style',null)) { |
|
| 7067 | + return $style; |
|
| 7068 | + } else |
|
| 6612 | 7069 | { |
| 6613 | 7070 | $style=$this->createStyle(); |
| 6614 | 7071 | $this->setViewState('Style',$style,null); |
@@ -6617,10 +7074,11 @@ discard block |
||
| 6617 | 7074 | } |
| 6618 | 7075 | public function setStyle($value) |
| 6619 | 7076 | { |
| 6620 | - if(is_string($value)) |
|
| 6621 | - $this->getStyle()->setCustomStyle($value); |
|
| 6622 | - else |
|
| 6623 | - throw new TInvalidDataValueException('webcontrol_style_invalid',get_class($this)); |
|
| 7077 | + if(is_string($value)) { |
|
| 7078 | + $this->getStyle()->setCustomStyle($value); |
|
| 7079 | + } else { |
|
| 7080 | + throw new TInvalidDataValueException('webcontrol_style_invalid',get_class($this)); |
|
| 7081 | + } |
|
| 6624 | 7082 | } |
| 6625 | 7083 | public function clearStyle() |
| 6626 | 7084 | { |
@@ -6648,38 +7106,47 @@ discard block |
||
| 6648 | 7106 | } |
| 6649 | 7107 | public function getWidth() |
| 6650 | 7108 | { |
| 6651 | - if($style=$this->getViewState('Style',null)) |
|
| 6652 | - return $style->getWidth(); |
|
| 6653 | - else |
|
| 6654 | - return ''; |
|
| 7109 | + if($style=$this->getViewState('Style',null)) { |
|
| 7110 | + return $style->getWidth(); |
|
| 7111 | + } else { |
|
| 7112 | + return ''; |
|
| 7113 | + } |
|
| 6655 | 7114 | } |
| 6656 | 7115 | public function setWidth($value) |
| 6657 | 7116 | { |
| 6658 | 7117 | $this->getStyle()->setWidth($value); |
| 6659 | 7118 | } |
| 6660 | 7119 | public function onPreRender($param) { |
| 6661 | - if($decorator = $this->getDecorator(false)) |
|
| 6662 | - $decorator->instantiate(); |
|
| 7120 | + if($decorator = $this->getDecorator(false)) { |
|
| 7121 | + $decorator->instantiate(); |
|
| 7122 | + } |
|
| 6663 | 7123 | parent::onPreRender($param); |
| 6664 | 7124 | } |
| 6665 | 7125 | protected function addAttributesToRender($writer) |
| 6666 | 7126 | { |
| 6667 | - if($this->getID()!=='' || $this->getEnsureId()) |
|
| 6668 | - $writer->addAttribute('id',$this->getClientID()); |
|
| 6669 | - if(($accessKey=$this->getAccessKey())!=='') |
|
| 6670 | - $writer->addAttribute('accesskey',$accessKey); |
|
| 6671 | - if(!$this->getEnabled()) |
|
| 6672 | - $writer->addAttribute('disabled','disabled'); |
|
| 6673 | - if(($tabIndex=$this->getTabIndex())>0) |
|
| 6674 | - $writer->addAttribute('tabindex',"$tabIndex"); |
|
| 6675 | - if(($toolTip=$this->getToolTip())!=='') |
|
| 6676 | - $writer->addAttribute('title',$toolTip); |
|
| 6677 | - if($style=$this->getViewState('Style',null)) |
|
| 6678 | - $style->addAttributesToRender($writer); |
|
| 7127 | + if($this->getID()!=='' || $this->getEnsureId()) { |
|
| 7128 | + $writer->addAttribute('id',$this->getClientID()); |
|
| 7129 | + } |
|
| 7130 | + if(($accessKey=$this->getAccessKey())!=='') { |
|
| 7131 | + $writer->addAttribute('accesskey',$accessKey); |
|
| 7132 | + } |
|
| 7133 | + if(!$this->getEnabled()) { |
|
| 7134 | + $writer->addAttribute('disabled','disabled'); |
|
| 7135 | + } |
|
| 7136 | + if(($tabIndex=$this->getTabIndex())>0) { |
|
| 7137 | + $writer->addAttribute('tabindex',"$tabIndex"); |
|
| 7138 | + } |
|
| 7139 | + if(($toolTip=$this->getToolTip())!=='') { |
|
| 7140 | + $writer->addAttribute('title',$toolTip); |
|
| 7141 | + } |
|
| 7142 | + if($style=$this->getViewState('Style',null)) { |
|
| 7143 | + $style->addAttributesToRender($writer); |
|
| 7144 | + } |
|
| 6679 | 7145 | if($this->getHasAttributes()) |
| 6680 | 7146 | { |
| 6681 | - foreach($this->getAttributes() as $name=>$value) |
|
| 6682 | - $writer->addAttribute($name,$value); |
|
| 7147 | + foreach($this->getAttributes() as $name=>$value) { |
|
| 7148 | + $writer->addAttribute($name,$value); |
|
| 7149 | + } |
|
| 6683 | 7150 | } |
| 6684 | 7151 | } |
| 6685 | 7152 | public function render($writer) |
@@ -6710,8 +7177,9 @@ discard block |
||
| 6710 | 7177 | $decorator->renderPostContentsText($writer); |
| 6711 | 7178 | $writer->renderEndTag(); |
| 6712 | 7179 | $decorator->renderPostTagText($writer); |
| 6713 | - } else |
|
| 6714 | - $writer->renderEndTag($writer); |
|
| 7180 | + } else { |
|
| 7181 | + $writer->renderEndTag($writer); |
|
| 7182 | + } |
|
| 6715 | 7183 | } |
| 6716 | 7184 | } |
| 6717 | 7185 | class TCompositeControl extends TControl implements INamingContainer |
@@ -6736,12 +7204,13 @@ discard block |
||
| 6736 | 7204 | if($this->_localTemplate===null) |
| 6737 | 7205 | { |
| 6738 | 7206 | $class=get_class($this); |
| 6739 | - if(!isset(self::$_template[$class])) |
|
| 6740 | - self::$_template[$class]=$this->loadTemplate(); |
|
| 7207 | + if(!isset(self::$_template[$class])) { |
|
| 7208 | + self::$_template[$class]=$this->loadTemplate(); |
|
| 7209 | + } |
|
| 6741 | 7210 | return self::$_template[$class]; |
| 7211 | + } else { |
|
| 7212 | + return $this->_localTemplate; |
|
| 6742 | 7213 | } |
| 6743 | - else |
|
| 6744 | - return $this->_localTemplate; |
|
| 6745 | 7214 | } |
| 6746 | 7215 | public function setTemplate($value) |
| 6747 | 7216 | { |
@@ -6749,17 +7218,19 @@ discard block |
||
| 6749 | 7218 | } |
| 6750 | 7219 | public function getIsSourceTemplateControl() |
| 6751 | 7220 | { |
| 6752 | - if(($template=$this->getTemplate())!==null) |
|
| 6753 | - return $template->getIsSourceTemplate(); |
|
| 6754 | - else |
|
| 6755 | - return false; |
|
| 7221 | + if(($template=$this->getTemplate())!==null) { |
|
| 7222 | + return $template->getIsSourceTemplate(); |
|
| 7223 | + } else { |
|
| 7224 | + return false; |
|
| 7225 | + } |
|
| 6756 | 7226 | } |
| 6757 | 7227 | public function getTemplateDirectory() |
| 6758 | 7228 | { |
| 6759 | - if(($template=$this->getTemplate())!==null) |
|
| 6760 | - return $template->getContextPath(); |
|
| 6761 | - else |
|
| 6762 | - return ''; |
|
| 7229 | + if(($template=$this->getTemplate())!==null) { |
|
| 7230 | + return $template->getContextPath(); |
|
| 7231 | + } else { |
|
| 7232 | + return ''; |
|
| 7233 | + } |
|
| 6763 | 7234 | } |
| 6764 | 7235 | protected function loadTemplate() |
| 6765 | 7236 | { |
@@ -6772,27 +7243,30 @@ discard block |
||
| 6772 | 7243 | { |
| 6773 | 7244 | foreach($tpl->getDirective() as $name=>$value) |
| 6774 | 7245 | { |
| 6775 | - if(is_string($value)) |
|
| 6776 | - $this->setSubProperty($name,$value); |
|
| 6777 | - else |
|
| 6778 | - throw new TConfigurationException('templatecontrol_directive_invalid',get_class($this),$name); |
|
| 7246 | + if(is_string($value)) { |
|
| 7247 | + $this->setSubProperty($name,$value); |
|
| 7248 | + } else { |
|
| 7249 | + throw new TConfigurationException('templatecontrol_directive_invalid',get_class($this),$name); |
|
| 7250 | + } |
|
| 6779 | 7251 | } |
| 6780 | 7252 | $tpl->instantiateIn($this); |
| 6781 | 7253 | } |
| 6782 | 7254 | } |
| 6783 | 7255 | public function registerContent($id,TContent $object) |
| 6784 | 7256 | { |
| 6785 | - if(isset($this->_contents[$id])) |
|
| 6786 | - throw new TConfigurationException('templatecontrol_contentid_duplicated',$id); |
|
| 6787 | - else |
|
| 6788 | - $this->_contents[$id]=$object; |
|
| 7257 | + if(isset($this->_contents[$id])) { |
|
| 7258 | + throw new TConfigurationException('templatecontrol_contentid_duplicated',$id); |
|
| 7259 | + } else { |
|
| 7260 | + $this->_contents[$id]=$object; |
|
| 7261 | + } |
|
| 6789 | 7262 | } |
| 6790 | 7263 | public function registerContentPlaceHolder($id,TContentPlaceHolder $object) |
| 6791 | 7264 | { |
| 6792 | - if(isset($this->_placeholders[$id])) |
|
| 6793 | - throw new TConfigurationException('templatecontrol_placeholderid_duplicated',$id); |
|
| 6794 | - else |
|
| 6795 | - $this->_placeholders[$id]=$object; |
|
| 7265 | + if(isset($this->_placeholders[$id])) { |
|
| 7266 | + throw new TConfigurationException('templatecontrol_placeholderid_duplicated',$id); |
|
| 7267 | + } else { |
|
| 7268 | + $this->_placeholders[$id]=$object; |
|
| 7269 | + } |
|
| 6796 | 7270 | } |
| 6797 | 7271 | public function getMasterClass() |
| 6798 | 7272 | { |
@@ -6814,9 +7288,9 @@ discard block |
||
| 6814 | 7288 | $controls=$placeholder->getParent()->getControls(); |
| 6815 | 7289 | $loc=$controls->remove($placeholder); |
| 6816 | 7290 | $controls->insertAt($loc,$content); |
| 7291 | + } else { |
|
| 7292 | + throw new TConfigurationException('templatecontrol_placeholder_inexistent',$id); |
|
| 6817 | 7293 | } |
| 6818 | - else |
|
| 6819 | - throw new TConfigurationException('templatecontrol_placeholder_inexistent',$id); |
|
| 6820 | 7294 | } |
| 6821 | 7295 | protected function initRecursive($namingContainer=null) |
| 6822 | 7296 | { |
@@ -6824,17 +7298,19 @@ discard block |
||
| 6824 | 7298 | if($this->_masterClass!=='') |
| 6825 | 7299 | { |
| 6826 | 7300 | $master=Prado::createComponent($this->_masterClass); |
| 6827 | - if(!($master instanceof TTemplateControl)) |
|
| 6828 | - throw new TInvalidDataValueException('templatecontrol_mastercontrol_invalid'); |
|
| 7301 | + if(!($master instanceof TTemplateControl)) { |
|
| 7302 | + throw new TInvalidDataValueException('templatecontrol_mastercontrol_invalid'); |
|
| 7303 | + } |
|
| 6829 | 7304 | $this->_master=$master; |
| 6830 | 7305 | $this->getControls()->clear(); |
| 6831 | 7306 | $this->getControls()->add($master); |
| 6832 | 7307 | $master->ensureChildControls(); |
| 6833 | - foreach($this->_contents as $id=>$content) |
|
| 6834 | - $master->injectContent($id,$content); |
|
| 7308 | + foreach($this->_contents as $id=>$content) { |
|
| 7309 | + $master->injectContent($id,$content); |
|
| 7310 | + } |
|
| 7311 | + } else if(!empty($this->_contents)) { |
|
| 7312 | + throw new TConfigurationException('templatecontrol_mastercontrol_required',get_class($this)); |
|
| 6835 | 7313 | } |
| 6836 | - else if(!empty($this->_contents)) |
|
| 6837 | - throw new TConfigurationException('templatecontrol_mastercontrol_required',get_class($this)); |
|
| 6838 | 7314 | parent::initRecursive($namingContainer); |
| 6839 | 7315 | } |
| 6840 | 7316 | public function tryToUpdateView($arObj, $throwExceptions = false) |
@@ -6847,14 +7323,14 @@ discard block |
||
| 6847 | 7323 | if ($key != "RELATIONS") |
| 6848 | 7324 | { |
| 6849 | 7325 | $control = $this->{$key}; |
| 6850 | - if ($control instanceof TTextBox) |
|
| 6851 | - $control->Text = $arObj->{$key}; |
|
| 6852 | - elseif ($control instanceof TCheckBox) |
|
| 6853 | - $control->Checked = (boolean) $arObj->{$key}; |
|
| 6854 | - elseif ($control instanceof TDatePicker) |
|
| 6855 | - $control->Date = $arObj->{$key}; |
|
| 6856 | - } |
|
| 6857 | - else |
|
| 7326 | + if ($control instanceof TTextBox) { |
|
| 7327 | + $control->Text = $arObj->{$key}; |
|
| 7328 | + } elseif ($control instanceof TCheckBox) { |
|
| 7329 | + $control->Checked = (boolean) $arObj->{$key}; |
|
| 7330 | + } elseif ($control instanceof TDatePicker) { |
|
| 7331 | + $control->Date = $arObj->{$key}; |
|
| 7332 | + } |
|
| 7333 | + } else |
|
| 6858 | 7334 | { |
| 6859 | 7335 | foreach ($objAttrs["RELATIONS"] as $relKey => $relValues) |
| 6860 | 7336 | { |
@@ -6876,11 +7352,11 @@ discard block |
||
| 6876 | 7352 | } |
| 6877 | 7353 | break; |
| 6878 | 7354 | } |
| 6879 | - } |
|
| 6880 | - catch (Exception $ex) |
|
| 7355 | + } catch (Exception $ex) |
|
| 6881 | 7356 | { |
| 6882 | - if ($throwExceptions) |
|
| 6883 | - throw $ex; |
|
| 7357 | + if ($throwExceptions) { |
|
| 7358 | + throw $ex; |
|
| 7359 | + } |
|
| 6884 | 7360 | } |
| 6885 | 7361 | } |
| 6886 | 7362 | } |
@@ -6891,20 +7367,22 @@ discard block |
||
| 6891 | 7367 | { |
| 6892 | 7368 | try |
| 6893 | 7369 | { |
| 6894 | - if ($key == "RELATIONS") |
|
| 6895 | - break; |
|
| 7370 | + if ($key == "RELATIONS") { |
|
| 7371 | + break; |
|
| 7372 | + } |
|
| 6896 | 7373 | $control = $this->{$key}; |
| 6897 | - if ($control instanceof TTextBox) |
|
| 6898 | - $arObj->{$key} = $control->Text; |
|
| 6899 | - elseif ($control instanceof TCheckBox) |
|
| 6900 | - $arObj->{$key} = $control->Checked; |
|
| 6901 | - elseif ($control instanceof TDatePicker) |
|
| 6902 | - $arObj->{$key} = $control->Date; |
|
| 6903 | - } |
|
| 6904 | - catch (Exception $ex) |
|
| 7374 | + if ($control instanceof TTextBox) { |
|
| 7375 | + $arObj->{$key} = $control->Text; |
|
| 7376 | + } elseif ($control instanceof TCheckBox) { |
|
| 7377 | + $arObj->{$key} = $control->Checked; |
|
| 7378 | + } elseif ($control instanceof TDatePicker) { |
|
| 7379 | + $arObj->{$key} = $control->Date; |
|
| 7380 | + } |
|
| 7381 | + } catch (Exception $ex) |
|
| 6905 | 7382 | { |
| 6906 | - if ($throwExceptions) |
|
| 6907 | - throw $ex; |
|
| 7383 | + if ($throwExceptions) { |
|
| 7384 | + throw $ex; |
|
| 7385 | + } |
|
| 6908 | 7386 | } |
| 6909 | 7387 | } |
| 6910 | 7388 | } |
@@ -6922,17 +7400,19 @@ discard block |
||
| 6922 | 7400 | $writer->addAttribute('method',$this->getMethod()); |
| 6923 | 7401 | $uri=$this->getRequest()->getRequestURI(); |
| 6924 | 7402 | $writer->addAttribute('action',str_replace('&','&',str_replace('&','&',$uri))); |
| 6925 | - if(($enctype=$this->getEnctype())!=='') |
|
| 6926 | - $writer->addAttribute('enctype',$enctype); |
|
| 7403 | + if(($enctype=$this->getEnctype())!=='') { |
|
| 7404 | + $writer->addAttribute('enctype',$enctype); |
|
| 7405 | + } |
|
| 6927 | 7406 | $attributes=$this->getAttributes(); |
| 6928 | 7407 | $attributes->remove('action'); |
| 6929 | 7408 | $writer->addAttributes($attributes); |
| 6930 | 7409 | if(($butt=$this->getDefaultButton())!=='') |
| 6931 | 7410 | { |
| 6932 | - if(($button=$this->findControl($butt))!==null) |
|
| 6933 | - $this->getPage()->getClientScript()->registerDefaultButton($this, $button); |
|
| 6934 | - else |
|
| 6935 | - throw new TInvalidDataValueException('form_defaultbutton_invalid',$butt); |
|
| 7411 | + if(($button=$this->findControl($butt))!==null) { |
|
| 7412 | + $this->getPage()->getClientScript()->registerDefaultButton($this, $button); |
|
| 7413 | + } else { |
|
| 7414 | + throw new TInvalidDataValueException('form_defaultbutton_invalid',$butt); |
|
| 7415 | + } |
|
| 6936 | 7416 | } |
| 6937 | 7417 | } |
| 6938 | 7418 | public function render($writer) |
@@ -6952,8 +7432,7 @@ discard block |
||
| 6952 | 7432 | $page->endFormRender($writer); |
| 6953 | 7433 | $cs->renderScriptFilesEnd($writer); |
| 6954 | 7434 | $cs->renderEndScripts($writer); |
| 6955 | - } |
|
| 6956 | - else |
|
| 7435 | + } else |
|
| 6957 | 7436 | { |
| 6958 | 7437 | $cs->renderHiddenFieldsBegin($writer); |
| 6959 | 7438 | $page->beginFormRender($writer); |
@@ -7045,10 +7524,11 @@ discard block |
||
| 7045 | 7524 | self::$_pradoScripts = $deps; |
| 7046 | 7525 | self::$_pradoPackages = $packages; |
| 7047 | 7526 | } |
| 7048 | - if (isset(self::$_pradoScripts[$name])) |
|
| 7049 | - $this->_registeredPradoScripts[$name]=true; |
|
| 7050 | - else |
|
| 7051 | - throw new TInvalidOperationException('csmanager_pradoscript_invalid',$name); |
|
| 7527 | + if (isset(self::$_pradoScripts[$name])) { |
|
| 7528 | + $this->_registeredPradoScripts[$name]=true; |
|
| 7529 | + } else { |
|
| 7530 | + throw new TInvalidOperationException('csmanager_pradoscript_invalid',$name); |
|
| 7531 | + } |
|
| 7052 | 7532 | if(($packages=array_keys($this->_registeredPradoScripts))!==array()) |
| 7053 | 7533 | { |
| 7054 | 7534 | $base = Prado::getFrameworkPath().DIRECTORY_SEPARATOR.self::SCRIPT_PATH; |
@@ -7059,22 +7539,25 @@ discard block |
||
| 7059 | 7539 | { |
| 7060 | 7540 | foreach (self::$_pradoScripts[$p] as $dep) |
| 7061 | 7541 | { |
| 7062 | - foreach (self::$_pradoPackages[$dep] as $script) |
|
| 7063 | - if (!isset($this->_expandedPradoScripts[$script])) |
|
| 7542 | + foreach (self::$_pradoPackages[$dep] as $script) { |
|
| 7543 | + if (!isset($this->_expandedPradoScripts[$script])) |
|
| 7064 | 7544 | { |
| 7065 | 7545 | $this->_expandedPradoScripts[$script] = true; |
| 7546 | + } |
|
| 7066 | 7547 | if($isDebug) |
| 7067 | 7548 | { |
| 7068 | - if (!in_array($url=$baseUrl.'/'.$script,$packagesUrl)) |
|
| 7069 | - $packagesUrl[]=$url; |
|
| 7549 | + if (!in_array($url=$baseUrl.'/'.$script,$packagesUrl)) { |
|
| 7550 | + $packagesUrl[]=$url; |
|
| 7551 | + } |
|
| 7070 | 7552 | } else { |
| 7071 | 7553 | if (!in_array($url=$baseUrl.'/min/'.$script,$packagesUrl)) |
| 7072 | 7554 | { |
| 7073 | 7555 | if(!is_file($filePath=$path.'/min/'.$script)) |
| 7074 | 7556 | { |
| 7075 | 7557 | $dirPath=dirname($filePath); |
| 7076 | - if(!is_dir($dirPath)) |
|
| 7077 | - mkdir($dirPath, PRADO_CHMOD, true); |
|
| 7558 | + if(!is_dir($dirPath)) { |
|
| 7559 | + mkdir($dirPath, PRADO_CHMOD, true); |
|
| 7560 | + } |
|
| 7078 | 7561 | file_put_contents($filePath, TJavaScript::JSMin(file_get_contents($base.'/'.$script))); |
| 7079 | 7562 | chmod($filePath, PRADO_CHMOD); |
| 7080 | 7563 | } |
@@ -7084,8 +7567,9 @@ discard block |
||
| 7084 | 7567 | } |
| 7085 | 7568 | } |
| 7086 | 7569 | } |
| 7087 | - foreach($packagesUrl as $url) |
|
| 7088 | - $this->registerScriptFile($url,$url); |
|
| 7570 | + foreach($packagesUrl as $url) { |
|
| 7571 | + $this->registerScriptFile($url,$url); |
|
| 7572 | + } |
|
| 7089 | 7573 | } |
| 7090 | 7574 | } |
| 7091 | 7575 | } |
@@ -7111,8 +7595,7 @@ discard block |
||
| 7111 | 7595 | $base = $dir; |
| 7112 | 7596 | } |
| 7113 | 7597 | return array($assets->getPublishedPath($base), $assets->publishFilePath($base)); |
| 7114 | - } |
|
| 7115 | - else |
|
| 7598 | + } else |
|
| 7116 | 7599 | { |
| 7117 | 7600 | return array($assets->getBasePath().str_replace($assets->getBaseUrl(),'',$base), $base); |
| 7118 | 7601 | } |
@@ -7142,8 +7625,9 @@ discard block |
||
| 7142 | 7625 | if($class === null) { |
| 7143 | 7626 | return; |
| 7144 | 7627 | } |
| 7145 | - if(!isset($options['FormID']) && ($form=$this->_page->getForm())!==null) |
|
| 7146 | - $options['FormID']=$form->getClientID(); |
|
| 7628 | + if(!isset($options['FormID']) && ($form=$this->_page->getForm())!==null) { |
|
| 7629 | + $options['FormID']=$form->getClientID(); |
|
| 7630 | + } |
|
| 7147 | 7631 | $optionString=TJavaScript::encode($options); |
| 7148 | 7632 | $code="new {$class}({$optionString});"; |
| 7149 | 7633 | $this->_endScripts[sprintf('%08X', crc32($code))]=$code; |
@@ -7154,9 +7638,9 @@ discard block |
||
| 7154 | 7638 | public function registerDefaultButton($panel, $button) |
| 7155 | 7639 | { |
| 7156 | 7640 | $panelID=is_string($panel)?$panel:$panel->getUniqueID(); |
| 7157 | - if(is_string($button)) |
|
| 7158 | - $buttonID=$button; |
|
| 7159 | - else |
|
| 7641 | + if(is_string($button)) { |
|
| 7642 | + $buttonID=$button; |
|
| 7643 | + } else |
|
| 7160 | 7644 | { |
| 7161 | 7645 | $button->setIsDefaultButton(true); |
| 7162 | 7646 | $buttonID=$button->getUniqueID(); |
@@ -7180,18 +7664,20 @@ discard block |
||
| 7180 | 7664 | public function registerFocusControl($target) |
| 7181 | 7665 | { |
| 7182 | 7666 | $this->registerPradoScriptInternal('jquery'); |
| 7183 | - if($target instanceof TControl) |
|
| 7184 | - $target=$target->getClientID(); |
|
| 7667 | + if($target instanceof TControl) { |
|
| 7668 | + $target=$target->getClientID(); |
|
| 7669 | + } |
|
| 7185 | 7670 | $this->_endScripts['prado:focus'] = 'jQuery(\'#'.$target.'\').focus();'; |
| 7186 | 7671 | $params=func_get_args(); |
| 7187 | 7672 | $this->_page->registerCachingAction('Page.ClientScript','registerFocusControl',$params); |
| 7188 | 7673 | } |
| 7189 | 7674 | public function registerStyleSheetFile($key,$url,$media='') |
| 7190 | 7675 | { |
| 7191 | - if($media==='') |
|
| 7192 | - $this->_styleSheetFiles[$key]=$url; |
|
| 7193 | - else |
|
| 7194 | - $this->_styleSheetFiles[$key]=array($url,$media); |
|
| 7676 | + if($media==='') { |
|
| 7677 | + $this->_styleSheetFiles[$key]=$url; |
|
| 7678 | + } else { |
|
| 7679 | + $this->_styleSheetFiles[$key]=array($url,$media); |
|
| 7680 | + } |
|
| 7195 | 7681 | $params=func_get_args(); |
| 7196 | 7682 | $this->_page->registerCachingAction('Page.ClientScript','registerStyleSheetFile',$params); |
| 7197 | 7683 | } |
@@ -7208,9 +7694,10 @@ discard block |
||
| 7208 | 7694 | return is_array($e) ? $e[0] : $e; |
| 7209 | 7695 | }, $this->_styleSheetFiles) |
| 7210 | 7696 | ); |
| 7211 | - foreach(Prado::getApplication()->getAssetManager()->getPublished() as $path=>$url) |
|
| 7212 | - if (substr($url,strlen($url)-4)=='.css') |
|
| 7697 | + foreach(Prado::getApplication()->getAssetManager()->getPublished() as $path=>$url) { |
|
| 7698 | + if (substr($url,strlen($url)-4)=='.css') |
|
| 7213 | 7699 | $stylesheets[] = $url; |
| 7700 | + } |
|
| 7214 | 7701 | $stylesheets = array_unique($stylesheets); |
| 7215 | 7702 | return $stylesheets; |
| 7216 | 7703 | } |
@@ -7302,17 +7789,19 @@ discard block |
||
| 7302 | 7789 | $str=''; |
| 7303 | 7790 | foreach($this->_styleSheetFiles as $url) |
| 7304 | 7791 | { |
| 7305 | - if(is_array($url)) |
|
| 7306 | - $str.="<link rel=\"stylesheet\" type=\"text/css\" media=\"{$url[1]}\" href=\"".THttpUtility::htmlEncode($url[0])."\" />\n"; |
|
| 7307 | - else |
|
| 7308 | - $str.="<link rel=\"stylesheet\" type=\"text/css\" href=\"".THttpUtility::htmlEncode($url)."\" />\n"; |
|
| 7792 | + if(is_array($url)) { |
|
| 7793 | + $str.="<link rel=\"stylesheet\" type=\"text/css\" media=\"{$url[1]}\" href=\"".THttpUtility::htmlEncode($url[0])."\" />\n"; |
|
| 7794 | + } else { |
|
| 7795 | + $str.="<link rel=\"stylesheet\" type=\"text/css\" href=\"".THttpUtility::htmlEncode($url)."\" />\n"; |
|
| 7796 | + } |
|
| 7309 | 7797 | } |
| 7310 | 7798 | $writer->write($str); |
| 7311 | 7799 | } |
| 7312 | 7800 | public function renderStyleSheets($writer) |
| 7313 | 7801 | { |
| 7314 | - if(count($this->_styleSheets)) |
|
| 7315 | - $writer->write("<style type=\"text/css\">\n/*<![CDATA[*/\n".implode("\n",$this->_styleSheets)."\n/*]]>*/\n</style>\n"); |
|
| 7802 | + if(count($this->_styleSheets)) { |
|
| 7803 | + $writer->write("<style type=\"text/css\">\n/*<![CDATA[*/\n".implode("\n",$this->_styleSheets)."\n/*]]>*/\n</style>\n"); |
|
| 7804 | + } |
|
| 7316 | 7805 | } |
| 7317 | 7806 | public function renderHeadScriptFiles($writer) |
| 7318 | 7807 | { |
@@ -7390,25 +7879,30 @@ discard block |
||
| 7390 | 7879 | } |
| 7391 | 7880 | protected function renderHiddenFieldsInt($writer, $initial) |
| 7392 | 7881 | { |
| 7393 | - if ($initial) $this->_renderedHiddenFields = array(); |
|
| 7882 | + if ($initial) { |
|
| 7883 | + $this->_renderedHiddenFields = array(); |
|
| 7884 | + } |
|
| 7394 | 7885 | $str=''; |
| 7395 | 7886 | foreach($this->_hiddenFields as $name=>$value) |
| 7396 | 7887 | { |
| 7397 | - if (in_array($name,$this->_renderedHiddenFields)) continue; |
|
| 7888 | + if (in_array($name,$this->_renderedHiddenFields)) { |
|
| 7889 | + continue; |
|
| 7890 | + } |
|
| 7398 | 7891 | $id=strtr($name,':','_'); |
| 7399 | 7892 | if(is_array($value)) |
| 7400 | 7893 | { |
| 7401 | - foreach($value as $v) |
|
| 7402 | - $str.='<input type="hidden" name="'.$name.'[]" id="'.$id.'" value="'.THttpUtility::htmlEncode($value)."\" />\n"; |
|
| 7403 | - } |
|
| 7404 | - else |
|
| 7894 | + foreach($value as $v) { |
|
| 7895 | + $str.='<input type="hidden" name="'.$name.'[]" id="'.$id.'" value="'.THttpUtility::htmlEncode($value)."\" />\n"; |
|
| 7896 | + } |
|
| 7897 | + } else |
|
| 7405 | 7898 | { |
| 7406 | 7899 | $str.='<input type="hidden" name="'.$name.'" id="'.$id.'" value="'.THttpUtility::htmlEncode($value)."\" />\n"; |
| 7407 | 7900 | } |
| 7408 | 7901 | $this->_renderedHiddenFields[] = $name; |
| 7409 | 7902 | } |
| 7410 | - if($str!=='') |
|
| 7411 | - $writer->write("<div style=\"visibility:hidden;\">\n".$str."</div>\n"); |
|
| 7903 | + if($str!=='') { |
|
| 7904 | + $writer->write("<div style=\"visibility:hidden;\">\n".$str."</div>\n"); |
|
| 7905 | + } |
|
| 7412 | 7906 | } |
| 7413 | 7907 | public function getHiddenFields() |
| 7414 | 7908 | { |
@@ -7416,8 +7910,9 @@ discard block |
||
| 7416 | 7910 | } |
| 7417 | 7911 | protected function checkIfNotInRender() |
| 7418 | 7912 | { |
| 7419 | - if ($form = $this->_page->InFormRender) |
|
| 7420 | - throw new Exception('Operation invalid when page is already rendering'); |
|
| 7913 | + if ($form = $this->_page->InFormRender) { |
|
| 7914 | + throw new Exception('Operation invalid when page is already rendering'); |
|
| 7915 | + } |
|
| 7421 | 7916 | } |
| 7422 | 7917 | } |
| 7423 | 7918 | abstract class TClientSideOptions extends TComponent |
@@ -7425,16 +7920,18 @@ discard block |
||
| 7425 | 7920 | private $_options; |
| 7426 | 7921 | protected function setFunction($name, $code) |
| 7427 | 7922 | { |
| 7428 | - if(!TJavaScript::isJsLiteral($code)) |
|
| 7429 | - $code = TJavaScript::quoteJsLiteral($this->ensureFunction($code)); |
|
| 7923 | + if(!TJavaScript::isJsLiteral($code)) { |
|
| 7924 | + $code = TJavaScript::quoteJsLiteral($this->ensureFunction($code)); |
|
| 7925 | + } |
|
| 7430 | 7926 | $this->setOption($name, $code); |
| 7431 | 7927 | } |
| 7432 | 7928 | protected function getOption($name) |
| 7433 | 7929 | { |
| 7434 | - if ($this->_options) |
|
| 7435 | - return $this->_options->itemAt($name); |
|
| 7436 | - else |
|
| 7437 | - return null; |
|
| 7930 | + if ($this->_options) { |
|
| 7931 | + return $this->_options->itemAt($name); |
|
| 7932 | + } else { |
|
| 7933 | + return null; |
|
| 7934 | + } |
|
| 7438 | 7935 | } |
| 7439 | 7936 | protected function setOption($name, $value) |
| 7440 | 7937 | { |
@@ -7442,8 +7939,9 @@ discard block |
||
| 7442 | 7939 | } |
| 7443 | 7940 | public function getOptions() |
| 7444 | 7941 | { |
| 7445 | - if (!$this->_options) |
|
| 7446 | - $this->_options = Prado::createComponent('System.Collections.TMap'); |
|
| 7942 | + if (!$this->_options) { |
|
| 7943 | + $this->_options = Prado::createComponent('System.Collections.TMap'); |
|
| 7944 | + } |
|
| 7447 | 7945 | return $this->_options; |
| 7448 | 7946 | } |
| 7449 | 7947 | protected function ensureFunction($javascript) |
@@ -7506,13 +8004,14 @@ discard block |
||
| 7506 | 8004 | $this->determinePostBackMode(); |
| 7507 | 8005 | if($this->getIsPostBack()) |
| 7508 | 8006 | { |
| 7509 | - if($this->getIsCallback()) |
|
| 7510 | - $this->processCallbackRequest($writer); |
|
| 7511 | - else |
|
| 7512 | - $this->processPostBackRequest($writer); |
|
| 8007 | + if($this->getIsCallback()) { |
|
| 8008 | + $this->processCallbackRequest($writer); |
|
| 8009 | + } else { |
|
| 8010 | + $this->processPostBackRequest($writer); |
|
| 8011 | + } |
|
| 8012 | + } else { |
|
| 8013 | + $this->processNormalRequest($writer); |
|
| 7513 | 8014 | } |
| 7514 | - else |
|
| 7515 | - $this->processNormalRequest($writer); |
|
| 7516 | 8015 | $this->_writer = null; |
| 7517 | 8016 | } |
| 7518 | 8017 | protected function processNormalRequest($writer) |
@@ -7555,8 +8054,9 @@ discard block |
||
| 7555 | 8054 | { |
| 7556 | 8055 | if(is_array($data)) |
| 7557 | 8056 | { |
| 7558 | - foreach($data as $k=>$v) |
|
| 7559 | - $data[$k]=self::decodeUTF8($v, $enc); |
|
| 8057 | + foreach($data as $k=>$v) { |
|
| 8058 | + $data[$k]=self::decodeUTF8($v, $enc); |
|
| 8059 | + } |
|
| 7560 | 8060 | return $data; |
| 7561 | 8061 | } elseif(is_string($data)) { |
| 7562 | 8062 | return iconv('UTF-8',$enc.'//IGNORE',$data); |
@@ -7570,12 +8070,14 @@ discard block |
||
| 7570 | 8070 | Prado::using('System.Web.UI.JuiControls.TJuiControlOptions'); |
| 7571 | 8071 | $this->setAdapter(new TActivePageAdapter($this)); |
| 7572 | 8072 | $callbackEventParameter = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_PARAMETER); |
| 7573 | - if(strlen($callbackEventParameter) > 0) |
|
| 7574 | - $this->_postData[TPage::FIELD_CALLBACK_PARAMETER]=TJavaScript::jsonDecode((string)$callbackEventParameter); |
|
| 8073 | + if(strlen($callbackEventParameter) > 0) { |
|
| 8074 | + $this->_postData[TPage::FIELD_CALLBACK_PARAMETER]=TJavaScript::jsonDecode((string)$callbackEventParameter); |
|
| 8075 | + } |
|
| 7575 | 8076 | if (($g=$this->getApplication()->getGlobalization(false))!==null && |
| 7576 | - strtoupper($enc=$g->getCharset())!='UTF-8') |
|
| 7577 | - foreach ($this->_postData as $k=>$v) |
|
| 8077 | + strtoupper($enc=$g->getCharset())!='UTF-8') { |
|
| 8078 | + foreach ($this->_postData as $k=>$v) |
|
| 7578 | 8079 | $this->_postData[$k]=self::decodeUTF8($v, $enc); |
| 8080 | + } |
|
| 7579 | 8081 | $this->onPreInit(null); |
| 7580 | 8082 | $this->initRecursive(); |
| 7581 | 8083 | $this->onInitComplete(null); |
@@ -7597,10 +8099,11 @@ discard block |
||
| 7597 | 8099 | } |
| 7598 | 8100 | public function getCallbackClient() |
| 7599 | 8101 | { |
| 7600 | - if($this->getAdapter() !== null) |
|
| 7601 | - return $this->getAdapter()->getCallbackClientHandler(); |
|
| 7602 | - else |
|
| 7603 | - return new TCallbackClientScript(); |
|
| 8102 | + if($this->getAdapter() !== null) { |
|
| 8103 | + return $this->getAdapter()->getCallbackClientHandler(); |
|
| 8104 | + } else { |
|
| 8105 | + return new TCallbackClientScript(); |
|
| 8106 | + } |
|
| 7604 | 8107 | } |
| 7605 | 8108 | public function setCallbackClient($client) |
| 7606 | 8109 | { |
@@ -7628,23 +8131,26 @@ discard block |
||
| 7628 | 8131 | } |
| 7629 | 8132 | public function setForm(TForm $form) |
| 7630 | 8133 | { |
| 7631 | - if($this->_form===null) |
|
| 7632 | - $this->_form=$form; |
|
| 7633 | - else |
|
| 7634 | - throw new TInvalidOperationException('page_form_duplicated'); |
|
| 8134 | + if($this->_form===null) { |
|
| 8135 | + $this->_form=$form; |
|
| 8136 | + } else { |
|
| 8137 | + throw new TInvalidOperationException('page_form_duplicated'); |
|
| 8138 | + } |
|
| 7635 | 8139 | } |
| 7636 | 8140 | public function getValidators($validationGroup=null) |
| 7637 | 8141 | { |
| 7638 | - if(!$this->_validators) |
|
| 7639 | - $this->_validators=new TList; |
|
| 7640 | - if(empty($validationGroup) === true) |
|
| 7641 | - return $this->_validators; |
|
| 7642 | - else |
|
| 8142 | + if(!$this->_validators) { |
|
| 8143 | + $this->_validators=new TList; |
|
| 8144 | + } |
|
| 8145 | + if(empty($validationGroup) === true) { |
|
| 8146 | + return $this->_validators; |
|
| 8147 | + } else |
|
| 7643 | 8148 | { |
| 7644 | 8149 | $list=new TList; |
| 7645 | - foreach($this->_validators as $validator) |
|
| 7646 | - if($validator->getValidationGroup()===$validationGroup) |
|
| 8150 | + foreach($this->_validators as $validator) { |
|
| 8151 | + if($validator->getValidationGroup()===$validationGroup) |
|
| 7647 | 8152 | $list->add($validator); |
| 8153 | + } |
|
| 7648 | 8154 | return $list; |
| 7649 | 8155 | } |
| 7650 | 8156 | } |
@@ -7655,15 +8161,16 @@ discard block |
||
| 7655 | 8161 | { |
| 7656 | 8162 | if($validationGroup===null) |
| 7657 | 8163 | { |
| 7658 | - foreach($this->_validators as $validator) |
|
| 7659 | - $validator->validate(); |
|
| 7660 | - } |
|
| 7661 | - else |
|
| 8164 | + foreach($this->_validators as $validator) { |
|
| 8165 | + $validator->validate(); |
|
| 8166 | + } |
|
| 8167 | + } else |
|
| 7662 | 8168 | { |
| 7663 | 8169 | foreach($this->_validators as $validator) |
| 7664 | 8170 | { |
| 7665 | - if($validator->getValidationGroup()===$validationGroup) |
|
| 7666 | - $validator->validate(); |
|
| 8171 | + if($validator->getValidationGroup()===$validationGroup) { |
|
| 8172 | + $validator->validate(); |
|
| 8173 | + } |
|
| 7667 | 8174 | } |
| 7668 | 8175 | } |
| 7669 | 8176 | } |
@@ -7674,19 +8181,21 @@ discard block |
||
| 7674 | 8181 | { |
| 7675 | 8182 | if($this->_validators && $this->_validators->getCount()) |
| 7676 | 8183 | { |
| 7677 | - foreach($this->_validators as $validator) |
|
| 7678 | - if(!$validator->getIsValid()) |
|
| 8184 | + foreach($this->_validators as $validator) { |
|
| 8185 | + if(!$validator->getIsValid()) |
|
| 7679 | 8186 | return false; |
| 8187 | + } |
|
| 7680 | 8188 | } |
| 7681 | 8189 | return true; |
| 8190 | + } else { |
|
| 8191 | + throw new TInvalidOperationException('page_isvalid_unknown'); |
|
| 7682 | 8192 | } |
| 7683 | - else |
|
| 7684 | - throw new TInvalidOperationException('page_isvalid_unknown'); |
|
| 7685 | 8193 | } |
| 7686 | 8194 | public function getTheme() |
| 7687 | 8195 | { |
| 7688 | - if(is_string($this->_theme)) |
|
| 7689 | - $this->_theme=$this->getService()->getThemeManager()->getTheme($this->_theme); |
|
| 8196 | + if(is_string($this->_theme)) { |
|
| 8197 | + $this->_theme=$this->getService()->getThemeManager()->getTheme($this->_theme); |
|
| 8198 | + } |
|
| 7690 | 8199 | return $this->_theme; |
| 7691 | 8200 | } |
| 7692 | 8201 | public function setTheme($value) |
@@ -7695,8 +8204,9 @@ discard block |
||
| 7695 | 8204 | } |
| 7696 | 8205 | public function getStyleSheetTheme() |
| 7697 | 8206 | { |
| 7698 | - if(is_string($this->_styleSheet)) |
|
| 7699 | - $this->_styleSheet=$this->getService()->getThemeManager()->getTheme($this->_styleSheet); |
|
| 8207 | + if(is_string($this->_styleSheet)) { |
|
| 8208 | + $this->_styleSheet=$this->getService()->getThemeManager()->getTheme($this->_styleSheet); |
|
| 8209 | + } |
|
| 7700 | 8210 | return $this->_styleSheet; |
| 7701 | 8211 | } |
| 7702 | 8212 | public function setStyleSheetTheme($value) |
@@ -7705,23 +8215,27 @@ discard block |
||
| 7705 | 8215 | } |
| 7706 | 8216 | public function applyControlSkin($control) |
| 7707 | 8217 | { |
| 7708 | - if(($theme=$this->getTheme())!==null) |
|
| 7709 | - $theme->applySkin($control); |
|
| 8218 | + if(($theme=$this->getTheme())!==null) { |
|
| 8219 | + $theme->applySkin($control); |
|
| 8220 | + } |
|
| 7710 | 8221 | } |
| 7711 | 8222 | public function applyControlStyleSheet($control) |
| 7712 | 8223 | { |
| 7713 | - if(($theme=$this->getStyleSheetTheme())!==null) |
|
| 7714 | - $theme->applySkin($control); |
|
| 8224 | + if(($theme=$this->getStyleSheetTheme())!==null) { |
|
| 8225 | + $theme->applySkin($control); |
|
| 8226 | + } |
|
| 7715 | 8227 | } |
| 7716 | 8228 | public function getClientScript() |
| 7717 | 8229 | { |
| 7718 | 8230 | if(!$this->_clientScript) { |
| 7719 | 8231 | $className = $classPath = $this->getService()->getClientScriptManagerClass(); |
| 7720 | 8232 | Prado::using($className); |
| 7721 | - if(($pos=strrpos($className,'.'))!==false) |
|
| 7722 | - $className=substr($className,$pos+1); |
|
| 7723 | - if(!class_exists($className,false) || ($className!=='TClientScriptManager' && !is_subclass_of($className,'TClientScriptManager'))) |
|
| 7724 | - throw new THttpException(404,'page_csmanagerclass_invalid',$classPath); |
|
| 8233 | + if(($pos=strrpos($className,'.'))!==false) { |
|
| 8234 | + $className=substr($className,$pos+1); |
|
| 8235 | + } |
|
| 8236 | + if(!class_exists($className,false) || ($className!=='TClientScriptManager' && !is_subclass_of($className,'TClientScriptManager'))) { |
|
| 8237 | + throw new THttpException(404,'page_csmanagerclass_invalid',$classPath); |
|
| 8238 | + } |
|
| 7725 | 8239 | $this->_clientScript=new $className($this); |
| 7726 | 8240 | } |
| 7727 | 8241 | return $this->_clientScript; |
@@ -7749,29 +8263,35 @@ discard block |
||
| 7749 | 8263 | $theme=$this->getTheme(); |
| 7750 | 8264 | if($theme instanceof ITheme) |
| 7751 | 8265 | { |
| 7752 | - foreach($theme->getStyleSheetFiles() as $url) |
|
| 7753 | - $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url)); |
|
| 7754 | - foreach($theme->getJavaScriptFiles() as $url) |
|
| 7755 | - $cs->registerHeadScriptFile($url,$url); |
|
| 8266 | + foreach($theme->getStyleSheetFiles() as $url) { |
|
| 8267 | + $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url)); |
|
| 8268 | + } |
|
| 8269 | + foreach($theme->getJavaScriptFiles() as $url) { |
|
| 8270 | + $cs->registerHeadScriptFile($url,$url); |
|
| 8271 | + } |
|
| 7756 | 8272 | } |
| 7757 | 8273 | $styleSheet=$this->getStyleSheetTheme(); |
| 7758 | 8274 | if($styleSheet instanceof ITheme) |
| 7759 | 8275 | { |
| 7760 | - foreach($styleSheet->getStyleSheetFiles() as $url) |
|
| 7761 | - $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url)); |
|
| 7762 | - foreach($styleSheet->getJavaScriptFiles() as $url) |
|
| 7763 | - $cs->registerHeadScriptFile($url,$url); |
|
| 8276 | + foreach($styleSheet->getStyleSheetFiles() as $url) { |
|
| 8277 | + $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url)); |
|
| 8278 | + } |
|
| 8279 | + foreach($styleSheet->getJavaScriptFiles() as $url) { |
|
| 8280 | + $cs->registerHeadScriptFile($url,$url); |
|
| 8281 | + } |
|
| 8282 | + } |
|
| 8283 | + if($cs->getRequiresHead() && $this->getHead()===null) { |
|
| 8284 | + throw new TConfigurationException('page_head_required'); |
|
| 7764 | 8285 | } |
| 7765 | - if($cs->getRequiresHead() && $this->getHead()===null) |
|
| 7766 | - throw new TConfigurationException('page_head_required'); |
|
| 7767 | 8286 | } |
| 7768 | 8287 | private function getCssMediaType($url) |
| 7769 | 8288 | { |
| 7770 | 8289 | $segs=explode('.',basename($url)); |
| 7771 | - if(isset($segs[2])) |
|
| 7772 | - return $segs[count($segs)-2]; |
|
| 7773 | - else |
|
| 7774 | - return ''; |
|
| 8290 | + if(isset($segs[2])) { |
|
| 8291 | + return $segs[count($segs)-2]; |
|
| 8292 | + } else { |
|
| 8293 | + return ''; |
|
| 8294 | + } |
|
| 7775 | 8295 | } |
| 7776 | 8296 | public function onSaveStateComplete($param) |
| 7777 | 8297 | { |
@@ -7780,8 +8300,9 @@ discard block |
||
| 7780 | 8300 | private function determinePostBackMode() |
| 7781 | 8301 | { |
| 7782 | 8302 | $postData=$this->getRequest(); |
| 7783 | - if($postData->contains(self::FIELD_PAGESTATE) || $postData->contains(self::FIELD_POSTBACK_TARGET)) |
|
| 7784 | - $this->_postData=$postData; |
|
| 8303 | + if($postData->contains(self::FIELD_PAGESTATE) || $postData->contains(self::FIELD_POSTBACK_TARGET)) { |
|
| 8304 | + $this->_postData=$postData; |
|
| 8305 | + } |
|
| 7785 | 8306 | } |
| 7786 | 8307 | public function getIsPostBack() |
| 7787 | 8308 | { |
@@ -7820,16 +8341,18 @@ discard block |
||
| 7820 | 8341 | $id=is_string($control)?$control:$control->getUniqueID(); |
| 7821 | 8342 | $this->_controlsRegisteredForPostData[$id]=true; |
| 7822 | 8343 | $params=func_get_args(); |
| 7823 | - foreach($this->getCachingStack() as $item) |
|
| 7824 | - $item->registerAction('Page','registerRequiresPostData',array($id)); |
|
| 8344 | + foreach($this->getCachingStack() as $item) { |
|
| 8345 | + $item->registerAction('Page','registerRequiresPostData',array($id)); |
|
| 8346 | + } |
|
| 7825 | 8347 | } |
| 7826 | 8348 | public function getPostBackEventTarget() |
| 7827 | 8349 | { |
| 7828 | 8350 | if($this->_postBackEventTarget===null && $this->_postData!==null) |
| 7829 | 8351 | { |
| 7830 | 8352 | $eventTarget=$this->_postData->itemAt(self::FIELD_POSTBACK_TARGET); |
| 7831 | - if(!empty($eventTarget)) |
|
| 7832 | - $this->_postBackEventTarget=$this->findControl($eventTarget); |
|
| 8353 | + if(!empty($eventTarget)) { |
|
| 8354 | + $this->_postBackEventTarget=$this->findControl($eventTarget); |
|
| 8355 | + } |
|
| 7833 | 8356 | } |
| 7834 | 8357 | return $this->_postBackEventTarget; |
| 7835 | 8358 | } |
@@ -7841,8 +8364,9 @@ discard block |
||
| 7841 | 8364 | { |
| 7842 | 8365 | if($this->_postBackEventParameter===null && $this->_postData!==null) |
| 7843 | 8366 | { |
| 7844 | - if(($this->_postBackEventParameter=$this->_postData->itemAt(self::FIELD_POSTBACK_PARAMETER))===null) |
|
| 7845 | - $this->_postBackEventParameter=''; |
|
| 8367 | + if(($this->_postBackEventParameter=$this->_postData->itemAt(self::FIELD_POSTBACK_PARAMETER))===null) { |
|
| 8368 | + $this->_postBackEventParameter=''; |
|
| 8369 | + } |
|
| 7846 | 8370 | } |
| 7847 | 8371 | return $this->_postBackEventParameter; |
| 7848 | 8372 | } |
@@ -7853,27 +8377,28 @@ discard block |
||
| 7853 | 8377 | protected function processPostData($postData,$beforeLoad) |
| 7854 | 8378 | { |
| 7855 | 8379 | $this->_isLoadingPostData=true; |
| 7856 | - if($beforeLoad) |
|
| 7857 | - $this->_restPostData=new TMap; |
|
| 8380 | + if($beforeLoad) { |
|
| 8381 | + $this->_restPostData=new TMap; |
|
| 8382 | + } |
|
| 7858 | 8383 | foreach($postData as $key=>$value) |
| 7859 | 8384 | { |
| 7860 | - if($this->isSystemPostField($key)) |
|
| 7861 | - continue; |
|
| 7862 | - else if($control=$this->findControl($key)) |
|
| 8385 | + if($this->isSystemPostField($key)) { |
|
| 8386 | + continue; |
|
| 8387 | + } else if($control=$this->findControl($key)) |
|
| 7863 | 8388 | { |
| 7864 | 8389 | if($control instanceof IPostBackDataHandler) |
| 7865 | 8390 | { |
| 7866 | - if($control->loadPostData($key,$postData)) |
|
| 7867 | - $this->_controlsPostDataChanged[]=$control; |
|
| 7868 | - } |
|
| 7869 | - else if($control instanceof IPostBackEventHandler && |
|
| 8391 | + if($control->loadPostData($key,$postData)) { |
|
| 8392 | + $this->_controlsPostDataChanged[]=$control; |
|
| 8393 | + } |
|
| 8394 | + } else if($control instanceof IPostBackEventHandler && |
|
| 7870 | 8395 | empty($this->_postData[self::FIELD_POSTBACK_TARGET])) |
| 7871 | 8396 | { |
| 7872 | 8397 | $this->_postData->add(self::FIELD_POSTBACK_TARGET,$key); } |
| 7873 | 8398 | unset($this->_controlsRequiringPostData[$key]); |
| 8399 | + } else if($beforeLoad) { |
|
| 8400 | + $this->_restPostData->add($key,$value); |
|
| 7874 | 8401 | } |
| 7875 | - else if($beforeLoad) |
|
| 7876 | - $this->_restPostData->add($key,$value); |
|
| 7877 | 8402 | } |
| 7878 | 8403 | foreach($this->_controlsRequiringPostData as $key=>$value) |
| 7879 | 8404 | { |
@@ -7881,11 +8406,12 @@ discard block |
||
| 7881 | 8406 | { |
| 7882 | 8407 | if($control instanceof IPostBackDataHandler) |
| 7883 | 8408 | { |
| 7884 | - if($control->loadPostData($key,$this->_postData)) |
|
| 7885 | - $this->_controlsPostDataChanged[]=$control; |
|
| 8409 | + if($control->loadPostData($key,$this->_postData)) { |
|
| 8410 | + $this->_controlsPostDataChanged[]=$control; |
|
| 8411 | + } |
|
| 8412 | + } else { |
|
| 8413 | + throw new TInvalidDataValueException('page_postbackcontrol_invalid',$key); |
|
| 7886 | 8414 | } |
| 7887 | - else |
|
| 7888 | - throw new TInvalidDataValueException('page_postbackcontrol_invalid',$key); |
|
| 7889 | 8415 | unset($this->_controlsRequiringPostData[$key]); |
| 7890 | 8416 | } |
| 7891 | 8417 | } |
@@ -7897,15 +8423,17 @@ discard block |
||
| 7897 | 8423 | } |
| 7898 | 8424 | protected function raiseChangedEvents() |
| 7899 | 8425 | { |
| 7900 | - foreach($this->_controlsPostDataChanged as $control) |
|
| 7901 | - $control->raisePostDataChangedEvent(); |
|
| 8426 | + foreach($this->_controlsPostDataChanged as $control) { |
|
| 8427 | + $control->raisePostDataChangedEvent(); |
|
| 8428 | + } |
|
| 7902 | 8429 | } |
| 7903 | 8430 | protected function raisePostBackEvent() |
| 7904 | 8431 | { |
| 7905 | - if(($postBackHandler=$this->getPostBackEventTarget())===null) |
|
| 7906 | - $this->validate(); |
|
| 7907 | - else if($postBackHandler instanceof IPostBackEventHandler) |
|
| 7908 | - $postBackHandler->raisePostBackEvent($this->getPostBackEventParameter()); |
|
| 8432 | + if(($postBackHandler=$this->getPostBackEventTarget())===null) { |
|
| 8433 | + $this->validate(); |
|
| 8434 | + } else if($postBackHandler instanceof IPostBackEventHandler) { |
|
| 8435 | + $postBackHandler->raisePostBackEvent($this->getPostBackEventParameter()); |
|
| 8436 | + } |
|
| 7909 | 8437 | } |
| 7910 | 8438 | public function getInFormRender() |
| 7911 | 8439 | { |
@@ -7913,13 +8441,15 @@ discard block |
||
| 7913 | 8441 | } |
| 7914 | 8442 | public function ensureRenderInForm($control) |
| 7915 | 8443 | { |
| 7916 | - if(!$this->getIsCallback() && !$this->_inFormRender) |
|
| 7917 | - throw new TConfigurationException('page_control_outofform',get_class($control), $control ? $control->getUniqueID() : null); |
|
| 8444 | + if(!$this->getIsCallback() && !$this->_inFormRender) { |
|
| 8445 | + throw new TConfigurationException('page_control_outofform',get_class($control), $control ? $control->getUniqueID() : null); |
|
| 8446 | + } |
|
| 7918 | 8447 | } |
| 7919 | 8448 | public function beginFormRender($writer) |
| 7920 | 8449 | { |
| 7921 | - if($this->_formRendered) |
|
| 7922 | - throw new TConfigurationException('page_form_duplicated'); |
|
| 8450 | + if($this->_formRendered) { |
|
| 8451 | + throw new TConfigurationException('page_form_duplicated'); |
|
| 8452 | + } |
|
| 7923 | 8453 | $this->_formRendered=true; |
| 7924 | 8454 | $this->getClientScript()->registerHiddenField(self::FIELD_PAGESTATE,$this->getClientState()); |
| 7925 | 8455 | $this->_inFormRender=true; |
@@ -7928,14 +8458,15 @@ discard block |
||
| 7928 | 8458 | { |
| 7929 | 8459 | if($this->_focus) |
| 7930 | 8460 | { |
| 7931 | - if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true)) |
|
| 7932 | - $focus=$this->_focus->getClientID(); |
|
| 7933 | - else |
|
| 7934 | - $focus=$this->_focus; |
|
| 8461 | + if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true)) { |
|
| 8462 | + $focus=$this->_focus->getClientID(); |
|
| 8463 | + } else { |
|
| 8464 | + $focus=$this->_focus; |
|
| 8465 | + } |
|
| 7935 | 8466 | $this->getClientScript()->registerFocusControl($focus); |
| 8467 | + } else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null) { |
|
| 8468 | + $this->getClientScript()->registerFocusControl($lastFocus); |
|
| 7936 | 8469 | } |
| 7937 | - else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null) |
|
| 7938 | - $this->getClientScript()->registerFocusControl($lastFocus); |
|
| 7939 | 8470 | $this->_inFormRender=false; |
| 7940 | 8471 | } |
| 7941 | 8472 | public function setFocus($value) |
@@ -7956,8 +8487,9 @@ discard block |
||
| 7956 | 8487 | } |
| 7957 | 8488 | public function setHead(THead $value) |
| 7958 | 8489 | { |
| 7959 | - if($this->_head) |
|
| 7960 | - throw new TInvalidOperationException('page_head_duplicated'); |
|
| 8490 | + if($this->_head) { |
|
| 8491 | + throw new TInvalidOperationException('page_head_duplicated'); |
|
| 8492 | + } |
|
| 7961 | 8493 | $this->_head=$value; |
| 7962 | 8494 | if($this->_title!==null) |
| 7963 | 8495 | { |
@@ -7967,17 +8499,19 @@ discard block |
||
| 7967 | 8499 | } |
| 7968 | 8500 | public function getTitle() |
| 7969 | 8501 | { |
| 7970 | - if($this->_head) |
|
| 7971 | - return $this->_head->getTitle(); |
|
| 7972 | - else |
|
| 7973 | - return $this->_title===null ? '' : $this->_title; |
|
| 8502 | + if($this->_head) { |
|
| 8503 | + return $this->_head->getTitle(); |
|
| 8504 | + } else { |
|
| 8505 | + return $this->_title===null ? '' : $this->_title; |
|
| 8506 | + } |
|
| 7974 | 8507 | } |
| 7975 | 8508 | public function setTitle($value) |
| 7976 | 8509 | { |
| 7977 | - if($this->_head) |
|
| 7978 | - $this->_head->setTitle($value); |
|
| 7979 | - else |
|
| 7980 | - $this->_title=$value; |
|
| 8510 | + if($this->_head) { |
|
| 8511 | + $this->_head->setTitle($value); |
|
| 8512 | + } else { |
|
| 8513 | + $this->_title=$value; |
|
| 8514 | + } |
|
| 7981 | 8515 | } |
| 7982 | 8516 | public function getClientState() |
| 7983 | 8517 | { |
@@ -8004,8 +8538,9 @@ discard block |
||
| 8004 | 8538 | if($this->_statePersister===null) |
| 8005 | 8539 | { |
| 8006 | 8540 | $this->_statePersister=Prado::createComponent($this->_statePersisterClass); |
| 8007 | - if(!($this->_statePersister instanceof IPageStatePersister)) |
|
| 8008 | - throw new TInvalidDataTypeException('page_statepersister_invalid'); |
|
| 8541 | + if(!($this->_statePersister instanceof IPageStatePersister)) { |
|
| 8542 | + throw new TInvalidDataTypeException('page_statepersister_invalid'); |
|
| 8543 | + } |
|
| 8009 | 8544 | $this->_statePersister->setPage($this); |
| 8010 | 8545 | } |
| 8011 | 8546 | return $this->_statePersister; |
@@ -8046,20 +8581,23 @@ discard block |
||
| 8046 | 8581 | { |
| 8047 | 8582 | if($this->_cachingStack) |
| 8048 | 8583 | { |
| 8049 | - foreach($this->_cachingStack as $cache) |
|
| 8050 | - $cache->registerAction($context,$funcName,$funcParams); |
|
| 8584 | + foreach($this->_cachingStack as $cache) { |
|
| 8585 | + $cache->registerAction($context,$funcName,$funcParams); |
|
| 8586 | + } |
|
| 8051 | 8587 | } |
| 8052 | 8588 | } |
| 8053 | 8589 | public function getCachingStack() |
| 8054 | 8590 | { |
| 8055 | - if(!$this->_cachingStack) |
|
| 8056 | - $this->_cachingStack=new TStack; |
|
| 8591 | + if(!$this->_cachingStack) { |
|
| 8592 | + $this->_cachingStack=new TStack; |
|
| 8593 | + } |
|
| 8057 | 8594 | return $this->_cachingStack; |
| 8058 | 8595 | } |
| 8059 | 8596 | public function flushWriter() |
| 8060 | 8597 | { |
| 8061 | - if ($this->_writer) |
|
| 8062 | - $this->Response->write($this->_writer->flush()); |
|
| 8598 | + if ($this->_writer) { |
|
| 8599 | + $this->Response->write($this->_writer->flush()); |
|
| 8600 | + } |
|
| 8063 | 8601 | } |
| 8064 | 8602 | } |
| 8065 | 8603 | interface IPageStatePersister |
@@ -8074,35 +8612,42 @@ discard block |
||
| 8074 | 8612 | public static function serialize($page,$data) |
| 8075 | 8613 | { |
| 8076 | 8614 | $sm=$page->getApplication()->getSecurityManager(); |
| 8077 | - if($page->getEnableStateValidation()) |
|
| 8078 | - $str=$sm->hashData(serialize($data)); |
|
| 8079 | - else |
|
| 8080 | - $str=serialize($data); |
|
| 8081 | - if($page->getEnableStateCompression() && extension_loaded('zlib')) |
|
| 8082 | - $str=gzcompress($str); |
|
| 8083 | - if($page->getEnableStateEncryption()) |
|
| 8084 | - $str=$sm->encrypt($str); |
|
| 8615 | + if($page->getEnableStateValidation()) { |
|
| 8616 | + $str=$sm->hashData(serialize($data)); |
|
| 8617 | + } else { |
|
| 8618 | + $str=serialize($data); |
|
| 8619 | + } |
|
| 8620 | + if($page->getEnableStateCompression() && extension_loaded('zlib')) { |
|
| 8621 | + $str=gzcompress($str); |
|
| 8622 | + } |
|
| 8623 | + if($page->getEnableStateEncryption()) { |
|
| 8624 | + $str=$sm->encrypt($str); |
|
| 8625 | + } |
|
| 8085 | 8626 | return base64_encode($str); |
| 8086 | 8627 | } |
| 8087 | 8628 | public static function unserialize($page,$data) |
| 8088 | 8629 | { |
| 8089 | 8630 | $str=base64_decode($data); |
| 8090 | - if($str==='') |
|
| 8091 | - return null; |
|
| 8631 | + if($str==='') { |
|
| 8632 | + return null; |
|
| 8633 | + } |
|
| 8092 | 8634 | if($str!==false) |
| 8093 | 8635 | { |
| 8094 | 8636 | $sm=$page->getApplication()->getSecurityManager(); |
| 8095 | - if($page->getEnableStateEncryption()) |
|
| 8096 | - $str=$sm->decrypt($str); |
|
| 8097 | - if($page->getEnableStateCompression() && extension_loaded('zlib')) |
|
| 8098 | - $str=@gzuncompress($str); |
|
| 8637 | + if($page->getEnableStateEncryption()) { |
|
| 8638 | + $str=$sm->decrypt($str); |
|
| 8639 | + } |
|
| 8640 | + if($page->getEnableStateCompression() && extension_loaded('zlib')) { |
|
| 8641 | + $str=@gzuncompress($str); |
|
| 8642 | + } |
|
| 8099 | 8643 | if($page->getEnableStateValidation()) |
| 8100 | 8644 | { |
| 8101 | - if(($str=$sm->validateData($str))!==false) |
|
| 8102 | - return unserialize($str); |
|
| 8645 | + if(($str=$sm->validateData($str))!==false) { |
|
| 8646 | + return unserialize($str); |
|
| 8647 | + } |
|
| 8648 | + } else { |
|
| 8649 | + return unserialize($str); |
|
| 8103 | 8650 | } |
| 8104 | - else |
|
| 8105 | - return unserialize($str); |
|
| 8106 | 8651 | } |
| 8107 | 8652 | return null; |
| 8108 | 8653 | } |
@@ -8140,11 +8685,12 @@ discard block |
||
| 8140 | 8685 | if($this->_cacheModuleID!=='') |
| 8141 | 8686 | { |
| 8142 | 8687 | $this->_cache=$this->getApplication()->getModule($this->_cacheModuleID); |
| 8143 | - if(!($this->_cache instanceof ICache)) |
|
| 8144 | - throw new TConfigurationException('outputcache_cachemoduleid_invalid',$this->_cacheModuleID); |
|
| 8688 | + if(!($this->_cache instanceof ICache)) { |
|
| 8689 | + throw new TConfigurationException('outputcache_cachemoduleid_invalid',$this->_cacheModuleID); |
|
| 8690 | + } |
|
| 8691 | + } else { |
|
| 8692 | + $this->_cache=$this->getApplication()->getCache(); |
|
| 8145 | 8693 | } |
| 8146 | - else |
|
| 8147 | - $this->_cache=$this->getApplication()->getCache(); |
|
| 8148 | 8694 | if($this->_cache!==null) |
| 8149 | 8695 | { |
| 8150 | 8696 | $this->_cacheAvailable=true; |
@@ -8155,11 +8701,12 @@ discard block |
||
| 8155 | 8701 | $param->setCacheTime(isset($data[3])?$data[3]:0); |
| 8156 | 8702 | $this->onCheckDependency($param); |
| 8157 | 8703 | $this->_dataCached=$param->getIsValid(); |
| 8704 | + } else { |
|
| 8705 | + $this->_dataCached=false; |
|
| 8706 | + } |
|
| 8707 | + if($this->_dataCached) { |
|
| 8708 | + list($this->_contents,$this->_state,$this->_actions,$this->_cacheTime)=$data; |
|
| 8158 | 8709 | } |
| 8159 | - else |
|
| 8160 | - $this->_dataCached=false; |
|
| 8161 | - if($this->_dataCached) |
|
| 8162 | - list($this->_contents,$this->_state,$this->_actions,$this->_cacheTime)=$data; |
|
| 8163 | 8710 | } |
| 8164 | 8711 | } |
| 8165 | 8712 | } |
@@ -8172,9 +8719,9 @@ discard block |
||
| 8172 | 8719 | $stack->push($this); |
| 8173 | 8720 | parent::initRecursive($namingContainer); |
| 8174 | 8721 | $stack->pop(); |
| 8722 | + } else { |
|
| 8723 | + parent::initRecursive($namingContainer); |
|
| 8175 | 8724 | } |
| 8176 | - else |
|
| 8177 | - parent::initRecursive($namingContainer); |
|
| 8178 | 8725 | } |
| 8179 | 8726 | protected function loadRecursive() |
| 8180 | 8727 | { |
@@ -8184,11 +8731,11 @@ discard block |
||
| 8184 | 8731 | $stack->push($this); |
| 8185 | 8732 | parent::loadRecursive(); |
| 8186 | 8733 | $stack->pop(); |
| 8187 | - } |
|
| 8188 | - else |
|
| 8734 | + } else |
|
| 8189 | 8735 | { |
| 8190 | - if($this->_dataCached) |
|
| 8191 | - $this->performActions(); |
|
| 8736 | + if($this->_dataCached) { |
|
| 8737 | + $this->performActions(); |
|
| 8738 | + } |
|
| 8192 | 8739 | parent::loadRecursive(); |
| 8193 | 8740 | } |
| 8194 | 8741 | } |
@@ -8198,12 +8745,13 @@ discard block |
||
| 8198 | 8745 | $cs=$page->getClientScript(); |
| 8199 | 8746 | foreach($this->_actions as $action) |
| 8200 | 8747 | { |
| 8201 | - if($action[0]==='Page.ClientScript') |
|
| 8202 | - call_user_func_array(array($cs,$action[1]),$action[2]); |
|
| 8203 | - else if($action[0]==='Page') |
|
| 8204 | - call_user_func_array(array($page,$action[1]),$action[2]); |
|
| 8205 | - else |
|
| 8206 | - call_user_func_array(array($this->getSubProperty($action[0]),$action[1]),$action[2]); |
|
| 8748 | + if($action[0]==='Page.ClientScript') { |
|
| 8749 | + call_user_func_array(array($cs,$action[1]),$action[2]); |
|
| 8750 | + } else if($action[0]==='Page') { |
|
| 8751 | + call_user_func_array(array($page,$action[1]),$action[2]); |
|
| 8752 | + } else { |
|
| 8753 | + call_user_func_array(array($this->getSubProperty($action[0]),$action[1]),$action[2]); |
|
| 8754 | + } |
|
| 8207 | 8755 | } |
| 8208 | 8756 | } |
| 8209 | 8757 | protected function preRenderRecursive() |
@@ -8214,9 +8762,9 @@ discard block |
||
| 8214 | 8762 | $stack->push($this); |
| 8215 | 8763 | parent::preRenderRecursive(); |
| 8216 | 8764 | $stack->pop(); |
| 8765 | + } else { |
|
| 8766 | + parent::preRenderRecursive(); |
|
| 8217 | 8767 | } |
| 8218 | - else |
|
| 8219 | - parent::preRenderRecursive(); |
|
| 8220 | 8768 | } |
| 8221 | 8769 | protected function loadStateRecursive(&$state,$needViewState=true) |
| 8222 | 8770 | { |
@@ -8225,9 +8773,9 @@ discard block |
||
| 8225 | 8773 | } |
| 8226 | 8774 | protected function &saveStateRecursive($needViewState=true) |
| 8227 | 8775 | { |
| 8228 | - if($this->_dataCached) |
|
| 8229 | - return $this->_state; |
|
| 8230 | - else |
|
| 8776 | + if($this->_dataCached) { |
|
| 8777 | + return $this->_state; |
|
| 8778 | + } else |
|
| 8231 | 8779 | { |
| 8232 | 8780 | $st=parent::saveStateRecursive($needViewState); |
| 8233 | 8781 | $this->_state=serialize($st); |
@@ -8240,15 +8788,17 @@ discard block |
||
| 8240 | 8788 | } |
| 8241 | 8789 | public function getCacheKey() |
| 8242 | 8790 | { |
| 8243 | - if($this->_cacheKey===null) |
|
| 8244 | - $this->_cacheKey=$this->calculateCacheKey(); |
|
| 8791 | + if($this->_cacheKey===null) { |
|
| 8792 | + $this->_cacheKey=$this->calculateCacheKey(); |
|
| 8793 | + } |
|
| 8245 | 8794 | return $this->_cacheKey; |
| 8246 | 8795 | } |
| 8247 | 8796 | protected function calculateCacheKey() |
| 8248 | 8797 | { |
| 8249 | 8798 | $key=$this->getBaseCacheKey(); |
| 8250 | - if($this->_varyBySession) |
|
| 8251 | - $key.=$this->getSession()->getSessionID(); |
|
| 8799 | + if($this->_varyBySession) { |
|
| 8800 | + $key.=$this->getSession()->getSessionID(); |
|
| 8801 | + } |
|
| 8252 | 8802 | if($this->_varyByParam!=='') |
| 8253 | 8803 | { |
| 8254 | 8804 | $params=array(); |
@@ -8299,8 +8849,9 @@ discard block |
||
| 8299 | 8849 | } |
| 8300 | 8850 | public function setDuration($value) |
| 8301 | 8851 | { |
| 8302 | - if(($value=TPropertyValue::ensureInteger($value))<0) |
|
| 8303 | - throw new TInvalidDataValueException('outputcache_duration_invalid',get_class($this)); |
|
| 8852 | + if(($value=TPropertyValue::ensureInteger($value))<0) { |
|
| 8853 | + throw new TInvalidDataValueException('outputcache_duration_invalid',get_class($this)); |
|
| 8854 | + } |
|
| 8304 | 8855 | $this->_duration=$value; |
| 8305 | 8856 | } |
| 8306 | 8857 | public function getVaryByParam() |
@@ -8337,9 +8888,9 @@ discard block |
||
| 8337 | 8888 | } |
| 8338 | 8889 | public function render($writer) |
| 8339 | 8890 | { |
| 8340 | - if($this->_dataCached) |
|
| 8341 | - $writer->write($this->_contents); |
|
| 8342 | - else if($this->_cacheAvailable) |
|
| 8891 | + if($this->_dataCached) { |
|
| 8892 | + $writer->write($this->_contents); |
|
| 8893 | + } else if($this->_cacheAvailable) |
|
| 8343 | 8894 | { |
| 8344 | 8895 | $textwriter = new TTextWriter(); |
| 8345 | 8896 | $multiwriter = new TOutputCacheTextWriterMulti(array($writer->getWriter(),$textwriter)); |
@@ -8351,9 +8902,9 @@ discard block |
||
| 8351 | 8902 | $content=$textwriter->flush(); |
| 8352 | 8903 | $data=array($content,$this->_state,$this->_actions,time()); |
| 8353 | 8904 | $this->_cache->set($this->getCacheKey(),$data,$this->getDuration(),$this->getCacheDependency()); |
| 8905 | + } else { |
|
| 8906 | + parent::render($writer); |
|
| 8354 | 8907 | } |
| 8355 | - else |
|
| 8356 | - parent::render($writer); |
|
| 8357 | 8908 | } |
| 8358 | 8909 | } |
| 8359 | 8910 | class TOutputCacheCheckDependencyEventParameter extends TEventParameter |
@@ -8398,13 +8949,15 @@ discard block |
||
| 8398 | 8949 | } |
| 8399 | 8950 | public function write($s) |
| 8400 | 8951 | { |
| 8401 | - foreach($this->_writers as $writer) |
|
| 8402 | - $writer->write($s); |
|
| 8952 | + foreach($this->_writers as $writer) { |
|
| 8953 | + $writer->write($s); |
|
| 8954 | + } |
|
| 8403 | 8955 | } |
| 8404 | 8956 | public function flush() |
| 8405 | 8957 | { |
| 8406 | - foreach($this->_writers as $writer) |
|
| 8407 | - $s = $writer->flush(); |
|
| 8958 | + foreach($this->_writers as $writer) { |
|
| 8959 | + $s = $writer->flush(); |
|
| 8960 | + } |
|
| 8408 | 8961 | return $s; |
| 8409 | 8962 | } |
| 8410 | 8963 | } |
@@ -8426,16 +8979,17 @@ discard block |
||
| 8426 | 8979 | { |
| 8427 | 8980 | if(($fileName=$this->getLocalizedTemplate($fileName))!==null) |
| 8428 | 8981 | { |
| 8429 | - if(($cache=$this->getApplication()->getCache())===null) |
|
| 8430 | - return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName); |
|
| 8431 | - else |
|
| 8982 | + if(($cache=$this->getApplication()->getCache())===null) { |
|
| 8983 | + return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName); |
|
| 8984 | + } else |
|
| 8432 | 8985 | { |
| 8433 | 8986 | $array=$cache->get(self::TEMPLATE_CACHE_PREFIX.$fileName); |
| 8434 | 8987 | if(is_array($array)) |
| 8435 | 8988 | { |
| 8436 | 8989 | list($template,$timestamps)=$array; |
| 8437 | - if($this->getApplication()->getMode()===TApplicationMode::Performance) |
|
| 8438 | - return $template; |
|
| 8990 | + if($this->getApplication()->getMode()===TApplicationMode::Performance) { |
|
| 8991 | + return $template; |
|
| 8992 | + } |
|
| 8439 | 8993 | $cacheValid=true; |
| 8440 | 8994 | foreach($timestamps as $tplFile=>$timestamp) |
| 8441 | 8995 | { |
@@ -8445,30 +8999,34 @@ discard block |
||
| 8445 | 8999 | break; |
| 8446 | 9000 | } |
| 8447 | 9001 | } |
| 8448 | - if($cacheValid) |
|
| 8449 | - return $template; |
|
| 9002 | + if($cacheValid) { |
|
| 9003 | + return $template; |
|
| 9004 | + } |
|
| 8450 | 9005 | } |
| 8451 | 9006 | $template=new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName); |
| 8452 | 9007 | $includedFiles=$template->getIncludedFiles(); |
| 8453 | 9008 | $timestamps=array(); |
| 8454 | 9009 | $timestamps[$fileName]=filemtime($fileName); |
| 8455 | - foreach($includedFiles as $includedFile) |
|
| 8456 | - $timestamps[$includedFile]=filemtime($includedFile); |
|
| 9010 | + foreach($includedFiles as $includedFile) { |
|
| 9011 | + $timestamps[$includedFile]=filemtime($includedFile); |
|
| 9012 | + } |
|
| 8457 | 9013 | $cache->set(self::TEMPLATE_CACHE_PREFIX.$fileName,array($template,$timestamps)); |
| 8458 | 9014 | return $template; |
| 8459 | 9015 | } |
| 9016 | + } else { |
|
| 9017 | + return null; |
|
| 8460 | 9018 | } |
| 8461 | - else |
|
| 8462 | - return null; |
|
| 8463 | 9019 | } |
| 8464 | 9020 | protected function getLocalizedTemplate($filename) |
| 8465 | 9021 | { |
| 8466 | - if(($app=$this->getApplication()->getGlobalization(false))===null) |
|
| 8467 | - return is_file($filename)?$filename:null; |
|
| 9022 | + if(($app=$this->getApplication()->getGlobalization(false))===null) { |
|
| 9023 | + return is_file($filename)?$filename:null; |
|
| 9024 | + } |
|
| 8468 | 9025 | foreach($app->getLocalizedResource($filename) as $file) |
| 8469 | 9026 | { |
| 8470 | - if(($file=realpath($file))!==false && is_file($file)) |
|
| 8471 | - return $file; |
|
| 9027 | + if(($file=realpath($file))!==false && is_file($file)) { |
|
| 9028 | + return $file; |
|
| 9029 | + } |
|
| 8472 | 9030 | } |
| 8473 | 9031 | return null; |
| 8474 | 9032 | } |
@@ -8531,118 +9089,139 @@ discard block |
||
| 8531 | 9089 | public function instantiateIn($tplControl,$parentControl=null) |
| 8532 | 9090 | { |
| 8533 | 9091 | $this->_tplControl=$tplControl; |
| 8534 | - if($parentControl===null) |
|
| 8535 | - $parentControl=$tplControl; |
|
| 8536 | - if(($page=$tplControl->getPage())===null) |
|
| 8537 | - $page=$this->getService()->getRequestedPage(); |
|
| 9092 | + if($parentControl===null) { |
|
| 9093 | + $parentControl=$tplControl; |
|
| 9094 | + } |
|
| 9095 | + if(($page=$tplControl->getPage())===null) { |
|
| 9096 | + $page=$this->getService()->getRequestedPage(); |
|
| 9097 | + } |
|
| 8538 | 9098 | $controls=array(); |
| 8539 | 9099 | $directChildren=array(); |
| 8540 | 9100 | foreach($this->_tpl as $key=>$object) |
| 8541 | 9101 | { |
| 8542 | - if($object[0]===-1) |
|
| 8543 | - $parent=$parentControl; |
|
| 8544 | - else if(isset($controls[$object[0]])) |
|
| 8545 | - $parent=$controls[$object[0]]; |
|
| 8546 | - else |
|
| 8547 | - continue; |
|
| 9102 | + if($object[0]===-1) { |
|
| 9103 | + $parent=$parentControl; |
|
| 9104 | + } else if(isset($controls[$object[0]])) { |
|
| 9105 | + $parent=$controls[$object[0]]; |
|
| 9106 | + } else { |
|
| 9107 | + continue; |
|
| 9108 | + } |
|
| 8548 | 9109 | if(isset($object[2])) { |
| 8549 | 9110 | $component=Prado::createComponent($object[1]); |
| 8550 | 9111 | $properties=&$object[2]; |
| 8551 | 9112 | if($component instanceof TControl) |
| 8552 | 9113 | { |
| 8553 | - if($component instanceof TOutputCache) |
|
| 8554 | - $component->setCacheKeyPrefix($this->_hashCode.$key); |
|
| 9114 | + if($component instanceof TOutputCache) { |
|
| 9115 | + $component->setCacheKeyPrefix($this->_hashCode.$key); |
|
| 9116 | + } |
|
| 8555 | 9117 | $component->setTemplateControl($tplControl); |
| 8556 | 9118 | if(isset($properties['id'])) |
| 8557 | 9119 | { |
| 8558 | - if(is_array($properties['id'])) |
|
| 8559 | - $properties['id']=$component->evaluateExpression($properties['id'][1]); |
|
| 9120 | + if(is_array($properties['id'])) { |
|
| 9121 | + $properties['id']=$component->evaluateExpression($properties['id'][1]); |
|
| 9122 | + } |
|
| 8560 | 9123 | $tplControl->registerObject($properties['id'],$component); |
| 8561 | 9124 | } |
| 8562 | 9125 | if(isset($properties['skinid'])) |
| 8563 | 9126 | { |
| 8564 | - if(is_array($properties['skinid'])) |
|
| 8565 | - $component->setSkinID($component->evaluateExpression($properties['skinid'][1])); |
|
| 8566 | - else |
|
| 8567 | - $component->setSkinID($properties['skinid']); |
|
| 9127 | + if(is_array($properties['skinid'])) { |
|
| 9128 | + $component->setSkinID($component->evaluateExpression($properties['skinid'][1])); |
|
| 9129 | + } else { |
|
| 9130 | + $component->setSkinID($properties['skinid']); |
|
| 9131 | + } |
|
| 8568 | 9132 | unset($properties['skinid']); |
| 8569 | 9133 | } |
| 8570 | 9134 | $component->trackViewState(false); |
| 8571 | 9135 | $component->applyStyleSheetSkin($page); |
| 8572 | - foreach($properties as $name=>$value) |
|
| 8573 | - $this->configureControl($component,$name,$value); |
|
| 9136 | + foreach($properties as $name=>$value) { |
|
| 9137 | + $this->configureControl($component,$name,$value); |
|
| 9138 | + } |
|
| 8574 | 9139 | $component->trackViewState(true); |
| 8575 | - if($parent===$parentControl) |
|
| 8576 | - $directChildren[]=$component; |
|
| 8577 | - else |
|
| 8578 | - $component->createdOnTemplate($parent); |
|
| 8579 | - if($component->getAllowChildControls()) |
|
| 8580 | - $controls[$key]=$component; |
|
| 8581 | - } |
|
| 8582 | - else if($component instanceof TComponent) |
|
| 9140 | + if($parent===$parentControl) { |
|
| 9141 | + $directChildren[]=$component; |
|
| 9142 | + } else { |
|
| 9143 | + $component->createdOnTemplate($parent); |
|
| 9144 | + } |
|
| 9145 | + if($component->getAllowChildControls()) { |
|
| 9146 | + $controls[$key]=$component; |
|
| 9147 | + } |
|
| 9148 | + } else if($component instanceof TComponent) |
|
| 8583 | 9149 | { |
| 8584 | 9150 | $controls[$key]=$component; |
| 8585 | 9151 | if(isset($properties['id'])) |
| 8586 | 9152 | { |
| 8587 | - if(is_array($properties['id'])) |
|
| 8588 | - $properties['id']=$component->evaluateExpression($properties['id'][1]); |
|
| 9153 | + if(is_array($properties['id'])) { |
|
| 9154 | + $properties['id']=$component->evaluateExpression($properties['id'][1]); |
|
| 9155 | + } |
|
| 8589 | 9156 | $tplControl->registerObject($properties['id'],$component); |
| 8590 | - if(!$component->hasProperty('id')) |
|
| 8591 | - unset($properties['id']); |
|
| 9157 | + if(!$component->hasProperty('id')) { |
|
| 9158 | + unset($properties['id']); |
|
| 9159 | + } |
|
| 9160 | + } |
|
| 9161 | + foreach($properties as $name=>$value) { |
|
| 9162 | + $this->configureComponent($component,$name,$value); |
|
| 9163 | + } |
|
| 9164 | + if($parent===$parentControl) { |
|
| 9165 | + $directChildren[]=$component; |
|
| 9166 | + } else { |
|
| 9167 | + $component->createdOnTemplate($parent); |
|
| 8592 | 9168 | } |
| 8593 | - foreach($properties as $name=>$value) |
|
| 8594 | - $this->configureComponent($component,$name,$value); |
|
| 8595 | - if($parent===$parentControl) |
|
| 8596 | - $directChildren[]=$component; |
|
| 8597 | - else |
|
| 8598 | - $component->createdOnTemplate($parent); |
|
| 8599 | 9169 | } |
| 8600 | - } |
|
| 8601 | - else |
|
| 9170 | + } else |
|
| 8602 | 9171 | { |
| 8603 | 9172 | if($object[1] instanceof TCompositeLiteral) |
| 8604 | 9173 | { |
| 8605 | 9174 | $o=clone $object[1]; |
| 8606 | 9175 | $o->setContainer($tplControl); |
| 8607 | - if($parent===$parentControl) |
|
| 8608 | - $directChildren[]=$o; |
|
| 8609 | - else |
|
| 8610 | - $parent->addParsedObject($o); |
|
| 8611 | - } |
|
| 8612 | - else |
|
| 9176 | + if($parent===$parentControl) { |
|
| 9177 | + $directChildren[]=$o; |
|
| 9178 | + } else { |
|
| 9179 | + $parent->addParsedObject($o); |
|
| 9180 | + } |
|
| 9181 | + } else |
|
| 8613 | 9182 | { |
| 8614 | - if($parent===$parentControl) |
|
| 8615 | - $directChildren[]=$object[1]; |
|
| 8616 | - else |
|
| 8617 | - $parent->addParsedObject($object[1]); |
|
| 9183 | + if($parent===$parentControl) { |
|
| 9184 | + $directChildren[]=$object[1]; |
|
| 9185 | + } else { |
|
| 9186 | + $parent->addParsedObject($object[1]); |
|
| 9187 | + } |
|
| 8618 | 9188 | } |
| 8619 | 9189 | } |
| 8620 | 9190 | } |
| 8621 | 9191 | foreach($directChildren as $control) |
| 8622 | 9192 | { |
| 8623 | - if($control instanceof TComponent) |
|
| 8624 | - $control->createdOnTemplate($parentControl); |
|
| 8625 | - else |
|
| 8626 | - $parentControl->addParsedObject($control); |
|
| 9193 | + if($control instanceof TComponent) { |
|
| 9194 | + $control->createdOnTemplate($parentControl); |
|
| 9195 | + } else { |
|
| 9196 | + $parentControl->addParsedObject($control); |
|
| 9197 | + } |
|
| 8627 | 9198 | } |
| 8628 | 9199 | } |
| 8629 | 9200 | protected function configureControl($control,$name,$value) |
| 8630 | 9201 | { |
| 8631 | - if(strncasecmp($name,'on',2)===0) $this->configureEvent($control,$name,$value,$control); |
|
| 8632 | - else if(($pos=strrpos($name,'.'))===false) $this->configureProperty($control,$name,$value); |
|
| 8633 | - else $this->configureSubProperty($control,$name,$value); |
|
| 9202 | + if(strncasecmp($name,'on',2)===0) { |
|
| 9203 | + $this->configureEvent($control,$name,$value,$control); |
|
| 9204 | + } else if(($pos=strrpos($name,'.'))===false) { |
|
| 9205 | + $this->configureProperty($control,$name,$value); |
|
| 9206 | + } else { |
|
| 9207 | + $this->configureSubProperty($control,$name,$value); |
|
| 9208 | + } |
|
| 8634 | 9209 | } |
| 8635 | 9210 | protected function configureComponent($component,$name,$value) |
| 8636 | 9211 | { |
| 8637 | - if(strpos($name,'.')===false) $this->configureProperty($component,$name,$value); |
|
| 8638 | - else $this->configureSubProperty($component,$name,$value); |
|
| 9212 | + if(strpos($name,'.')===false) { |
|
| 9213 | + $this->configureProperty($component,$name,$value); |
|
| 9214 | + } else { |
|
| 9215 | + $this->configureSubProperty($component,$name,$value); |
|
| 9216 | + } |
|
| 8639 | 9217 | } |
| 8640 | 9218 | protected function configureEvent($control,$name,$value,$contextControl) |
| 8641 | 9219 | { |
| 8642 | - if(strpos($value,'.')===false) |
|
| 8643 | - $control->attachEventHandler($name,array($contextControl,'TemplateControl.'.$value)); |
|
| 8644 | - else |
|
| 8645 | - $control->attachEventHandler($name,array($contextControl,$value)); |
|
| 9220 | + if(strpos($value,'.')===false) { |
|
| 9221 | + $control->attachEventHandler($name,array($contextControl,'TemplateControl.'.$value)); |
|
| 9222 | + } else { |
|
| 9223 | + $control->attachEventHandler($name,array($contextControl,$value)); |
|
| 9224 | + } |
|
| 8646 | 9225 | } |
| 8647 | 9226 | protected function configureProperty($component,$name,$value) |
| 8648 | 9227 | { |
@@ -8654,9 +9233,9 @@ discard block |
||
| 8654 | 9233 | $component->bindProperty($name,$value[1]); |
| 8655 | 9234 | break; |
| 8656 | 9235 | case self::CONFIG_EXPRESSION: |
| 8657 | - if($component instanceof TControl) |
|
| 8658 | - $component->autoBindProperty($name,$value[1]); |
|
| 8659 | - else |
|
| 9236 | + if($component instanceof TControl) { |
|
| 9237 | + $component->autoBindProperty($name,$value[1]); |
|
| 9238 | + } else |
|
| 8660 | 9239 | { |
| 8661 | 9240 | $setter='set'.$name; |
| 8662 | 9241 | $component->$setter($this->_tplControl->evaluateExpression($value[1])); |
@@ -8680,12 +9259,12 @@ discard block |
||
| 8680 | 9259 | default: throw new TConfigurationException('template_tag_unexpected',$name,$value[1]); |
| 8681 | 9260 | break; |
| 8682 | 9261 | } |
| 8683 | - } |
|
| 8684 | - else |
|
| 9262 | + } else |
|
| 8685 | 9263 | { |
| 8686 | - if (substr($name,0,2)=='js') |
|
| 8687 | - if ($value and !($value instanceof TJavaScriptLiteral)) |
|
| 9264 | + if (substr($name,0,2)=='js') { |
|
| 9265 | + if ($value and !($value instanceof TJavaScriptLiteral)) |
|
| 8688 | 9266 | $value = new TJavaScriptLiteral($value); |
| 9267 | + } |
|
| 8689 | 9268 | $setter='set'.$name; |
| 8690 | 9269 | $component->$setter($value); |
| 8691 | 9270 | } |
@@ -8698,10 +9277,11 @@ discard block |
||
| 8698 | 9277 | { |
| 8699 | 9278 | case self::CONFIG_DATABIND: $component->bindProperty($name,$value[1]); |
| 8700 | 9279 | break; |
| 8701 | - case self::CONFIG_EXPRESSION: if($component instanceof TControl) |
|
| 8702 | - $component->autoBindProperty($name,$value[1]); |
|
| 8703 | - else |
|
| 8704 | - $component->setSubProperty($name,$this->_tplControl->evaluateExpression($value[1])); |
|
| 9280 | + case self::CONFIG_EXPRESSION: if($component instanceof TControl) { |
|
| 9281 | + $component->autoBindProperty($name,$value[1]); |
|
| 9282 | + } else { |
|
| 9283 | + $component->setSubProperty($name,$this->_tplControl->evaluateExpression($value[1])); |
|
| 9284 | + } |
|
| 8705 | 9285 | break; |
| 8706 | 9286 | case self::CONFIG_TEMPLATE: |
| 8707 | 9287 | $component->setSubProperty($name,$value[1]); |
@@ -8717,9 +9297,9 @@ discard block |
||
| 8717 | 9297 | default: throw new TConfigurationException('template_tag_unexpected',$name,$value[1]); |
| 8718 | 9298 | break; |
| 8719 | 9299 | } |
| 9300 | + } else { |
|
| 9301 | + $component->setSubProperty($name,$value); |
|
| 8720 | 9302 | } |
| 8721 | - else |
|
| 8722 | - $component->setSubProperty($name,$value); |
|
| 8723 | 9303 | } |
| 8724 | 9304 | protected function parse($input) |
| 8725 | 9305 | { |
@@ -8742,10 +9322,12 @@ discard block |
||
| 8742 | 9322 | $matchStart=$match[0][1]; |
| 8743 | 9323 | $matchEnd=$matchStart+strlen($str)-1; |
| 8744 | 9324 | if(strpos($str,'<com:')===0) { |
| 8745 | - if($expectPropEnd) |
|
| 8746 | - continue; |
|
| 8747 | - if($matchStart>$textStart) |
|
| 8748 | - $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9325 | + if($expectPropEnd) { |
|
| 9326 | + continue; |
|
| 9327 | + } |
|
| 9328 | + if($matchStart>$textStart) { |
|
| 9329 | + $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9330 | + } |
|
| 8749 | 9331 | $textStart=$matchEnd+1; |
| 8750 | 9332 | $type=$match[1][0]; |
| 8751 | 9333 | $attributes=$this->parseAttributes($match[2][0],$match[2][1]); |
@@ -8755,16 +9337,18 @@ discard block |
||
| 8755 | 9337 | $stack[] = $type; |
| 8756 | 9338 | $container=$c-1; |
| 8757 | 9339 | } |
| 8758 | - } |
|
| 8759 | - else if(strpos($str,'</com:')===0) { |
|
| 8760 | - if($expectPropEnd) |
|
| 8761 | - continue; |
|
| 8762 | - if($matchStart>$textStart) |
|
| 8763 | - $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9340 | + } else if(strpos($str,'</com:')===0) { |
|
| 9341 | + if($expectPropEnd) { |
|
| 9342 | + continue; |
|
| 9343 | + } |
|
| 9344 | + if($matchStart>$textStart) { |
|
| 9345 | + $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9346 | + } |
|
| 8764 | 9347 | $textStart=$matchEnd+1; |
| 8765 | 9348 | $type=$match[1][0]; |
| 8766 | - if(empty($stack)) |
|
| 8767 | - throw new TConfigurationException('template_closingtag_unexpected',"</com:$type>"); |
|
| 9349 | + if(empty($stack)) { |
|
| 9350 | + throw new TConfigurationException('template_closingtag_unexpected',"</com:$type>"); |
|
| 9351 | + } |
|
| 8768 | 9352 | $name=array_pop($stack); |
| 8769 | 9353 | if($name!==$type) |
| 8770 | 9354 | { |
@@ -8772,77 +9356,85 @@ discard block |
||
| 8772 | 9356 | throw new TConfigurationException('template_closingtag_expected',$tag); |
| 8773 | 9357 | } |
| 8774 | 9358 | $container=$tpl[$container][0]; |
| 8775 | - } |
|
| 8776 | - else if(strpos($str,'<%@')===0) { |
|
| 8777 | - if($expectPropEnd) |
|
| 8778 | - continue; |
|
| 8779 | - if($matchStart>$textStart) |
|
| 8780 | - $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9359 | + } else if(strpos($str,'<%@')===0) { |
|
| 9360 | + if($expectPropEnd) { |
|
| 9361 | + continue; |
|
| 9362 | + } |
|
| 9363 | + if($matchStart>$textStart) { |
|
| 9364 | + $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9365 | + } |
|
| 8781 | 9366 | $textStart=$matchEnd+1; |
| 8782 | - if(isset($tpl[0]) || $this->_directive!==null) |
|
| 8783 | - throw new TConfigurationException('template_directive_nonunique'); |
|
| 9367 | + if(isset($tpl[0]) || $this->_directive!==null) { |
|
| 9368 | + throw new TConfigurationException('template_directive_nonunique'); |
|
| 9369 | + } |
|
| 8784 | 9370 | $this->_directive=$this->parseAttributes($match[4][0],$match[4][1]); |
| 8785 | - } |
|
| 8786 | - else if(strpos($str,'<%')===0) { |
|
| 8787 | - if($expectPropEnd) |
|
| 8788 | - continue; |
|
| 8789 | - if($matchStart>$textStart) |
|
| 8790 | - $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9371 | + } else if(strpos($str,'<%')===0) { |
|
| 9372 | + if($expectPropEnd) { |
|
| 9373 | + continue; |
|
| 9374 | + } |
|
| 9375 | + if($matchStart>$textStart) { |
|
| 9376 | + $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9377 | + } |
|
| 8791 | 9378 | $textStart=$matchEnd+1; |
| 8792 | 9379 | $literal=trim($match[5][0]); |
| 8793 | - if($str[2]==='=') $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,$literal)); |
|
| 8794 | - else if($str[2]==='%') $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_STATEMENTS,$literal)); |
|
| 8795 | - else if($str[2]==='#') |
|
| 8796 | - $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_DATABINDING,$literal)); |
|
| 8797 | - else if($str[2]==='$') |
|
| 8798 | - $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')")); |
|
| 8799 | - else if($str[2]==='~') |
|
| 8800 | - $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')")); |
|
| 8801 | - else if($str[2]==='/') |
|
| 8802 | - $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '/').'/$literal'")); |
|
| 8803 | - else if($str[2]==='[') |
|
| 9380 | + if($str[2]==='=') { |
|
| 9381 | + $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,$literal)); |
|
| 9382 | + } else if($str[2]==='%') { |
|
| 9383 | + $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_STATEMENTS,$literal)); |
|
| 9384 | + } else if($str[2]==='#') { |
|
| 9385 | + $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_DATABINDING,$literal)); |
|
| 9386 | + } else if($str[2]==='$') { |
|
| 9387 | + $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')")); |
|
| 9388 | + } else if($str[2]==='~') { |
|
| 9389 | + $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')")); |
|
| 9390 | + } else if($str[2]==='/') { |
|
| 9391 | + $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '/').'/$literal'")); |
|
| 9392 | + } else if($str[2]==='[') |
|
| 8804 | 9393 | { |
| 8805 | 9394 | $literal=strtr(trim(substr($literal,0,strlen($literal)-1)),array("'"=>"\'","\\"=>"\\\\")); |
| 8806 | 9395 | $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"Prado::localize('$literal')")); |
| 8807 | 9396 | } |
| 8808 | - } |
|
| 8809 | - else if(strpos($str,'<prop:')===0) { |
|
| 9397 | + } else if(strpos($str,'<prop:')===0) { |
|
| 8810 | 9398 | if(strrpos($str,'/>')===strlen($str)-2) { |
| 8811 | - if($expectPropEnd) |
|
| 8812 | - continue; |
|
| 8813 | - if($matchStart>$textStart) |
|
| 8814 | - $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9399 | + if($expectPropEnd) { |
|
| 9400 | + continue; |
|
| 9401 | + } |
|
| 9402 | + if($matchStart>$textStart) { |
|
| 9403 | + $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9404 | + } |
|
| 8815 | 9405 | $textStart=$matchEnd+1; |
| 8816 | 9406 | $prop=strtolower($match[6][0]); |
| 8817 | 9407 | $attrs=$this->parseAttributes($match[7][0],$match[7][1]); |
| 8818 | 9408 | $attributes=array(); |
| 8819 | - foreach($attrs as $name=>$value) |
|
| 8820 | - $attributes[$prop.'.'.$name]=$value; |
|
| 9409 | + foreach($attrs as $name=>$value) { |
|
| 9410 | + $attributes[$prop.'.'.$name]=$value; |
|
| 9411 | + } |
|
| 8821 | 9412 | $type=$tpl[$container][1]; |
| 8822 | 9413 | $this->validateAttributes($type,$attributes); |
| 8823 | 9414 | foreach($attributes as $name=>$value) |
| 8824 | 9415 | { |
| 8825 | - if(isset($tpl[$container][2][$name])) |
|
| 8826 | - throw new TConfigurationException('template_property_duplicated',$name); |
|
| 9416 | + if(isset($tpl[$container][2][$name])) { |
|
| 9417 | + throw new TConfigurationException('template_property_duplicated',$name); |
|
| 9418 | + } |
|
| 8827 | 9419 | $tpl[$container][2][$name]=$value; |
| 8828 | 9420 | } |
| 8829 | - } |
|
| 8830 | - else { |
|
| 9421 | + } else { |
|
| 8831 | 9422 | $prop=strtolower($match[3][0]); |
| 8832 | 9423 | $stack[] = '@'.$prop; |
| 8833 | 9424 | if(!$expectPropEnd) |
| 8834 | 9425 | { |
| 8835 | - if($matchStart>$textStart) |
|
| 8836 | - $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9426 | + if($matchStart>$textStart) { |
|
| 9427 | + $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9428 | + } |
|
| 8837 | 9429 | $textStart=$matchEnd+1; |
| 8838 | 9430 | $expectPropEnd=true; |
| 8839 | 9431 | } |
| 8840 | 9432 | } |
| 8841 | - } |
|
| 8842 | - else if(strpos($str,'</prop:')===0) { |
|
| 9433 | + } else if(strpos($str,'</prop:')===0) { |
|
| 8843 | 9434 | $prop=strtolower($match[3][0]); |
| 8844 | - if(empty($stack)) |
|
| 8845 | - throw new TConfigurationException('template_closingtag_unexpected',"</prop:$prop>"); |
|
| 9435 | + if(empty($stack)) { |
|
| 9436 | + throw new TConfigurationException('template_closingtag_unexpected',"</prop:$prop>"); |
|
| 9437 | + } |
|
| 8846 | 9438 | $name=array_pop($stack); |
| 8847 | 9439 | if($name!=='@'.$prop) |
| 8848 | 9440 | { |
@@ -8854,33 +9446,37 @@ discard block |
||
| 8854 | 9446 | if($matchStart>$textStart) |
| 8855 | 9447 | { |
| 8856 | 9448 | $value=substr($input,$textStart,$matchStart-$textStart); |
| 8857 | - if(substr($prop,-8,8)==='template') |
|
| 8858 | - $value=$this->parseTemplateProperty($value,$textStart); |
|
| 8859 | - else |
|
| 8860 | - $value=$this->parseAttribute($value); |
|
| 9449 | + if(substr($prop,-8,8)==='template') { |
|
| 9450 | + $value=$this->parseTemplateProperty($value,$textStart); |
|
| 9451 | + } else { |
|
| 9452 | + $value=$this->parseAttribute($value); |
|
| 9453 | + } |
|
| 8861 | 9454 | if($container>=0) |
| 8862 | 9455 | { |
| 8863 | 9456 | $type=$tpl[$container][1]; |
| 8864 | 9457 | $this->validateAttributes($type,array($prop=>$value)); |
| 8865 | - if(isset($tpl[$container][2][$prop])) |
|
| 8866 | - throw new TConfigurationException('template_property_duplicated',$prop); |
|
| 9458 | + if(isset($tpl[$container][2][$prop])) { |
|
| 9459 | + throw new TConfigurationException('template_property_duplicated',$prop); |
|
| 9460 | + } |
|
| 8867 | 9461 | $tpl[$container][2][$prop]=$value; |
| 9462 | + } else { |
|
| 9463 | + $this->_directive[$prop]=$value; |
|
| 8868 | 9464 | } |
| 8869 | - else $this->_directive[$prop]=$value; |
|
| 8870 | 9465 | $textStart=$matchEnd+1; |
| 8871 | 9466 | } |
| 8872 | 9467 | $expectPropEnd=false; |
| 8873 | 9468 | } |
| 8874 | - } |
|
| 8875 | - else if(strpos($str,'<!--')===0) { |
|
| 8876 | - if($expectPropEnd) |
|
| 8877 | - throw new TConfigurationException('template_comments_forbidden'); |
|
| 8878 | - if($matchStart>$textStart) |
|
| 8879 | - $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9469 | + } else if(strpos($str,'<!--')===0) { |
|
| 9470 | + if($expectPropEnd) { |
|
| 9471 | + throw new TConfigurationException('template_comments_forbidden'); |
|
| 9472 | + } |
|
| 9473 | + if($matchStart>$textStart) { |
|
| 9474 | + $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); |
|
| 9475 | + } |
|
| 8880 | 9476 | $textStart=$matchEnd+1; |
| 9477 | + } else { |
|
| 9478 | + throw new TConfigurationException('template_matching_unexpected',$match); |
|
| 8881 | 9479 | } |
| 8882 | - else |
|
| 8883 | - throw new TConfigurationException('template_matching_unexpected',$match); |
|
| 8884 | 9480 | } |
| 8885 | 9481 | if(!empty($stack)) |
| 8886 | 9482 | { |
@@ -8888,21 +9484,24 @@ discard block |
||
| 8888 | 9484 | $tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>"; |
| 8889 | 9485 | throw new TConfigurationException('template_closingtag_expected',$tag); |
| 8890 | 9486 | } |
| 8891 | - if($textStart<strlen($input)) |
|
| 8892 | - $tpl[$c++]=array($container,substr($input,$textStart)); |
|
| 8893 | - } |
|
| 8894 | - catch(Exception $e) |
|
| 9487 | + if($textStart<strlen($input)) { |
|
| 9488 | + $tpl[$c++]=array($container,substr($input,$textStart)); |
|
| 9489 | + } |
|
| 9490 | + } catch(Exception $e) |
|
| 8895 | 9491 | { |
| 8896 | - if(($e instanceof TException) && ($e instanceof TTemplateException)) |
|
| 8897 | - throw $e; |
|
| 8898 | - if($matchEnd===0) |
|
| 8899 | - $line=$this->_startingLine+1; |
|
| 8900 | - else |
|
| 8901 | - $line=$this->_startingLine+count(explode("\n",substr($input,0,$matchEnd+1))); |
|
| 9492 | + if(($e instanceof TException) && ($e instanceof TTemplateException)) { |
|
| 9493 | + throw $e; |
|
| 9494 | + } |
|
| 9495 | + if($matchEnd===0) { |
|
| 9496 | + $line=$this->_startingLine+1; |
|
| 9497 | + } else { |
|
| 9498 | + $line=$this->_startingLine+count(explode("\n",substr($input,0,$matchEnd+1))); |
|
| 9499 | + } |
|
| 8902 | 9500 | $this->handleException($e,$line,$input); |
| 8903 | 9501 | } |
| 8904 | - if($this->_directive===null) |
|
| 8905 | - $this->_directive=array(); |
|
| 9502 | + if($this->_directive===null) { |
|
| 9503 | + $this->_directive=array(); |
|
| 9504 | + } |
|
| 8906 | 9505 | $objects=array(); |
| 8907 | 9506 | $parent=null; |
| 8908 | 9507 | $merged=array(); |
@@ -8912,39 +9511,41 @@ discard block |
||
| 8912 | 9511 | { |
| 8913 | 9512 | if($parent!==null) |
| 8914 | 9513 | { |
| 8915 | - if(count($merged[1])===1 && is_string($merged[1][0])) |
|
| 8916 | - $objects[$id-1]=array($merged[0],$merged[1][0]); |
|
| 8917 | - else |
|
| 8918 | - $objects[$id-1]=array($merged[0],new TCompositeLiteral($merged[1])); |
|
| 9514 | + if(count($merged[1])===1 && is_string($merged[1][0])) { |
|
| 9515 | + $objects[$id-1]=array($merged[0],$merged[1][0]); |
|
| 9516 | + } else { |
|
| 9517 | + $objects[$id-1]=array($merged[0],new TCompositeLiteral($merged[1])); |
|
| 9518 | + } |
|
| 8919 | 9519 | } |
| 8920 | 9520 | if(isset($object[2])) |
| 8921 | 9521 | { |
| 8922 | 9522 | $parent=null; |
| 8923 | 9523 | $objects[$id]=$object; |
| 8924 | - } |
|
| 8925 | - else |
|
| 9524 | + } else |
|
| 8926 | 9525 | { |
| 8927 | 9526 | $parent=$object[0]; |
| 8928 | 9527 | $merged=array($parent,array($object[1])); |
| 8929 | 9528 | } |
| 9529 | + } else { |
|
| 9530 | + $merged[1][]=$object[1]; |
|
| 8930 | 9531 | } |
| 8931 | - else |
|
| 8932 | - $merged[1][]=$object[1]; |
|
| 8933 | 9532 | } |
| 8934 | 9533 | if($parent!==null) |
| 8935 | 9534 | { |
| 8936 | - if(count($merged[1])===1 && is_string($merged[1][0])) |
|
| 8937 | - $objects[$id]=array($merged[0],$merged[1][0]); |
|
| 8938 | - else |
|
| 8939 | - $objects[$id]=array($merged[0],new TCompositeLiteral($merged[1])); |
|
| 9535 | + if(count($merged[1])===1 && is_string($merged[1][0])) { |
|
| 9536 | + $objects[$id]=array($merged[0],$merged[1][0]); |
|
| 9537 | + } else { |
|
| 9538 | + $objects[$id]=array($merged[0],new TCompositeLiteral($merged[1])); |
|
| 9539 | + } |
|
| 8940 | 9540 | } |
| 8941 | 9541 | $tpl=$objects; |
| 8942 | 9542 | return $objects; |
| 8943 | 9543 | } |
| 8944 | 9544 | protected function parseAttributes($str,$offset) |
| 8945 | 9545 | { |
| 8946 | - if($str==='') |
|
| 8947 | - return array(); |
|
| 9546 | + if($str==='') { |
|
| 9547 | + return array(); |
|
| 9548 | + } |
|
| 8948 | 9549 | $pattern='/([\w\.\-]+)\s*=\s*(\'.*?\'|".*?"|<%.*?%>)/msS'; |
| 8949 | 9550 | $attributes=array(); |
| 8950 | 9551 | $n=preg_match_all($pattern,$str,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE); |
@@ -8952,22 +9553,24 @@ discard block |
||
| 8952 | 9553 | { |
| 8953 | 9554 | $match=&$matches[$i]; |
| 8954 | 9555 | $name=strtolower($match[1][0]); |
| 8955 | - if(isset($attributes[$name])) |
|
| 8956 | - throw new TConfigurationException('template_property_duplicated',$name); |
|
| 9556 | + if(isset($attributes[$name])) { |
|
| 9557 | + throw new TConfigurationException('template_property_duplicated',$name); |
|
| 9558 | + } |
|
| 8957 | 9559 | $value=$match[2][0]; |
| 8958 | 9560 | if(substr($name,-8,8)==='template') |
| 8959 | 9561 | { |
| 8960 | - if($value[0]==='\'' || $value[0]==='"') |
|
| 8961 | - $attributes[$name]=$this->parseTemplateProperty(substr($value,1,strlen($value)-2),$match[2][1]+1); |
|
| 8962 | - else |
|
| 8963 | - $attributes[$name]=$this->parseTemplateProperty($value,$match[2][1]); |
|
| 8964 | - } |
|
| 8965 | - else |
|
| 9562 | + if($value[0]==='\'' || $value[0]==='"') { |
|
| 9563 | + $attributes[$name]=$this->parseTemplateProperty(substr($value,1,strlen($value)-2),$match[2][1]+1); |
|
| 9564 | + } else { |
|
| 9565 | + $attributes[$name]=$this->parseTemplateProperty($value,$match[2][1]); |
|
| 9566 | + } |
|
| 9567 | + } else |
|
| 8966 | 9568 | { |
| 8967 | - if($value[0]==='\'' || $value[0]==='"') |
|
| 8968 | - $attributes[$name]=$this->parseAttribute(substr($value,1,strlen($value)-2)); |
|
| 8969 | - else |
|
| 8970 | - $attributes[$name]=$this->parseAttribute($value); |
|
| 9569 | + if($value[0]==='\'' || $value[0]==='"') { |
|
| 9570 | + $attributes[$name]=$this->parseAttribute(substr($value,1,strlen($value)-2)); |
|
| 9571 | + } else { |
|
| 9572 | + $attributes[$name]=$this->parseAttribute($value); |
|
| 9573 | + } |
|
| 8971 | 9574 | } |
| 8972 | 9575 | } |
| 8973 | 9576 | return $attributes; |
@@ -8990,45 +9593,49 @@ discard block |
||
| 8990 | 9593 | $token=$match[0]; |
| 8991 | 9594 | $offset=$match[1]; |
| 8992 | 9595 | $length=strlen($token); |
| 8993 | - if($token[2]==='#') |
|
| 8994 | - $isDataBind=true; |
|
| 8995 | - if($offset>$textStart) |
|
| 8996 | - $expr.=".'".strtr(substr($value,$textStart,$offset-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'"; |
|
| 9596 | + if($token[2]==='#') { |
|
| 9597 | + $isDataBind=true; |
|
| 9598 | + } |
|
| 9599 | + if($offset>$textStart) { |
|
| 9600 | + $expr.=".'".strtr(substr($value,$textStart,$offset-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'"; |
|
| 9601 | + } |
|
| 8997 | 9602 | $expr.='.('.substr($token,3,$length-5).')'; |
| 8998 | 9603 | $textStart=$offset+$length; |
| 8999 | 9604 | } |
| 9000 | 9605 | $length=strlen($value); |
| 9001 | - if($length>$textStart) |
|
| 9002 | - $expr.=".'".strtr(substr($value,$textStart,$length-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'"; |
|
| 9003 | - if($isDataBind) |
|
| 9004 | - return array(self::CONFIG_DATABIND,ltrim($expr,'.')); |
|
| 9005 | - else |
|
| 9006 | - return array(self::CONFIG_EXPRESSION,ltrim($expr,'.')); |
|
| 9007 | - } |
|
| 9008 | - else if(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS',$value,$matches) && $matches[0]===$value) |
|
| 9606 | + if($length>$textStart) { |
|
| 9607 | + $expr.=".'".strtr(substr($value,$textStart,$length-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'"; |
|
| 9608 | + } |
|
| 9609 | + if($isDataBind) { |
|
| 9610 | + return array(self::CONFIG_DATABIND,ltrim($expr,'.')); |
|
| 9611 | + } else { |
|
| 9612 | + return array(self::CONFIG_EXPRESSION,ltrim($expr,'.')); |
|
| 9613 | + } |
|
| 9614 | + } else if(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS',$value,$matches) && $matches[0]===$value) |
|
| 9009 | 9615 | { |
| 9010 | 9616 | $value=$matches[1]; |
| 9011 | - if($value[2]==='~') |
|
| 9012 | - return array(self::CONFIG_ASSET,trim(substr($value,3,strlen($value)-5))); |
|
| 9013 | - elseif($value[2]==='[') |
|
| 9014 | - return array(self::CONFIG_LOCALIZATION,trim(substr($value,3,strlen($value)-6))); |
|
| 9015 | - elseif($value[2]==='$') |
|
| 9016 | - return array(self::CONFIG_PARAMETER,trim(substr($value,3,strlen($value)-5))); |
|
| 9017 | - elseif($value[2]==='/') { |
|
| 9617 | + if($value[2]==='~') { |
|
| 9618 | + return array(self::CONFIG_ASSET,trim(substr($value,3,strlen($value)-5))); |
|
| 9619 | + } elseif($value[2]==='[') { |
|
| 9620 | + return array(self::CONFIG_LOCALIZATION,trim(substr($value,3,strlen($value)-6))); |
|
| 9621 | + } elseif($value[2]==='$') { |
|
| 9622 | + return array(self::CONFIG_PARAMETER,trim(substr($value,3,strlen($value)-5))); |
|
| 9623 | + } elseif($value[2]==='/') { |
|
| 9018 | 9624 | $literal = trim(substr($value,3,strlen($value)-5)); |
| 9019 | 9625 | return array(self::CONFIG_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '/').'/$literal'"); |
| 9020 | 9626 | } |
| 9627 | + } else { |
|
| 9628 | + return $value; |
|
| 9021 | 9629 | } |
| 9022 | - else |
|
| 9023 | - return $value; |
|
| 9024 | 9630 | } |
| 9025 | 9631 | protected function validateAttributes($type,$attributes) |
| 9026 | 9632 | { |
| 9027 | 9633 | Prado::using($type); |
| 9028 | - if(($pos=strrpos($type,'.'))!==false) |
|
| 9029 | - $className=substr($type,$pos+1); |
|
| 9030 | - else |
|
| 9031 | - $className=$type; |
|
| 9634 | + if(($pos=strrpos($type,'.'))!==false) { |
|
| 9635 | + $className=substr($type,$pos+1); |
|
| 9636 | + } else { |
|
| 9637 | + $className=$type; |
|
| 9638 | + } |
|
| 9032 | 9639 | $class=new ReflectionClass($className); |
| 9033 | 9640 | if(is_subclass_of($className,'TControl') || $className==='TControl') |
| 9034 | 9641 | { |
@@ -9037,63 +9644,65 @@ discard block |
||
| 9037 | 9644 | if(($pos=strpos($name,'.'))!==false) |
| 9038 | 9645 | { |
| 9039 | 9646 | $subname=substr($name,0,$pos); |
| 9040 | - if(!$class->hasMethod('get'.$subname)) |
|
| 9041 | - throw new TConfigurationException('template_property_unknown',$type,$subname); |
|
| 9042 | - } |
|
| 9043 | - else if(strncasecmp($name,'on',2)===0) |
|
| 9647 | + if(!$class->hasMethod('get'.$subname)) { |
|
| 9648 | + throw new TConfigurationException('template_property_unknown',$type,$subname); |
|
| 9649 | + } |
|
| 9650 | + } else if(strncasecmp($name,'on',2)===0) |
|
| 9044 | 9651 | { |
| 9045 | - if(!$class->hasMethod($name)) |
|
| 9046 | - throw new TConfigurationException('template_event_unknown',$type,$name); |
|
| 9047 | - else if(!is_string($att)) |
|
| 9048 | - throw new TConfigurationException('template_eventhandler_invalid',$type,$name); |
|
| 9049 | - } |
|
| 9050 | - else |
|
| 9652 | + if(!$class->hasMethod($name)) { |
|
| 9653 | + throw new TConfigurationException('template_event_unknown',$type,$name); |
|
| 9654 | + } else if(!is_string($att)) { |
|
| 9655 | + throw new TConfigurationException('template_eventhandler_invalid',$type,$name); |
|
| 9656 | + } |
|
| 9657 | + } else |
|
| 9051 | 9658 | { |
| 9052 | 9659 | if (! ($class->hasMethod('set'.$name) || $class->hasMethod('setjs'.$name) || $this->isClassBehaviorMethod($class,'set'.$name)) ) |
| 9053 | 9660 | { |
| 9054 | - if ($class->hasMethod('get'.$name) || $class->hasMethod('getjs'.$name)) |
|
| 9055 | - throw new TConfigurationException('template_property_readonly',$type,$name); |
|
| 9056 | - else |
|
| 9057 | - throw new TConfigurationException('template_property_unknown',$type,$name); |
|
| 9058 | - } |
|
| 9059 | - else if(is_array($att) && $att[0]!==self::CONFIG_EXPRESSION) |
|
| 9661 | + if ($class->hasMethod('get'.$name) || $class->hasMethod('getjs'.$name)) { |
|
| 9662 | + throw new TConfigurationException('template_property_readonly',$type,$name); |
|
| 9663 | + } else { |
|
| 9664 | + throw new TConfigurationException('template_property_unknown',$type,$name); |
|
| 9665 | + } |
|
| 9666 | + } else if(is_array($att) && $att[0]!==self::CONFIG_EXPRESSION) |
|
| 9060 | 9667 | { |
| 9061 | - if(strcasecmp($name,'id')===0) |
|
| 9062 | - throw new TConfigurationException('template_controlid_invalid',$type); |
|
| 9063 | - else if(strcasecmp($name,'skinid')===0) |
|
| 9064 | - throw new TConfigurationException('template_controlskinid_invalid',$type); |
|
| 9668 | + if(strcasecmp($name,'id')===0) { |
|
| 9669 | + throw new TConfigurationException('template_controlid_invalid',$type); |
|
| 9670 | + } else if(strcasecmp($name,'skinid')===0) { |
|
| 9671 | + throw new TConfigurationException('template_controlskinid_invalid',$type); |
|
| 9672 | + } |
|
| 9065 | 9673 | } |
| 9066 | 9674 | } |
| 9067 | 9675 | } |
| 9068 | - } |
|
| 9069 | - else if(is_subclass_of($className,'TComponent') || $className==='TComponent') |
|
| 9676 | + } else if(is_subclass_of($className,'TComponent') || $className==='TComponent') |
|
| 9070 | 9677 | { |
| 9071 | 9678 | foreach($attributes as $name=>$att) |
| 9072 | 9679 | { |
| 9073 | - if(is_array($att) && ($att[0]===self::CONFIG_DATABIND)) |
|
| 9074 | - throw new TConfigurationException('template_databind_forbidden',$type,$name); |
|
| 9680 | + if(is_array($att) && ($att[0]===self::CONFIG_DATABIND)) { |
|
| 9681 | + throw new TConfigurationException('template_databind_forbidden',$type,$name); |
|
| 9682 | + } |
|
| 9075 | 9683 | if(($pos=strpos($name,'.'))!==false) |
| 9076 | 9684 | { |
| 9077 | 9685 | $subname=substr($name,0,$pos); |
| 9078 | - if(!$class->hasMethod('get'.$subname)) |
|
| 9079 | - throw new TConfigurationException('template_property_unknown',$type,$subname); |
|
| 9080 | - } |
|
| 9081 | - else if(strncasecmp($name,'on',2)===0) |
|
| 9082 | - throw new TConfigurationException('template_event_forbidden',$type,$name); |
|
| 9083 | - else |
|
| 9686 | + if(!$class->hasMethod('get'.$subname)) { |
|
| 9687 | + throw new TConfigurationException('template_property_unknown',$type,$subname); |
|
| 9688 | + } |
|
| 9689 | + } else if(strncasecmp($name,'on',2)===0) { |
|
| 9690 | + throw new TConfigurationException('template_event_forbidden',$type,$name); |
|
| 9691 | + } else |
|
| 9084 | 9692 | { |
| 9085 | 9693 | if(strcasecmp($name,'id')!==0 && !($class->hasMethod('set'.$name) || $this->isClassBehaviorMethod($class,'set'.$name))) |
| 9086 | 9694 | { |
| 9087 | - if($class->hasMethod('get'.$name)) |
|
| 9088 | - throw new TConfigurationException('template_property_readonly',$type,$name); |
|
| 9089 | - else |
|
| 9090 | - throw new TConfigurationException('template_property_unknown',$type,$name); |
|
| 9695 | + if($class->hasMethod('get'.$name)) { |
|
| 9696 | + throw new TConfigurationException('template_property_readonly',$type,$name); |
|
| 9697 | + } else { |
|
| 9698 | + throw new TConfigurationException('template_property_unknown',$type,$name); |
|
| 9699 | + } |
|
| 9091 | 9700 | } |
| 9092 | 9701 | } |
| 9093 | 9702 | } |
| 9703 | + } else { |
|
| 9704 | + throw new TConfigurationException('template_component_required',$type); |
|
| 9094 | 9705 | } |
| 9095 | - else |
|
| 9096 | - throw new TConfigurationException('template_component_required',$type); |
|
| 9097 | 9706 | } |
| 9098 | 9707 | public function getIncludedFiles() |
| 9099 | 9708 | { |
@@ -9112,18 +9721,19 @@ discard block |
||
| 9112 | 9721 | $line=$line-$this->_includeAtLine[$i]+1; |
| 9113 | 9722 | $srcFile=$this->_includedFiles[$i]; |
| 9114 | 9723 | break; |
| 9724 | + } else { |
|
| 9725 | + $line=$line-$this->_includeLines[$i]+1; |
|
| 9115 | 9726 | } |
| 9116 | - else |
|
| 9117 | - $line=$line-$this->_includeLines[$i]+1; |
|
| 9118 | 9727 | } |
| 9119 | 9728 | } |
| 9120 | 9729 | } |
| 9121 | 9730 | $exception=new TTemplateException('template_format_invalid',$e->getMessage()); |
| 9122 | 9731 | $exception->setLineNumber($line); |
| 9123 | - if(!empty($srcFile)) |
|
| 9124 | - $exception->setTemplateFile($srcFile); |
|
| 9125 | - else |
|
| 9126 | - $exception->setTemplateSource($input); |
|
| 9732 | + if(!empty($srcFile)) { |
|
| 9733 | + $exception->setTemplateFile($srcFile); |
|
| 9734 | + } else { |
|
| 9735 | + $exception->setTemplateSource($input); |
|
| 9736 | + } |
|
| 9127 | 9737 | throw $exception; |
| 9128 | 9738 | } |
| 9129 | 9739 | protected function preprocess($input) |
@@ -9133,9 +9743,9 @@ discard block |
||
| 9133 | 9743 | for($i=0;$i<$n;++$i) |
| 9134 | 9744 | { |
| 9135 | 9745 | $filePath=Prado::getPathOfNamespace(trim($matches[$i][1][0]),TTemplateManager::TEMPLATE_FILE_EXT); |
| 9136 | - if($filePath!==null && is_file($filePath)) |
|
| 9137 | - $this->_includedFiles[]=$filePath; |
|
| 9138 | - else |
|
| 9746 | + if($filePath!==null && is_file($filePath)) { |
|
| 9747 | + $this->_includedFiles[]=$filePath; |
|
| 9748 | + } else |
|
| 9139 | 9749 | { |
| 9140 | 9750 | $errorLine=count(explode("\n",substr($input,0,$matches[$i][0][1]+1))); |
| 9141 | 9751 | $this->handleException(new TConfigurationException('template_include_invalid',trim($matches[$i][1][0])),$errorLine,$input); |
@@ -9159,15 +9769,19 @@ discard block |
||
| 9159 | 9769 | { |
| 9160 | 9770 | $component=new ReflectionClass('TComponent'); |
| 9161 | 9771 | $behaviors=$component->getStaticProperties(); |
| 9162 | - if(!isset($behaviors['_um'])) |
|
| 9163 | - return false; |
|
| 9772 | + if(!isset($behaviors['_um'])) { |
|
| 9773 | + return false; |
|
| 9774 | + } |
|
| 9164 | 9775 | foreach($behaviors['_um'] as $name=>$list) |
| 9165 | 9776 | { |
| 9166 | - if(strtolower($class->getShortName())!==$name && !$class->isSubclassOf($name)) continue; |
|
| 9777 | + if(strtolower($class->getShortName())!==$name && !$class->isSubclassOf($name)) { |
|
| 9778 | + continue; |
|
| 9779 | + } |
|
| 9167 | 9780 | foreach($list as $param) |
| 9168 | 9781 | { |
| 9169 | - if(method_exists($param->getBehavior(),$method)) |
|
| 9170 | - return true; |
|
| 9782 | + if(method_exists($param->getBehavior(),$method)) { |
|
| 9783 | + return true; |
|
| 9784 | + } |
|
| 9171 | 9785 | } |
| 9172 | 9786 | } |
| 9173 | 9787 | return false; |
@@ -9185,10 +9799,11 @@ discard block |
||
| 9185 | 9799 | { |
| 9186 | 9800 | $this->_initialized=true; |
| 9187 | 9801 | $service=$this->getService(); |
| 9188 | - if($service instanceof TPageService) |
|
| 9189 | - $service->setThemeManager($this); |
|
| 9190 | - else |
|
| 9191 | - throw new TConfigurationException('thememanager_service_unavailable'); |
|
| 9802 | + if($service instanceof TPageService) { |
|
| 9803 | + $service->setThemeManager($this); |
|
| 9804 | + } else { |
|
| 9805 | + throw new TConfigurationException('thememanager_service_unavailable'); |
|
| 9806 | + } |
|
| 9192 | 9807 | } |
| 9193 | 9808 | public function getTheme($name) |
| 9194 | 9809 | { |
@@ -9209,8 +9824,9 @@ discard block |
||
| 9209 | 9824 | $folder=@opendir($basePath); |
| 9210 | 9825 | while($file=@readdir($folder)) |
| 9211 | 9826 | { |
| 9212 | - if($file!=='.' && $file!=='..' && $file!=='.svn' && is_dir($basePath.DIRECTORY_SEPARATOR.$file)) |
|
| 9213 | - $themes[]=$file; |
|
| 9827 | + if($file!=='.' && $file!=='..' && $file!=='.svn' && is_dir($basePath.DIRECTORY_SEPARATOR.$file)) { |
|
| 9828 | + $themes[]=$file; |
|
| 9829 | + } |
|
| 9214 | 9830 | } |
| 9215 | 9831 | closedir($folder); |
| 9216 | 9832 | return $themes; |
@@ -9220,21 +9836,23 @@ discard block |
||
| 9220 | 9836 | if($this->_basePath===null) |
| 9221 | 9837 | { |
| 9222 | 9838 | $this->_basePath=dirname($this->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
| 9223 | - if(($basePath=realpath($this->_basePath))===false || !is_dir($basePath)) |
|
| 9224 | - throw new TConfigurationException('thememanager_basepath_invalid2',$this->_basePath); |
|
| 9839 | + if(($basePath=realpath($this->_basePath))===false || !is_dir($basePath)) { |
|
| 9840 | + throw new TConfigurationException('thememanager_basepath_invalid2',$this->_basePath); |
|
| 9841 | + } |
|
| 9225 | 9842 | $this->_basePath=$basePath; |
| 9226 | 9843 | } |
| 9227 | 9844 | return $this->_basePath; |
| 9228 | 9845 | } |
| 9229 | 9846 | public function setBasePath($value) |
| 9230 | 9847 | { |
| 9231 | - if($this->_initialized) |
|
| 9232 | - throw new TInvalidOperationException('thememanager_basepath_unchangeable'); |
|
| 9233 | - else |
|
| 9848 | + if($this->_initialized) { |
|
| 9849 | + throw new TInvalidOperationException('thememanager_basepath_unchangeable'); |
|
| 9850 | + } else |
|
| 9234 | 9851 | { |
| 9235 | 9852 | $this->_basePath=Prado::getPathOfNamespace($value); |
| 9236 | - if($this->_basePath===null || !is_dir($this->_basePath)) |
|
| 9237 | - throw new TInvalidDataValueException('thememanager_basepath_invalid',$value); |
|
| 9853 | + if($this->_basePath===null || !is_dir($this->_basePath)) { |
|
| 9854 | + throw new TInvalidDataValueException('thememanager_basepath_invalid',$value); |
|
| 9855 | + } |
|
| 9238 | 9856 | } |
| 9239 | 9857 | } |
| 9240 | 9858 | public function getBaseUrl() |
@@ -9243,8 +9861,9 @@ discard block |
||
| 9243 | 9861 | { |
| 9244 | 9862 | $appPath=dirname($this->getRequest()->getApplicationFilePath()); |
| 9245 | 9863 | $basePath=$this->getBasePath(); |
| 9246 | - if(strpos($basePath,$appPath)===false) |
|
| 9247 | - throw new TConfigurationException('thememanager_baseurl_required'); |
|
| 9864 | + if(strpos($basePath,$appPath)===false) { |
|
| 9865 | + throw new TConfigurationException('thememanager_baseurl_required'); |
|
| 9866 | + } |
|
| 9248 | 9867 | $appUrl=rtrim(dirname($this->getRequest()->getApplicationUrl()),'/\\'); |
| 9249 | 9868 | $this->_baseUrl=$appUrl.strtr(substr($basePath,strlen($appPath)),'\\','/'); |
| 9250 | 9869 | } |
@@ -9279,28 +9898,29 @@ discard block |
||
| 9279 | 9898 | list($skins,$cssFiles,$jsFiles,$timestamp)=$array; |
| 9280 | 9899 | if($this->getApplication()->getMode()!==TApplicationMode::Performance) |
| 9281 | 9900 | { |
| 9282 | - if(($dir=opendir($themePath))===false) |
|
| 9283 | - throw new TIOException('theme_path_inexistent',$themePath); |
|
| 9901 | + if(($dir=opendir($themePath))===false) { |
|
| 9902 | + throw new TIOException('theme_path_inexistent',$themePath); |
|
| 9903 | + } |
|
| 9284 | 9904 | $cacheValid=true; |
| 9285 | 9905 | while(($file=readdir($dir))!==false) |
| 9286 | 9906 | { |
| 9287 | - if($file==='.' || $file==='..') |
|
| 9288 | - continue; |
|
| 9289 | - else if(basename($file,'.css')!==$file) |
|
| 9290 | - $this->_cssFiles[]=$themeUrl.'/'.$file; |
|
| 9291 | - else if(basename($file,'.js')!==$file) |
|
| 9292 | - $this->_jsFiles[]=$themeUrl.'/'.$file; |
|
| 9293 | - else if(basename($file,self::SKIN_FILE_EXT)!==$file && filemtime($themePath.DIRECTORY_SEPARATOR.$file)>$timestamp) |
|
| 9907 | + if($file==='.' || $file==='..') { |
|
| 9908 | + continue; |
|
| 9909 | + } else if(basename($file,'.css')!==$file) { |
|
| 9910 | + $this->_cssFiles[]=$themeUrl.'/'.$file; |
|
| 9911 | + } else if(basename($file,'.js')!==$file) { |
|
| 9912 | + $this->_jsFiles[]=$themeUrl.'/'.$file; |
|
| 9913 | + } else if(basename($file,self::SKIN_FILE_EXT)!==$file && filemtime($themePath.DIRECTORY_SEPARATOR.$file)>$timestamp) |
|
| 9294 | 9914 | { |
| 9295 | 9915 | $cacheValid=false; |
| 9296 | 9916 | break; |
| 9297 | 9917 | } |
| 9298 | 9918 | } |
| 9299 | 9919 | closedir($dir); |
| 9300 | - if($cacheValid) |
|
| 9301 | - $this->_skins=$skins; |
|
| 9302 | - } |
|
| 9303 | - else |
|
| 9920 | + if($cacheValid) { |
|
| 9921 | + $this->_skins=$skins; |
|
| 9922 | + } |
|
| 9923 | + } else |
|
| 9304 | 9924 | { |
| 9305 | 9925 | $cacheValid=true; |
| 9306 | 9926 | $this->_cssFiles=$cssFiles; |
@@ -9314,29 +9934,33 @@ discard block |
||
| 9314 | 9934 | $this->_cssFiles=array(); |
| 9315 | 9935 | $this->_jsFiles=array(); |
| 9316 | 9936 | $this->_skins=array(); |
| 9317 | - if(($dir=opendir($themePath))===false) |
|
| 9318 | - throw new TIOException('theme_path_inexistent',$themePath); |
|
| 9937 | + if(($dir=opendir($themePath))===false) { |
|
| 9938 | + throw new TIOException('theme_path_inexistent',$themePath); |
|
| 9939 | + } |
|
| 9319 | 9940 | while(($file=readdir($dir))!==false) |
| 9320 | 9941 | { |
| 9321 | - if($file==='.' || $file==='..') |
|
| 9322 | - continue; |
|
| 9323 | - else if(basename($file,'.css')!==$file) |
|
| 9324 | - $this->_cssFiles[]=$themeUrl.'/'.$file; |
|
| 9325 | - else if(basename($file,'.js')!==$file) |
|
| 9326 | - $this->_jsFiles[]=$themeUrl.'/'.$file; |
|
| 9327 | - else if(basename($file,self::SKIN_FILE_EXT)!==$file) |
|
| 9942 | + if($file==='.' || $file==='..') { |
|
| 9943 | + continue; |
|
| 9944 | + } else if(basename($file,'.css')!==$file) { |
|
| 9945 | + $this->_cssFiles[]=$themeUrl.'/'.$file; |
|
| 9946 | + } else if(basename($file,'.js')!==$file) { |
|
| 9947 | + $this->_jsFiles[]=$themeUrl.'/'.$file; |
|
| 9948 | + } else if(basename($file,self::SKIN_FILE_EXT)!==$file) |
|
| 9328 | 9949 | { |
| 9329 | 9950 | $template=new TTemplate(file_get_contents($themePath.'/'.$file),$themePath,$themePath.'/'.$file); |
| 9330 | 9951 | foreach($template->getItems() as $skin) |
| 9331 | 9952 | { |
| 9332 | - if(!isset($skin[2])) continue; |
|
| 9333 | - else if($skin[0]!==-1) |
|
| 9334 | - throw new TConfigurationException('theme_control_nested',$skin[1],dirname($themePath)); |
|
| 9953 | + if(!isset($skin[2])) { |
|
| 9954 | + continue; |
|
| 9955 | + } else if($skin[0]!==-1) { |
|
| 9956 | + throw new TConfigurationException('theme_control_nested',$skin[1],dirname($themePath)); |
|
| 9957 | + } |
|
| 9335 | 9958 | $type=$skin[1]; |
| 9336 | 9959 | $id=isset($skin[2]['skinid'])?$skin[2]['skinid']:0; |
| 9337 | 9960 | unset($skin[2]['skinid']); |
| 9338 | - if(isset($this->_skins[$type][$id])) |
|
| 9339 | - throw new TConfigurationException('theme_skinid_duplicated',$type,$id,dirname($themePath)); |
|
| 9961 | + if(isset($this->_skins[$type][$id])) { |
|
| 9962 | + throw new TConfigurationException('theme_skinid_duplicated',$type,$id,dirname($themePath)); |
|
| 9963 | + } |
|
| 9340 | 9964 | $this->_skins[$type][$id]=$skin[2]; |
| 9341 | 9965 | } |
| 9342 | 9966 | } |
@@ -9344,8 +9968,9 @@ discard block |
||
| 9344 | 9968 | closedir($dir); |
| 9345 | 9969 | sort($this->_cssFiles); |
| 9346 | 9970 | sort($this->_jsFiles); |
| 9347 | - if($cache!==null) |
|
| 9348 | - $cache->set(self::THEME_CACHE_PREFIX.$themePath,array($this->_skins,$this->_cssFiles,$this->_jsFiles,time())); |
|
| 9971 | + if($cache!==null) { |
|
| 9972 | + $cache->set(self::THEME_CACHE_PREFIX.$themePath,array($this->_skins,$this->_cssFiles,$this->_jsFiles,time())); |
|
| 9973 | + } |
|
| 9349 | 9974 | } |
| 9350 | 9975 | } |
| 9351 | 9976 | public function getName() |
@@ -9383,8 +10008,9 @@ discard block |
||
| 9383 | 10008 | public function applySkin($control) |
| 9384 | 10009 | { |
| 9385 | 10010 | $type=get_class($control); |
| 9386 | - if(($id=$control->getSkinID())==='') |
|
| 9387 | - $id=0; |
|
| 10011 | + if(($id=$control->getSkinID())==='') { |
|
| 10012 | + $id=0; |
|
| 10013 | + } |
|
| 9388 | 10014 | if(isset($this->_skins[$type][$id])) |
| 9389 | 10015 | { |
| 9390 | 10016 | foreach($this->_skins[$type][$id] as $name=>$value) |
@@ -9425,20 +10051,21 @@ discard block |
||
| 9425 | 10051 | { |
| 9426 | 10052 | $setter='set'.$name; |
| 9427 | 10053 | $control->$setter($value); |
| 10054 | + } else { |
|
| 10055 | + throw new TConfigurationException('theme_property_readonly',$type,$name); |
|
| 9428 | 10056 | } |
| 9429 | - else |
|
| 9430 | - throw new TConfigurationException('theme_property_readonly',$type,$name); |
|
| 10057 | + } else { |
|
| 10058 | + throw new TConfigurationException('theme_property_undefined',$type,$name); |
|
| 9431 | 10059 | } |
| 9432 | - else |
|
| 9433 | - throw new TConfigurationException('theme_property_undefined',$type,$name); |
|
| 10060 | + } else { |
|
| 10061 | + $control->setSubProperty($name,$value); |
|
| 9434 | 10062 | } |
| 9435 | - else $control->setSubProperty($name,$value); |
|
| 9436 | 10063 | } |
| 9437 | 10064 | } |
| 9438 | 10065 | return true; |
| 10066 | + } else { |
|
| 10067 | + return false; |
|
| 9439 | 10068 | } |
| 9440 | - else |
|
| 9441 | - return false; |
|
| 9442 | 10069 | } |
| 9443 | 10070 | public function getStyleSheetFiles() |
| 9444 | 10071 | { |
@@ -9484,8 +10111,9 @@ discard block |
||
| 9484 | 10111 | protected function initPageContext($pageConfig) |
| 9485 | 10112 | { |
| 9486 | 10113 | $application=$this->getApplication(); |
| 9487 | - foreach($pageConfig->getApplicationConfigurations() as $appConfig) |
|
| 9488 | - $application->applyConfiguration($appConfig); |
|
| 10114 | + foreach($pageConfig->getApplicationConfigurations() as $appConfig) { |
|
| 10115 | + $application->applyConfiguration($appConfig); |
|
| 10116 | + } |
|
| 9489 | 10117 | $this->applyConfiguration($pageConfig); |
| 9490 | 10118 | } |
| 9491 | 10119 | protected function applyConfiguration($config) |
@@ -9496,12 +10124,14 @@ discard block |
||
| 9496 | 10124 | foreach($config->getExternalConfigurations() as $filePath=>$params) |
| 9497 | 10125 | { |
| 9498 | 10126 | list($configPagePath,$condition)=$params; |
| 9499 | - if($condition!==true) |
|
| 9500 | - $condition=$this->evaluateExpression($condition); |
|
| 10127 | + if($condition!==true) { |
|
| 10128 | + $condition=$this->evaluateExpression($condition); |
|
| 10129 | + } |
|
| 9501 | 10130 | if($condition) |
| 9502 | 10131 | { |
| 9503 | - if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path)) |
|
| 9504 | - throw new TConfigurationException('pageservice_includefile_invalid',$filePath); |
|
| 10132 | + if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path)) { |
|
| 10133 | + throw new TConfigurationException('pageservice_includefile_invalid',$filePath); |
|
| 10134 | + } |
|
| 9505 | 10135 | $c=new TPageConfiguration($pagePath); |
| 9506 | 10136 | $c->loadFromFile($path,$configPagePath); |
| 9507 | 10137 | $this->applyConfiguration($c); |
@@ -9511,8 +10141,9 @@ discard block |
||
| 9511 | 10141 | protected function determineRequestedPagePath() |
| 9512 | 10142 | { |
| 9513 | 10143 | $pagePath=$this->getRequest()->getServiceParameter(); |
| 9514 | - if(empty($pagePath)) |
|
| 9515 | - $pagePath=$this->getDefaultPage(); |
|
| 10144 | + if(empty($pagePath)) { |
|
| 10145 | + $pagePath=$this->getDefaultPage(); |
|
| 10146 | + } |
|
| 9516 | 10147 | return $pagePath; |
| 9517 | 10148 | } |
| 9518 | 10149 | protected function loadPageConfig($config) |
@@ -9524,14 +10155,14 @@ discard block |
||
| 9524 | 10155 | $pageConfig=new TPageConfiguration($pagePath); |
| 9525 | 10156 | if($config!==null) |
| 9526 | 10157 | { |
| 9527 | - if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
| 9528 | - $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
| 9529 | - else |
|
| 9530 | - $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
| 10158 | + if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) { |
|
| 10159 | + $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
| 10160 | + } else { |
|
| 10161 | + $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
| 10162 | + } |
|
| 9531 | 10163 | } |
| 9532 | 10164 | $pageConfig->loadFromFiles($this->getBasePath()); |
| 9533 | - } |
|
| 9534 | - else |
|
| 10165 | + } else |
|
| 9535 | 10166 | { |
| 9536 | 10167 | $configCached=true; |
| 9537 | 10168 | $currentTimestamp=array(); |
@@ -9546,19 +10177,19 @@ discard block |
||
| 9546 | 10177 | if($fileName===0) { |
| 9547 | 10178 | $appConfigFile=$application->getConfigurationFile(); |
| 9548 | 10179 | $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); |
| 9549 | - if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0])) |
|
| 9550 | - $configCached=false; |
|
| 9551 | - } |
|
| 9552 | - else |
|
| 10180 | + if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0])) { |
|
| 10181 | + $configCached=false; |
|
| 10182 | + } |
|
| 10183 | + } else |
|
| 9553 | 10184 | { |
| 9554 | 10185 | $currentTimestamp[$fileName]=@filemtime($fileName); |
| 9555 | - if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName])) |
|
| 9556 | - $configCached=false; |
|
| 10186 | + if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName])) { |
|
| 10187 | + $configCached=false; |
|
| 10188 | + } |
|
| 9557 | 10189 | } |
| 9558 | 10190 | } |
| 9559 | 10191 | } |
| 9560 | - } |
|
| 9561 | - else |
|
| 10192 | + } else |
|
| 9562 | 10193 | { |
| 9563 | 10194 | $configCached=false; |
| 9564 | 10195 | $paths=explode('.',$pagePath); |
@@ -9580,10 +10211,11 @@ discard block |
||
| 9580 | 10211 | $pageConfig=new TPageConfiguration($pagePath); |
| 9581 | 10212 | if($config!==null) |
| 9582 | 10213 | { |
| 9583 | - if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
| 9584 | - $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
| 9585 | - else |
|
| 9586 | - $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
| 10214 | + if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) { |
|
| 10215 | + $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
| 10216 | + } else { |
|
| 10217 | + $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
| 10218 | + } |
|
| 9587 | 10219 | } |
| 9588 | 10220 | $pageConfig->loadFromFiles($this->getBasePath()); |
| 9589 | 10221 | $cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath,array($pageConfig,$currentTimestamp)); |
@@ -9622,8 +10254,9 @@ discard block |
||
| 9622 | 10254 | if($this->_pagePath===null) |
| 9623 | 10255 | { |
| 9624 | 10256 | $this->_pagePath=strtr($this->determineRequestedPagePath(),'/\\','..'); |
| 9625 | - if(empty($this->_pagePath)) |
|
| 9626 | - throw new THttpException(404,'pageservice_page_required'); |
|
| 10257 | + if(empty($this->_pagePath)) { |
|
| 10258 | + throw new THttpException(404,'pageservice_page_required'); |
|
| 10259 | + } |
|
| 9627 | 10260 | } |
| 9628 | 10261 | return $this->_pagePath; |
| 9629 | 10262 | } |
@@ -9637,10 +10270,11 @@ discard block |
||
| 9637 | 10270 | } |
| 9638 | 10271 | public function setDefaultPage($value) |
| 9639 | 10272 | { |
| 9640 | - if($this->_initialized) |
|
| 9641 | - throw new TInvalidOperationException('pageservice_defaultpage_unchangeable'); |
|
| 9642 | - else |
|
| 9643 | - $this->_defaultPage=$value; |
|
| 10273 | + if($this->_initialized) { |
|
| 10274 | + throw new TInvalidOperationException('pageservice_defaultpage_unchangeable'); |
|
| 10275 | + } else { |
|
| 10276 | + $this->_defaultPage=$value; |
|
| 10277 | + } |
|
| 9644 | 10278 | } |
| 9645 | 10279 | public function getDefaultPageUrl() |
| 9646 | 10280 | { |
@@ -9654,18 +10288,20 @@ discard block |
||
| 9654 | 10288 | if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) |
| 9655 | 10289 | { |
| 9656 | 10290 | $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::FALLBACK_BASEPATH; |
| 9657 | - if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) |
|
| 9658 | - throw new TConfigurationException('pageservice_basepath_invalid',$basePath); |
|
| 10291 | + if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) { |
|
| 10292 | + throw new TConfigurationException('pageservice_basepath_invalid',$basePath); |
|
| 10293 | + } |
|
| 9659 | 10294 | } |
| 9660 | 10295 | } |
| 9661 | 10296 | return $this->_basePath; |
| 9662 | 10297 | } |
| 9663 | 10298 | public function setBasePath($value) |
| 9664 | 10299 | { |
| 9665 | - if($this->_initialized) |
|
| 9666 | - throw new TInvalidOperationException('pageservice_basepath_unchangeable'); |
|
| 9667 | - else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path)) |
|
| 9668 | - throw new TConfigurationException('pageservice_basepath_invalid',$value); |
|
| 10300 | + if($this->_initialized) { |
|
| 10301 | + throw new TInvalidOperationException('pageservice_basepath_unchangeable'); |
|
| 10302 | + } else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path)) { |
|
| 10303 | + throw new TConfigurationException('pageservice_basepath_invalid',$value); |
|
| 10304 | + } |
|
| 9669 | 10305 | $this->_basePath=realpath($path); |
| 9670 | 10306 | } |
| 9671 | 10307 | public function setBasePageClass($value) |
@@ -9694,33 +10330,38 @@ discard block |
||
| 9694 | 10330 | $path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath,'.',DIRECTORY_SEPARATOR); |
| 9695 | 10331 | $hasTemplateFile=is_file($path.self::PAGE_FILE_EXT); |
| 9696 | 10332 | $hasClassFile=is_file($path.Prado::CLASS_FILE_EXT); |
| 9697 | - if(!$hasTemplateFile && !$hasClassFile) |
|
| 9698 | - throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
| 10333 | + if(!$hasTemplateFile && !$hasClassFile) { |
|
| 10334 | + throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
| 10335 | + } |
|
| 9699 | 10336 | if($hasClassFile) |
| 9700 | 10337 | { |
| 9701 | 10338 | $className=basename($path); |
| 9702 | - if(!class_exists($className,false)) |
|
| 9703 | - include_once($path.Prado::CLASS_FILE_EXT); |
|
| 9704 | - } |
|
| 9705 | - else |
|
| 10339 | + if(!class_exists($className,false)) { |
|
| 10340 | + include_once($path.Prado::CLASS_FILE_EXT); |
|
| 10341 | + } |
|
| 10342 | + } else |
|
| 9706 | 10343 | { |
| 9707 | 10344 | $className=$this->getBasePageClass(); |
| 9708 | 10345 | Prado::using($className); |
| 9709 | - if(($pos=strrpos($className,'.'))!==false) |
|
| 9710 | - $className=substr($className,$pos+1); |
|
| 10346 | + if(($pos=strrpos($className,'.'))!==false) { |
|
| 10347 | + $className=substr($className,$pos+1); |
|
| 10348 | + } |
|
| 9711 | 10349 | } |
| 9712 | - if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage'))) |
|
| 9713 | - throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
| 10350 | + if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage'))) { |
|
| 10351 | + throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
| 10352 | + } |
|
| 9714 | 10353 | $page=Prado::createComponent($className); |
| 9715 | 10354 | $page->setPagePath($pagePath); |
| 9716 | - if($hasTemplateFile) |
|
| 9717 | - $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT)); |
|
| 10355 | + if($hasTemplateFile) { |
|
| 10356 | + $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT)); |
|
| 10357 | + } |
|
| 9718 | 10358 | return $page; |
| 9719 | 10359 | } |
| 9720 | 10360 | protected function runPage($page,$properties) |
| 9721 | 10361 | { |
| 9722 | - foreach($properties as $name=>$value) |
|
| 9723 | - $page->setSubProperty($name,$value); |
|
| 10362 | + foreach($properties as $name=>$value) { |
|
| 10363 | + $page->setSubProperty($name,$value); |
|
| 10364 | + } |
|
| 9724 | 10365 | $page->run($this->getResponse()->createHtmlWriter()); |
| 9725 | 10366 | } |
| 9726 | 10367 | public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true) |
@@ -9768,30 +10409,32 @@ discard block |
||
| 9768 | 10409 | { |
| 9769 | 10410 | $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath); |
| 9770 | 10411 | $path.=DIRECTORY_SEPARATOR.$p; |
| 9771 | - if($configPagePath==='') |
|
| 9772 | - $configPagePath=$p; |
|
| 9773 | - else |
|
| 9774 | - $configPagePath.='.'.$p; |
|
| 10412 | + if($configPagePath==='') { |
|
| 10413 | + $configPagePath=$p; |
|
| 10414 | + } else { |
|
| 10415 | + $configPagePath.='.'.$p; |
|
| 10416 | + } |
|
| 9775 | 10417 | } |
| 9776 | 10418 | $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath); |
| 9777 | 10419 | $this->_rules=new TAuthorizationRuleCollection($this->_rules); |
| 9778 | 10420 | } |
| 9779 | 10421 | public function loadFromFile($fname,$configPagePath) |
| 9780 | 10422 | { |
| 9781 | - if(empty($fname) || !is_file($fname)) |
|
| 9782 | - return; |
|
| 10423 | + if(empty($fname) || !is_file($fname)) { |
|
| 10424 | + return; |
|
| 10425 | + } |
|
| 9783 | 10426 | if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
| 9784 | 10427 | { |
| 9785 | 10428 | $fcontent = include $fname; |
| 9786 | 10429 | $this->loadFromPhp($fcontent,dirname($fname),$configPagePath); |
| 9787 | - } |
|
| 9788 | - else |
|
| 10430 | + } else |
|
| 9789 | 10431 | { |
| 9790 | 10432 | $dom=new TXmlDocument; |
| 9791 | - if($dom->loadFromFile($fname)) |
|
| 9792 | - $this->loadFromXml($dom,dirname($fname),$configPagePath); |
|
| 9793 | - else |
|
| 9794 | - throw new TConfigurationException('pageserviceconf_file_invalid',$fname); |
|
| 10433 | + if($dom->loadFromFile($fname)) { |
|
| 10434 | + $this->loadFromXml($dom,dirname($fname),$configPagePath); |
|
| 10435 | + } else { |
|
| 10436 | + throw new TConfigurationException('pageserviceconf_file_invalid',$fname); |
|
| 10437 | + } |
|
| 9795 | 10438 | } |
| 9796 | 10439 | } |
| 9797 | 10440 | public function loadFromPhp($config,$configPath,$configPagePath) |
@@ -9825,14 +10468,17 @@ discard block |
||
| 9825 | 10468 | { |
| 9826 | 10469 | $patterns=isset($authorization['pages'])?$authorization['pages']:''; |
| 9827 | 10470 | $ruleApplies=false; |
| 9828 | - if(empty($patterns) || trim($patterns)==='*') $ruleApplies=true; |
|
| 9829 | - else |
|
| 10471 | + if(empty($patterns) || trim($patterns)==='*') { |
|
| 10472 | + $ruleApplies=true; |
|
| 10473 | + } else |
|
| 9830 | 10474 | { |
| 9831 | 10475 | foreach(explode(',',$patterns) as $pattern) |
| 9832 | 10476 | { |
| 9833 | 10477 | if(($pattern=trim($pattern))!=='') |
| 9834 | 10478 | { |
| 9835 | - if($configPagePath!=='') $pattern=$configPagePath.'.'.$pattern; |
|
| 10479 | + if($configPagePath!=='') { |
|
| 10480 | + $pattern=$configPagePath.'.'.$pattern; |
|
| 10481 | + } |
|
| 9836 | 10482 | if(strcasecmp($pattern,$this->_pagePath)===0) |
| 9837 | 10483 | { |
| 9838 | 10484 | $ruleApplies=true; |
@@ -9877,11 +10523,14 @@ discard block |
||
| 9877 | 10523 | } |
| 9878 | 10524 | $matching=false; |
| 9879 | 10525 | $id=($configPagePath==='')?$id:$configPagePath.'.'.$id; |
| 9880 | - if(strcasecmp($id,$this->_pagePath)===0) |
|
| 9881 | - $matching=true; |
|
| 9882 | - else if($id[strlen($id)-1]==='*') $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
|
| 9883 | - if($matching) |
|
| 9884 | - $this->_properties=array_merge($this->_properties,$properties); |
|
| 10526 | + if(strcasecmp($id,$this->_pagePath)===0) { |
|
| 10527 | + $matching=true; |
|
| 10528 | + } else if($id[strlen($id)-1]==='*') { |
|
| 10529 | + $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
|
| 10530 | + } |
|
| 10531 | + if($matching) { |
|
| 10532 | + $this->_properties=array_merge($this->_properties,$properties); |
|
| 10533 | + } |
|
| 9885 | 10534 | } |
| 9886 | 10535 | } |
| 9887 | 10536 | if(isset($config['includes']) && is_array($config['includes'])) |
@@ -9889,13 +10538,15 @@ discard block |
||
| 9889 | 10538 | foreach($config['includes'] as $include) |
| 9890 | 10539 | { |
| 9891 | 10540 | $when = isset($include['when'])?true:false; |
| 9892 | - if(!isset($include['file'])) |
|
| 9893 | - throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
| 10541 | + if(!isset($include['file'])) { |
|
| 10542 | + throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
| 10543 | + } |
|
| 9894 | 10544 | $filePath = $include['file']; |
| 9895 | - if(isset($this->_includes[$filePath])) |
|
| 9896 | - $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
| 9897 | - else |
|
| 9898 | - $this->_includes[$filePath]=array($configPagePath,$when); |
|
| 10545 | + if(isset($this->_includes[$filePath])) { |
|
| 10546 | + $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
| 10547 | + } else { |
|
| 10548 | + $this->_includes[$filePath]=array($configPagePath,$when); |
|
| 10549 | + } |
|
| 9899 | 10550 | } |
| 9900 | 10551 | } |
| 9901 | 10552 | } |
@@ -9908,14 +10559,17 @@ discard block |
||
| 9908 | 10559 | { |
| 9909 | 10560 | $patterns=$node->getAttribute('pages'); |
| 9910 | 10561 | $ruleApplies=false; |
| 9911 | - if(empty($patterns) || trim($patterns)==='*') $ruleApplies=true; |
|
| 9912 | - else |
|
| 10562 | + if(empty($patterns) || trim($patterns)==='*') { |
|
| 10563 | + $ruleApplies=true; |
|
| 10564 | + } else |
|
| 9913 | 10565 | { |
| 9914 | 10566 | foreach(explode(',',$patterns) as $pattern) |
| 9915 | 10567 | { |
| 9916 | 10568 | if(($pattern=trim($pattern))!=='') |
| 9917 | 10569 | { |
| 9918 | - if($configPagePath!=='') $pattern=$configPagePath.'.'.$pattern; |
|
| 10570 | + if($configPagePath!=='') { |
|
| 10571 | + $pattern=$configPagePath.'.'.$pattern; |
|
| 10572 | + } |
|
| 9919 | 10573 | if(strcasecmp($pattern,$this->_pagePath)===0) |
| 9920 | 10574 | { |
| 9921 | 10575 | $ruleApplies=true; |
@@ -9931,8 +10585,9 @@ discard block |
||
| 9931 | 10585 | } |
| 9932 | 10586 | } |
| 9933 | 10587 | } |
| 9934 | - if($ruleApplies) |
|
| 9935 | - $rules[]=new TAuthorizationRule($node->getTagName(),$node->getAttribute('users'),$node->getAttribute('roles'),$node->getAttribute('verb'),$node->getAttribute('ips')); |
|
| 10588 | + if($ruleApplies) { |
|
| 10589 | + $rules[]=new TAuthorizationRule($node->getTagName(),$node->getAttribute('users'),$node->getAttribute('roles'),$node->getAttribute('verb'),$node->getAttribute('ips')); |
|
| 10590 | + } |
|
| 9936 | 10591 | } |
| 9937 | 10592 | $this->_rules=array_merge($rules,$this->_rules); |
| 9938 | 10593 | } |
@@ -9943,27 +10598,34 @@ discard block |
||
| 9943 | 10598 | { |
| 9944 | 10599 | $properties=$node->getAttributes(); |
| 9945 | 10600 | $id=$properties->remove('id'); |
| 9946 | - if(empty($id)) |
|
| 9947 | - throw new TConfigurationException('pageserviceconf_page_invalid',$configPath); |
|
| 10601 | + if(empty($id)) { |
|
| 10602 | + throw new TConfigurationException('pageserviceconf_page_invalid',$configPath); |
|
| 10603 | + } |
|
| 9948 | 10604 | $matching=false; |
| 9949 | 10605 | $id=($configPagePath==='')?$id:$configPagePath.'.'.$id; |
| 9950 | - if(strcasecmp($id,$this->_pagePath)===0) |
|
| 9951 | - $matching=true; |
|
| 9952 | - else if($id[strlen($id)-1]==='*') $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
|
| 9953 | - if($matching) |
|
| 9954 | - $this->_properties=array_merge($this->_properties,$properties->toArray()); |
|
| 10606 | + if(strcasecmp($id,$this->_pagePath)===0) { |
|
| 10607 | + $matching=true; |
|
| 10608 | + } else if($id[strlen($id)-1]==='*') { |
|
| 10609 | + $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
|
| 10610 | + } |
|
| 10611 | + if($matching) { |
|
| 10612 | + $this->_properties=array_merge($this->_properties,$properties->toArray()); |
|
| 10613 | + } |
|
| 9955 | 10614 | } |
| 9956 | 10615 | } |
| 9957 | 10616 | foreach($dom->getElementsByTagName('include') as $node) |
| 9958 | 10617 | { |
| 9959 | - if(($when=$node->getAttribute('when'))===null) |
|
| 9960 | - $when=true; |
|
| 9961 | - if(($filePath=$node->getAttribute('file'))===null) |
|
| 9962 | - throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
| 9963 | - if(isset($this->_includes[$filePath])) |
|
| 9964 | - $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
| 9965 | - else |
|
| 9966 | - $this->_includes[$filePath]=array($configPagePath,$when); |
|
| 10618 | + if(($when=$node->getAttribute('when'))===null) { |
|
| 10619 | + $when=true; |
|
| 10620 | + } |
|
| 10621 | + if(($filePath=$node->getAttribute('file'))===null) { |
|
| 10622 | + throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
| 10623 | + } |
|
| 10624 | + if(isset($this->_includes[$filePath])) { |
|
| 10625 | + $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
| 10626 | + } else { |
|
| 10627 | + $this->_includes[$filePath]=array($configPagePath,$when); |
|
| 10628 | + } |
|
| 9967 | 10629 | } |
| 9968 | 10630 | } |
| 9969 | 10631 | } |
@@ -9979,12 +10641,15 @@ discard block |
||
| 9979 | 10641 | public function init($config) |
| 9980 | 10642 | { |
| 9981 | 10643 | $application=$this->getApplication(); |
| 9982 | - if($this->_basePath===null) |
|
| 9983 | - $this->_basePath=dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
|
| 9984 | - if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
| 9985 | - throw new TConfigurationException('assetmanager_basepath_invalid',$this->_basePath); |
|
| 9986 | - if($this->_baseUrl===null) |
|
| 9987 | - $this->_baseUrl=rtrim(dirname($application->getRequest()->getApplicationUrl()),'/\\').'/'.self::DEFAULT_BASEPATH; |
|
| 10644 | + if($this->_basePath===null) { |
|
| 10645 | + $this->_basePath=dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
|
| 10646 | + } |
|
| 10647 | + if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) { |
|
| 10648 | + throw new TConfigurationException('assetmanager_basepath_invalid',$this->_basePath); |
|
| 10649 | + } |
|
| 10650 | + if($this->_baseUrl===null) { |
|
| 10651 | + $this->_baseUrl=rtrim(dirname($application->getRequest()->getApplicationUrl()),'/\\').'/'.self::DEFAULT_BASEPATH; |
|
| 10652 | + } |
|
| 9988 | 10653 | $application->setAssetManager($this); |
| 9989 | 10654 | $this->_initialized=true; |
| 9990 | 10655 | } |
@@ -9994,13 +10659,14 @@ discard block |
||
| 9994 | 10659 | } |
| 9995 | 10660 | public function setBasePath($value) |
| 9996 | 10661 | { |
| 9997 | - if($this->_initialized) |
|
| 9998 | - throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
|
| 9999 | - else |
|
| 10662 | + if($this->_initialized) { |
|
| 10663 | + throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
|
| 10664 | + } else |
|
| 10000 | 10665 | { |
| 10001 | 10666 | $this->_basePath=Prado::getPathOfNamespace($value); |
| 10002 | - if($this->_basePath===null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
| 10003 | - throw new TInvalidDataValueException('assetmanager_basepath_invalid',$value); |
|
| 10667 | + if($this->_basePath===null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) { |
|
| 10668 | + throw new TInvalidDataValueException('assetmanager_basepath_invalid',$value); |
|
| 10669 | + } |
|
| 10004 | 10670 | } |
| 10005 | 10671 | } |
| 10006 | 10672 | public function getBaseUrl() |
@@ -10009,27 +10675,28 @@ discard block |
||
| 10009 | 10675 | } |
| 10010 | 10676 | public function setBaseUrl($value) |
| 10011 | 10677 | { |
| 10012 | - if($this->_initialized) |
|
| 10013 | - throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
|
| 10014 | - else |
|
| 10015 | - $this->_baseUrl=rtrim($value,'/'); |
|
| 10678 | + if($this->_initialized) { |
|
| 10679 | + throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
|
| 10680 | + } else { |
|
| 10681 | + $this->_baseUrl=rtrim($value,'/'); |
|
| 10682 | + } |
|
| 10016 | 10683 | } |
| 10017 | 10684 | public function publishFilePath($path,$checkTimestamp=false) |
| 10018 | 10685 | { |
| 10019 | - if(isset($this->_published[$path])) |
|
| 10020 | - return $this->_published[$path]; |
|
| 10021 | - else if(empty($path) || ($fullpath=realpath($path))===false) |
|
| 10022 | - throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path); |
|
| 10023 | - else if(is_file($fullpath)) |
|
| 10686 | + if(isset($this->_published[$path])) { |
|
| 10687 | + return $this->_published[$path]; |
|
| 10688 | + } else if(empty($path) || ($fullpath=realpath($path))===false) { |
|
| 10689 | + throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path); |
|
| 10690 | + } else if(is_file($fullpath)) |
|
| 10024 | 10691 | { |
| 10025 | 10692 | $dir=$this->hash(dirname($fullpath)); |
| 10026 | 10693 | $fileName=basename($fullpath); |
| 10027 | 10694 | $dst=$this->_basePath.DIRECTORY_SEPARATOR.$dir; |
| 10028 | - if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) |
|
| 10029 | - $this->copyFile($fullpath,$dst); |
|
| 10695 | + if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) { |
|
| 10696 | + $this->copyFile($fullpath,$dst); |
|
| 10697 | + } |
|
| 10030 | 10698 | return $this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.$fileName; |
| 10031 | - } |
|
| 10032 | - else |
|
| 10699 | + } else |
|
| 10033 | 10700 | { |
| 10034 | 10701 | $dir=$this->hash($fullpath); |
| 10035 | 10702 | if(!is_dir($this->_basePath.DIRECTORY_SEPARATOR.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) |
@@ -10050,18 +10717,20 @@ discard block |
||
| 10050 | 10717 | public function getPublishedPath($path) |
| 10051 | 10718 | { |
| 10052 | 10719 | $path=realpath($path); |
| 10053 | - if(is_file($path)) |
|
| 10054 | - return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path); |
|
| 10055 | - else |
|
| 10056 | - return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path); |
|
| 10720 | + if(is_file($path)) { |
|
| 10721 | + return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path); |
|
| 10722 | + } else { |
|
| 10723 | + return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path); |
|
| 10724 | + } |
|
| 10057 | 10725 | } |
| 10058 | 10726 | public function getPublishedUrl($path) |
| 10059 | 10727 | { |
| 10060 | 10728 | $path=realpath($path); |
| 10061 | - if(is_file($path)) |
|
| 10062 | - return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path); |
|
| 10063 | - else |
|
| 10064 | - return $this->_baseUrl.'/'.$this->hash($path); |
|
| 10729 | + if(is_file($path)) { |
|
| 10730 | + return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path); |
|
| 10731 | + } else { |
|
| 10732 | + return $this->_baseUrl.'/'.$this->hash($path); |
|
| 10733 | + } |
|
| 10065 | 10734 | } |
| 10066 | 10735 | protected function hash($dir) |
| 10067 | 10736 | { |
@@ -10091,18 +10760,18 @@ discard block |
||
| 10091 | 10760 | { |
| 10092 | 10761 | while($file=@readdir($folder)) |
| 10093 | 10762 | { |
| 10094 | - if($file==='.' || $file==='..' || $file==='.svn') |
|
| 10095 | - continue; |
|
| 10096 | - else if(is_file($src.DIRECTORY_SEPARATOR.$file)) |
|
| 10763 | + if($file==='.' || $file==='..' || $file==='.svn') { |
|
| 10764 | + continue; |
|
| 10765 | + } else if(is_file($src.DIRECTORY_SEPARATOR.$file)) |
|
| 10097 | 10766 | { |
| 10098 | 10767 | if(@filemtime($dst.DIRECTORY_SEPARATOR.$file)<@filemtime($src.DIRECTORY_SEPARATOR.$file)) |
| 10099 | 10768 | { |
| 10100 | 10769 | @copy($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file); |
| 10101 | 10770 | @chmod($dst.DIRECTORY_SEPARATOR.$file, PRADO_CHMOD); |
| 10102 | 10771 | } |
| 10772 | + } else { |
|
| 10773 | + $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file); |
|
| 10103 | 10774 | } |
| 10104 | - else |
|
| 10105 | - $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file); |
|
| 10106 | 10775 | } |
| 10107 | 10776 | closedir($folder); |
| 10108 | 10777 | } else { |
@@ -10111,11 +10780,11 @@ discard block |
||
| 10111 | 10780 | } |
| 10112 | 10781 | public function publishTarFile($tarfile, $md5sum, $checkTimestamp=false) |
| 10113 | 10782 | { |
| 10114 | - if(isset($this->_published[$md5sum])) |
|
| 10115 | - return $this->_published[$md5sum]; |
|
| 10116 | - else if(($fullpath=realpath($md5sum))===false || !is_file($fullpath)) |
|
| 10117 | - throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid',$md5sum); |
|
| 10118 | - else |
|
| 10783 | + if(isset($this->_published[$md5sum])) { |
|
| 10784 | + return $this->_published[$md5sum]; |
|
| 10785 | + } else if(($fullpath=realpath($md5sum))===false || !is_file($fullpath)) { |
|
| 10786 | + throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid',$md5sum); |
|
| 10787 | + } else |
|
| 10119 | 10788 | { |
| 10120 | 10789 | $dir=$this->hash(dirname($fullpath)); |
| 10121 | 10790 | $fileName=basename($fullpath); |
@@ -10133,9 +10802,9 @@ discard block |
||
| 10133 | 10802 | } |
| 10134 | 10803 | protected function deployTarFile($path,$destination) |
| 10135 | 10804 | { |
| 10136 | - if(($fullpath=realpath($path))===false || !is_file($fullpath)) |
|
| 10137 | - throw new TIOException('assetmanager_tarfile_invalid',$path); |
|
| 10138 | - else |
|
| 10805 | + if(($fullpath=realpath($path))===false || !is_file($fullpath)) { |
|
| 10806 | + throw new TIOException('assetmanager_tarfile_invalid',$path); |
|
| 10807 | + } else |
|
| 10139 | 10808 | { |
| 10140 | 10809 | Prado::using('System.IO.TTarFileExtractor'); |
| 10141 | 10810 | $tar = new TTarFileExtractor($fullpath); |
@@ -10153,21 +10822,24 @@ discard block |
||
| 10153 | 10822 | private $_translateDefaultCulture=true; |
| 10154 | 10823 | public function init($config) |
| 10155 | 10824 | { |
| 10156 | - if($this->_charset===null) |
|
| 10157 | - $this->_charset=$this->getDefaultCharset(); |
|
| 10158 | - if($this->_culture===null) |
|
| 10159 | - $this->_culture=$this->getDefaultCulture(); |
|
| 10825 | + if($this->_charset===null) { |
|
| 10826 | + $this->_charset=$this->getDefaultCharset(); |
|
| 10827 | + } |
|
| 10828 | + if($this->_culture===null) { |
|
| 10829 | + $this->_culture=$this->getDefaultCulture(); |
|
| 10830 | + } |
|
| 10160 | 10831 | if($config!==null) |
| 10161 | 10832 | { |
| 10162 | - if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
| 10163 | - $translation = isset($config['translate'])?$config['translate']:null; |
|
| 10164 | - else |
|
| 10833 | + if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) { |
|
| 10834 | + $translation = isset($config['translate'])?$config['translate']:null; |
|
| 10835 | + } else |
|
| 10165 | 10836 | { |
| 10166 | 10837 | $t = $config->getElementByTagName('translation'); |
| 10167 | 10838 | $translation = ($t)?$t->getAttributes():null; |
| 10168 | 10839 | } |
| 10169 | - if($translation) |
|
| 10170 | - $this->setTranslationConfiguration($translation); |
|
| 10840 | + if($translation) { |
|
| 10841 | + $this->setTranslationConfiguration($translation); |
|
| 10842 | + } |
|
| 10171 | 10843 | } |
| 10172 | 10844 | $this->getApplication()->setGlobalization($this); |
| 10173 | 10845 | } |
@@ -10226,12 +10898,12 @@ discard block |
||
| 10226 | 10898 | $config['source'] = Prado::getPathOfNamespace($config['source']); |
| 10227 | 10899 | if(!is_dir($config['source'])) |
| 10228 | 10900 | { |
| 10229 | - if(@mkdir($config['source'])===false) |
|
| 10230 | - throw new TConfigurationException('globalization_source_path_failed', |
|
| 10901 | + if(@mkdir($config['source'])===false) { |
|
| 10902 | + throw new TConfigurationException('globalization_source_path_failed', |
|
| 10231 | 10903 | $config['source']); |
| 10904 | + } |
|
| 10232 | 10905 | chmod($config['source'], PRADO_CHMOD); } |
| 10233 | - } |
|
| 10234 | - else |
|
| 10906 | + } else |
|
| 10235 | 10907 | { |
| 10236 | 10908 | throw new TConfigurationException("invalid source dir '{$config['source']}'"); |
| 10237 | 10909 | } |
@@ -10241,9 +10913,10 @@ discard block |
||
| 10241 | 10913 | $config['cache'] = $this->getApplication()->getRunTimePath().'/i18n'; |
| 10242 | 10914 | if(!is_dir($config['cache'])) |
| 10243 | 10915 | { |
| 10244 | - if(@mkdir($config['cache'])===false) |
|
| 10245 | - throw new TConfigurationException('globalization_cache_path_failed', |
|
| 10916 | + if(@mkdir($config['cache'])===false) { |
|
| 10917 | + throw new TConfigurationException('globalization_cache_path_failed', |
|
| 10246 | 10918 | $config['cache']); |
| 10919 | + } |
|
| 10247 | 10920 | chmod($config['cache'], PRADO_CHMOD); } |
| 10248 | 10921 | } |
| 10249 | 10922 | $this->_translation = $config; |
@@ -10258,11 +10931,14 @@ discard block |
||
| 10258 | 10931 | } |
| 10259 | 10932 | public function getCultureVariants($culture=null) |
| 10260 | 10933 | { |
| 10261 | - if($culture===null) $culture = $this->getCulture(); |
|
| 10934 | + if($culture===null) { |
|
| 10935 | + $culture = $this->getCulture(); |
|
| 10936 | + } |
|
| 10262 | 10937 | $variants = explode('_', $culture); |
| 10263 | 10938 | $result = array(); |
| 10264 | - for(; count($variants) > 0; array_pop($variants)) |
|
| 10265 | - $result[] = implode('_', $variants); |
|
| 10939 | + for(; count($variants) > 0; array_pop($variants)) { |
|
| 10940 | + $result[] = implode('_', $variants); |
|
| 10941 | + } |
|
| 10266 | 10942 | return $result; |
| 10267 | 10943 | } |
| 10268 | 10944 | public function getLocalizedResource($file,$culture=null) |
@@ -10270,11 +10946,13 @@ discard block |
||
| 10270 | 10946 | $files = array(); |
| 10271 | 10947 | $variants = $this->getCultureVariants($culture); |
| 10272 | 10948 | $path = pathinfo($file); |
| 10273 | - foreach($variants as $variant) |
|
| 10274 | - $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$variant.DIRECTORY_SEPARATOR.$path['basename']; |
|
| 10949 | + foreach($variants as $variant) { |
|
| 10950 | + $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$variant.DIRECTORY_SEPARATOR.$path['basename']; |
|
| 10951 | + } |
|
| 10275 | 10952 | $filename = substr($path['basename'],0,strrpos($path['basename'],'.')); |
| 10276 | - foreach($variants as $variant) |
|
| 10277 | - $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$filename.'.'.$variant.'.'.$path['extension']; |
|
| 10953 | + foreach($variants as $variant) { |
|
| 10954 | + $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$filename.'.'.$variant.'.'.$path['extension']; |
|
| 10955 | + } |
|
| 10278 | 10956 | $files[] = $file; |
| 10279 | 10957 | return $files; |
| 10280 | 10958 | } |
@@ -10345,8 +11023,9 @@ discard block |
||
| 10345 | 11023 | Prado::setApplication($this); |
| 10346 | 11024 | $this->setConfigurationType($configType); |
| 10347 | 11025 | $this->resolvePaths($basePath); |
| 10348 | - if($cacheConfig) |
|
| 10349 | - $this->_cacheFile=$this->_runtimePath.DIRECTORY_SEPARATOR.self::CONFIGCACHE_FILE; |
|
| 11026 | + if($cacheConfig) { |
|
| 11027 | + $this->_cacheFile=$this->_runtimePath.DIRECTORY_SEPARATOR.self::CONFIGCACHE_FILE; |
|
| 11028 | + } |
|
| 10350 | 11029 | $this->_uniqueID=md5($this->_runtimePath); |
| 10351 | 11030 | $this->_parameters=new TMap; |
| 10352 | 11031 | $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
@@ -10354,17 +11033,18 @@ discard block |
||
| 10354 | 11033 | } |
| 10355 | 11034 | protected function resolvePaths($basePath) |
| 10356 | 11035 | { |
| 10357 | - if(empty($basePath) || ($basePath=realpath($basePath))===false) |
|
| 10358 | - throw new TConfigurationException('application_basepath_invalid',$basePath); |
|
| 10359 | - if(is_dir($basePath) && is_file($basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName())) |
|
| 10360 | - $configFile=$basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName(); |
|
| 10361 | - else if(is_file($basePath)) |
|
| 11036 | + if(empty($basePath) || ($basePath=realpath($basePath))===false) { |
|
| 11037 | + throw new TConfigurationException('application_basepath_invalid',$basePath); |
|
| 11038 | + } |
|
| 11039 | + if(is_dir($basePath) && is_file($basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName())) { |
|
| 11040 | + $configFile=$basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName(); |
|
| 11041 | + } else if(is_file($basePath)) |
|
| 10362 | 11042 | { |
| 10363 | 11043 | $configFile=$basePath; |
| 10364 | 11044 | $basePath=dirname($configFile); |
| 11045 | + } else { |
|
| 11046 | + $configFile=null; |
|
| 10365 | 11047 | } |
| 10366 | - else |
|
| 10367 | - $configFile=null; |
|
| 10368 | 11048 | $runtimePath=$basePath.DIRECTORY_SEPARATOR.self::RUNTIME_PATH; |
| 10369 | 11049 | if(is_writable($runtimePath)) |
| 10370 | 11050 | { |
@@ -10373,16 +11053,17 @@ discard block |
||
| 10373 | 11053 | $runtimePath.=DIRECTORY_SEPARATOR.basename($configFile).'-'.Prado::getVersion(); |
| 10374 | 11054 | if(!is_dir($runtimePath)) |
| 10375 | 11055 | { |
| 10376 | - if(@mkdir($runtimePath)===false) |
|
| 10377 | - throw new TConfigurationException('application_runtimepath_failed',$runtimePath); |
|
| 11056 | + if(@mkdir($runtimePath)===false) { |
|
| 11057 | + throw new TConfigurationException('application_runtimepath_failed',$runtimePath); |
|
| 11058 | + } |
|
| 10378 | 11059 | @chmod($runtimePath, PRADO_CHMOD); } |
| 10379 | 11060 | $this->setConfigurationFile($configFile); |
| 10380 | 11061 | } |
| 10381 | 11062 | $this->setBasePath($basePath); |
| 10382 | 11063 | $this->setRuntimePath($runtimePath); |
| 11064 | + } else { |
|
| 11065 | + throw new TConfigurationException('application_runtimepath_invalid',$runtimePath); |
|
| 10383 | 11066 | } |
| 10384 | - else |
|
| 10385 | - throw new TConfigurationException('application_runtimepath_invalid',$runtimePath); |
|
| 10386 | 11067 | } |
| 10387 | 11068 | public function run() |
| 10388 | 11069 | { |
@@ -10394,16 +11075,17 @@ discard block |
||
| 10394 | 11075 | $this->_requestCompleted=false; |
| 10395 | 11076 | while($this->_step<$n) |
| 10396 | 11077 | { |
| 10397 | - if($this->_mode===self::STATE_OFF) |
|
| 10398 | - throw new THttpException(503,'application_unavailable'); |
|
| 10399 | - if($this->_requestCompleted) |
|
| 10400 | - break; |
|
| 11078 | + if($this->_mode===self::STATE_OFF) { |
|
| 11079 | + throw new THttpException(503,'application_unavailable'); |
|
| 11080 | + } |
|
| 11081 | + if($this->_requestCompleted) { |
|
| 11082 | + break; |
|
| 11083 | + } |
|
| 10401 | 11084 | $method=self::$_steps[$this->_step]; |
| 10402 | 11085 | $this->$method(); |
| 10403 | 11086 | $this->_step++; |
| 10404 | 11087 | } |
| 10405 | - } |
|
| 10406 | - catch(Exception $e) |
|
| 11088 | + } catch(Exception $e) |
|
| 10407 | 11089 | { |
| 10408 | 11090 | $this->onError($e); |
| 10409 | 11091 | } |
@@ -10424,12 +11106,14 @@ discard block |
||
| 10424 | 11106 | public function setGlobalState($key,$value,$defaultValue=null,$forceSave=false) |
| 10425 | 11107 | { |
| 10426 | 11108 | $this->_stateChanged=true; |
| 10427 | - if($value===$defaultValue) |
|
| 10428 | - unset($this->_globals[$key]); |
|
| 10429 | - else |
|
| 10430 | - $this->_globals[$key]=$value; |
|
| 10431 | - if($forceSave) |
|
| 10432 | - $this->saveGlobals(); |
|
| 11109 | + if($value===$defaultValue) { |
|
| 11110 | + unset($this->_globals[$key]); |
|
| 11111 | + } else { |
|
| 11112 | + $this->_globals[$key]=$value; |
|
| 11113 | + } |
|
| 11114 | + if($forceSave) { |
|
| 11115 | + $this->saveGlobals(); |
|
| 11116 | + } |
|
| 10433 | 11117 | } |
| 10434 | 11118 | public function clearGlobalState($key) |
| 10435 | 11119 | { |
@@ -10538,8 +11222,9 @@ discard block |
||
| 10538 | 11222 | public function setRuntimePath($value) |
| 10539 | 11223 | { |
| 10540 | 11224 | $this->_runtimePath=$value; |
| 10541 | - if($this->_cacheFile) |
|
| 10542 | - $this->_cacheFile=$this->_runtimePath.DIRECTORY_SEPARATOR.self::CONFIGCACHE_FILE; |
|
| 11225 | + if($this->_cacheFile) { |
|
| 11226 | + $this->_cacheFile=$this->_runtimePath.DIRECTORY_SEPARATOR.self::CONFIGCACHE_FILE; |
|
| 11227 | + } |
|
| 10543 | 11228 | $this->_uniqueID=md5($this->_runtimePath); |
| 10544 | 11229 | } |
| 10545 | 11230 | public function getService() |
@@ -10552,15 +11237,17 @@ discard block |
||
| 10552 | 11237 | } |
| 10553 | 11238 | public function setModule($id,IModule $module=null) |
| 10554 | 11239 | { |
| 10555 | - if(isset($this->_modules[$id])) |
|
| 10556 | - throw new TConfigurationException('application_moduleid_duplicated',$id); |
|
| 10557 | - else |
|
| 10558 | - $this->_modules[$id]=$module; |
|
| 11240 | + if(isset($this->_modules[$id])) { |
|
| 11241 | + throw new TConfigurationException('application_moduleid_duplicated',$id); |
|
| 11242 | + } else { |
|
| 11243 | + $this->_modules[$id]=$module; |
|
| 11244 | + } |
|
| 10559 | 11245 | } |
| 10560 | 11246 | public function getModule($id) |
| 10561 | 11247 | { |
| 10562 | - if(!array_key_exists($id, $this->_modules)) |
|
| 10563 | - return null; |
|
| 11248 | + if(!array_key_exists($id, $this->_modules)) { |
|
| 11249 | + return null; |
|
| 11250 | + } |
|
| 10564 | 11251 | if($this->_modules[$id]===null) |
| 10565 | 11252 | { |
| 10566 | 11253 | $module = $this->internalLoadModule($id, true); |
@@ -10698,8 +11385,9 @@ discard block |
||
| 10698 | 11385 | } |
| 10699 | 11386 | public function getAuthorizationRules() |
| 10700 | 11387 | { |
| 10701 | - if($this->_authRules===null) |
|
| 10702 | - $this->_authRules=new TAuthorizationRuleCollection; |
|
| 11388 | + if($this->_authRules===null) { |
|
| 11389 | + $this->_authRules=new TAuthorizationRuleCollection; |
|
| 11390 | + } |
|
| 10703 | 11391 | return $this->_authRules; |
| 10704 | 11392 | } |
| 10705 | 11393 | protected function getApplicationConfigurationClass() |
@@ -10717,7 +11405,9 @@ discard block |
||
| 10717 | 11405 | $module=Prado::createComponent($moduleClass); |
| 10718 | 11406 | foreach($initProperties as $name=>$value) |
| 10719 | 11407 | { |
| 10720 | - if($name==='lazy') continue; |
|
| 11408 | + if($name==='lazy') { |
|
| 11409 | + continue; |
|
| 11410 | + } |
|
| 10721 | 11411 | $module->setSubProperty($name,$value); |
| 10722 | 11412 | } |
| 10723 | 11413 | $this->setModule($id,$module); |
@@ -10726,52 +11416,64 @@ discard block |
||
| 10726 | 11416 | } |
| 10727 | 11417 | public function applyConfiguration($config,$withinService=false) |
| 10728 | 11418 | { |
| 10729 | - if($config->getIsEmpty()) |
|
| 10730 | - return; |
|
| 10731 | - foreach($config->getAliases() as $alias=>$path) |
|
| 10732 | - Prado::setPathOfAlias($alias,$path); |
|
| 10733 | - foreach($config->getUsings() as $using) |
|
| 10734 | - Prado::using($using); |
|
| 11419 | + if($config->getIsEmpty()) { |
|
| 11420 | + return; |
|
| 11421 | + } |
|
| 11422 | + foreach($config->getAliases() as $alias=>$path) { |
|
| 11423 | + Prado::setPathOfAlias($alias,$path); |
|
| 11424 | + } |
|
| 11425 | + foreach($config->getUsings() as $using) { |
|
| 11426 | + Prado::using($using); |
|
| 11427 | + } |
|
| 10735 | 11428 | if(!$withinService) |
| 10736 | 11429 | { |
| 10737 | - foreach($config->getProperties() as $name=>$value) |
|
| 10738 | - $this->setSubProperty($name,$value); |
|
| 11430 | + foreach($config->getProperties() as $name=>$value) { |
|
| 11431 | + $this->setSubProperty($name,$value); |
|
| 11432 | + } |
|
| 11433 | + } |
|
| 11434 | + if(empty($this->_services)) { |
|
| 11435 | + $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
|
| 10739 | 11436 | } |
| 10740 | - if(empty($this->_services)) |
|
| 10741 | - $this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null)); |
|
| 10742 | 11437 | foreach($config->getParameters() as $id=>$parameter) |
| 10743 | 11438 | { |
| 10744 | 11439 | if(is_array($parameter)) |
| 10745 | 11440 | { |
| 10746 | 11441 | $component=Prado::createComponent($parameter[0]); |
| 10747 | - foreach($parameter[1] as $name=>$value) |
|
| 10748 | - $component->setSubProperty($name,$value); |
|
| 11442 | + foreach($parameter[1] as $name=>$value) { |
|
| 11443 | + $component->setSubProperty($name,$value); |
|
| 11444 | + } |
|
| 10749 | 11445 | $this->_parameters->add($id,$component); |
| 11446 | + } else { |
|
| 11447 | + $this->_parameters->add($id,$parameter); |
|
| 10750 | 11448 | } |
| 10751 | - else |
|
| 10752 | - $this->_parameters->add($id,$parameter); |
|
| 10753 | 11449 | } |
| 10754 | 11450 | $modules=array(); |
| 10755 | 11451 | foreach($config->getModules() as $id=>$moduleConfig) |
| 10756 | 11452 | { |
| 10757 | - if(!is_string($id)) |
|
| 10758 | - $id='_module'.count($this->_lazyModules); |
|
| 11453 | + if(!is_string($id)) { |
|
| 11454 | + $id='_module'.count($this->_lazyModules); |
|
| 11455 | + } |
|
| 10759 | 11456 | $this->_lazyModules[$id]=$moduleConfig; |
| 10760 | - if($module = $this->internalLoadModule($id)) |
|
| 10761 | - $modules[]=$module; |
|
| 11457 | + if($module = $this->internalLoadModule($id)) { |
|
| 11458 | + $modules[]=$module; |
|
| 11459 | + } |
|
| 10762 | 11460 | } |
| 10763 | - foreach($modules as $module) |
|
| 10764 | - $module[0]->init($module[1]); |
|
| 10765 | - foreach($config->getServices() as $serviceID=>$serviceConfig) |
|
| 10766 | - $this->_services[$serviceID]=$serviceConfig; |
|
| 11461 | + foreach($modules as $module) { |
|
| 11462 | + $module[0]->init($module[1]); |
|
| 11463 | + } |
|
| 11464 | + foreach($config->getServices() as $serviceID=>$serviceConfig) { |
|
| 11465 | + $this->_services[$serviceID]=$serviceConfig; |
|
| 11466 | + } |
|
| 10767 | 11467 | foreach($config->getExternalConfigurations() as $filePath=>$condition) |
| 10768 | 11468 | { |
| 10769 | - if($condition!==true) |
|
| 10770 | - $condition=$this->evaluateExpression($condition); |
|
| 11469 | + if($condition!==true) { |
|
| 11470 | + $condition=$this->evaluateExpression($condition); |
|
| 11471 | + } |
|
| 10771 | 11472 | if($condition) |
| 10772 | 11473 | { |
| 10773 | - if(($path=Prado::getPathOfNamespace($filePath,$this->getConfigurationFileExt()))===null || !is_file($path)) |
|
| 10774 | - throw new TConfigurationException('application_includefile_invalid',$filePath); |
|
| 11474 | + if(($path=Prado::getPathOfNamespace($filePath,$this->getConfigurationFileExt()))===null || !is_file($path)) { |
|
| 11475 | + throw new TConfigurationException('application_includefile_invalid',$filePath); |
|
| 11476 | + } |
|
| 10775 | 11477 | $cn=$this->getApplicationConfigurationClass(); |
| 10776 | 11478 | $c=new $cn; |
| 10777 | 11479 | $c->loadFromFile($path); |
@@ -10787,15 +11489,17 @@ discard block |
||
| 10787 | 11489 | { |
| 10788 | 11490 | $config=new TApplicationConfiguration; |
| 10789 | 11491 | $config->loadFromFile($this->_configFile); |
| 10790 | - if($this->_cacheFile!==null) |
|
| 10791 | - file_put_contents($this->_cacheFile,serialize($config),LOCK_EX); |
|
| 11492 | + if($this->_cacheFile!==null) { |
|
| 11493 | + file_put_contents($this->_cacheFile,serialize($config),LOCK_EX); |
|
| 11494 | + } |
|
| 11495 | + } else { |
|
| 11496 | + $config=unserialize(file_get_contents($this->_cacheFile)); |
|
| 10792 | 11497 | } |
| 10793 | - else |
|
| 10794 | - $config=unserialize(file_get_contents($this->_cacheFile)); |
|
| 10795 | 11498 | $this->applyConfiguration($config,false); |
| 10796 | 11499 | } |
| 10797 | - if(($serviceID=$this->getRequest()->resolveRequest(array_keys($this->_services)))===null) |
|
| 10798 | - $serviceID=$this->getPageServiceID(); |
|
| 11500 | + if(($serviceID=$this->getRequest()->resolveRequest(array_keys($this->_services)))===null) { |
|
| 11501 | + $serviceID=$this->getPageServiceID(); |
|
| 11502 | + } |
|
| 10799 | 11503 | $this->startService($serviceID); |
| 10800 | 11504 | } |
| 10801 | 11505 | public function startService($serviceID) |
@@ -10804,27 +11508,31 @@ discard block |
||
| 10804 | 11508 | { |
| 10805 | 11509 | list($serviceClass,$initProperties,$configElement)=$this->_services[$serviceID]; |
| 10806 | 11510 | $service=Prado::createComponent($serviceClass); |
| 10807 | - if(!($service instanceof IService)) |
|
| 10808 | - throw new THttpException(500,'application_service_invalid',$serviceClass); |
|
| 10809 | - if(!$service->getEnabled()) |
|
| 10810 | - throw new THttpException(500,'application_service_unavailable',$serviceClass); |
|
| 11511 | + if(!($service instanceof IService)) { |
|
| 11512 | + throw new THttpException(500,'application_service_invalid',$serviceClass); |
|
| 11513 | + } |
|
| 11514 | + if(!$service->getEnabled()) { |
|
| 11515 | + throw new THttpException(500,'application_service_unavailable',$serviceClass); |
|
| 11516 | + } |
|
| 10811 | 11517 | $service->setID($serviceID); |
| 10812 | 11518 | $this->setService($service); |
| 10813 | - foreach($initProperties as $name=>$value) |
|
| 10814 | - $service->setSubProperty($name,$value); |
|
| 11519 | + foreach($initProperties as $name=>$value) { |
|
| 11520 | + $service->setSubProperty($name,$value); |
|
| 11521 | + } |
|
| 10815 | 11522 | if($configElement!==null) |
| 10816 | 11523 | { |
| 10817 | 11524 | $config=new TApplicationConfiguration; |
| 10818 | - if($this->getConfigurationType()==self::CONFIG_TYPE_PHP) |
|
| 10819 | - $config->loadFromPhp($configElement,$this->getBasePath()); |
|
| 10820 | - else |
|
| 10821 | - $config->loadFromXml($configElement,$this->getBasePath()); |
|
| 11525 | + if($this->getConfigurationType()==self::CONFIG_TYPE_PHP) { |
|
| 11526 | + $config->loadFromPhp($configElement,$this->getBasePath()); |
|
| 11527 | + } else { |
|
| 11528 | + $config->loadFromXml($configElement,$this->getBasePath()); |
|
| 11529 | + } |
|
| 10822 | 11530 | $this->applyConfiguration($config,true); |
| 10823 | 11531 | } |
| 10824 | 11532 | $service->init($configElement); |
| 11533 | + } else { |
|
| 11534 | + throw new THttpException(500,'application_service_unknown',$serviceID); |
|
| 10825 | 11535 | } |
| 10826 | - else |
|
| 10827 | - throw new THttpException(500,'application_service_unknown',$serviceID); |
|
| 10828 | 11536 | } |
| 10829 | 11537 | public function onError($param) |
| 10830 | 11538 | { |
@@ -10867,8 +11575,9 @@ discard block |
||
| 10867 | 11575 | } |
| 10868 | 11576 | public function runService() |
| 10869 | 11577 | { |
| 10870 | - if($this->_service) |
|
| 10871 | - $this->_service->run(); |
|
| 11578 | + if($this->_service) { |
|
| 11579 | + $this->_service->run(); |
|
| 11580 | + } |
|
| 10872 | 11581 | } |
| 10873 | 11582 | public function onSaveState() |
| 10874 | 11583 | { |
@@ -10915,8 +11624,7 @@ discard block |
||
| 10915 | 11624 | { |
| 10916 | 11625 | $fcontent = include $fname; |
| 10917 | 11626 | $this->loadFromPhp($fcontent,dirname($fname)); |
| 10918 | - } |
|
| 10919 | - else |
|
| 11627 | + } else |
|
| 10920 | 11628 | { |
| 10921 | 11629 | $dom=new TXmlDocument; |
| 10922 | 11630 | $dom->loadFromFile($fname); |
@@ -10937,16 +11645,21 @@ discard block |
||
| 10937 | 11645 | } |
| 10938 | 11646 | $this->_empty = false; |
| 10939 | 11647 | } |
| 10940 | - if(isset($config['paths']) && is_array($config['paths'])) |
|
| 10941 | - $this->loadPathsPhp($config['paths'],$configPath); |
|
| 10942 | - if(isset($config['modules']) && is_array($config['modules'])) |
|
| 10943 | - $this->loadModulesPhp($config['modules'],$configPath); |
|
| 10944 | - if(isset($config['services']) && is_array($config['services'])) |
|
| 10945 | - $this->loadServicesPhp($config['services'],$configPath); |
|
| 10946 | - if(isset($config['parameters']) && is_array($config['parameters'])) |
|
| 10947 | - $this->loadParametersPhp($config['parameters'], $configPath); |
|
| 10948 | - if(isset($config['includes']) && is_array($config['includes'])) |
|
| 10949 | - $this->loadExternalXml($config['includes'],$configPath); |
|
| 11648 | + if(isset($config['paths']) && is_array($config['paths'])) { |
|
| 11649 | + $this->loadPathsPhp($config['paths'],$configPath); |
|
| 11650 | + } |
|
| 11651 | + if(isset($config['modules']) && is_array($config['modules'])) { |
|
| 11652 | + $this->loadModulesPhp($config['modules'],$configPath); |
|
| 11653 | + } |
|
| 11654 | + if(isset($config['services']) && is_array($config['services'])) { |
|
| 11655 | + $this->loadServicesPhp($config['services'],$configPath); |
|
| 11656 | + } |
|
| 11657 | + if(isset($config['parameters']) && is_array($config['parameters'])) { |
|
| 11658 | + $this->loadParametersPhp($config['parameters'], $configPath); |
|
| 11659 | + } |
|
| 11660 | + if(isset($config['includes']) && is_array($config['includes'])) { |
|
| 11661 | + $this->loadExternalXml($config['includes'],$configPath); |
|
| 11662 | + } |
|
| 10950 | 11663 | } |
| 10951 | 11664 | public function loadFromXml($dom,$configPath) |
| 10952 | 11665 | { |
@@ -10986,13 +11699,17 @@ discard block |
||
| 10986 | 11699 | foreach($pathsNode['aliases'] as $id=>$path) |
| 10987 | 11700 | { |
| 10988 | 11701 | $path=str_replace('\\','/',$path); |
| 10989 | - if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) $p=realpath($path); |
|
| 10990 | - else |
|
| 10991 | - $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
|
| 10992 | - if($p===false || !is_dir($p)) |
|
| 10993 | - throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
| 10994 | - if(isset($this->_aliases[$id])) |
|
| 10995 | - throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
| 11702 | + if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) { |
|
| 11703 | + $p=realpath($path); |
|
| 11704 | + } else { |
|
| 11705 | + $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
|
| 11706 | + } |
|
| 11707 | + if($p===false || !is_dir($p)) { |
|
| 11708 | + throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
| 11709 | + } |
|
| 11710 | + if(isset($this->_aliases[$id])) { |
|
| 11711 | + throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
| 11712 | + } |
|
| 10996 | 11713 | $this->_aliases[$id]=$p; |
| 10997 | 11714 | } |
| 10998 | 11715 | } |
@@ -11015,26 +11732,31 @@ discard block |
||
| 11015 | 11732 | if(($id=$element->getAttribute('id'))!==null && ($path=$element->getAttribute('path'))!==null) |
| 11016 | 11733 | { |
| 11017 | 11734 | $path=str_replace('\\','/',$path); |
| 11018 | - if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) $p=realpath($path); |
|
| 11019 | - else |
|
| 11020 | - $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
|
| 11021 | - if($p===false || !is_dir($p)) |
|
| 11022 | - throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
| 11023 | - if(isset($this->_aliases[$id])) |
|
| 11024 | - throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
| 11735 | + if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) { |
|
| 11736 | + $p=realpath($path); |
|
| 11737 | + } else { |
|
| 11738 | + $p=realpath($configPath.DIRECTORY_SEPARATOR.$path); |
|
| 11739 | + } |
|
| 11740 | + if($p===false || !is_dir($p)) { |
|
| 11741 | + throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path); |
|
| 11742 | + } |
|
| 11743 | + if(isset($this->_aliases[$id])) { |
|
| 11744 | + throw new TConfigurationException('appconfig_alias_redefined',$id); |
|
| 11745 | + } |
|
| 11025 | 11746 | $this->_aliases[$id]=$p; |
| 11747 | + } else { |
|
| 11748 | + throw new TConfigurationException('appconfig_alias_invalid'); |
|
| 11026 | 11749 | } |
| 11027 | - else |
|
| 11028 | - throw new TConfigurationException('appconfig_alias_invalid'); |
|
| 11029 | 11750 | $this->_empty=false; |
| 11030 | 11751 | break; |
| 11031 | 11752 | } |
| 11032 | 11753 | case 'using': |
| 11033 | 11754 | { |
| 11034 | - if(($namespace=$element->getAttribute('namespace'))!==null) |
|
| 11035 | - $this->_usings[]=$namespace; |
|
| 11036 | - else |
|
| 11037 | - throw new TConfigurationException('appconfig_using_invalid'); |
|
| 11755 | + if(($namespace=$element->getAttribute('namespace'))!==null) { |
|
| 11756 | + $this->_usings[]=$namespace; |
|
| 11757 | + } else { |
|
| 11758 | + throw new TConfigurationException('appconfig_using_invalid'); |
|
| 11759 | + } |
|
| 11038 | 11760 | $this->_empty=false; |
| 11039 | 11761 | break; |
| 11040 | 11762 | } |
@@ -11047,8 +11769,9 @@ discard block |
||
| 11047 | 11769 | { |
| 11048 | 11770 | foreach($modulesNode as $id=>$module) |
| 11049 | 11771 | { |
| 11050 | - if(!isset($module['class'])) |
|
| 11051 | - throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
| 11772 | + if(!isset($module['class'])) { |
|
| 11773 | + throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
| 11774 | + } |
|
| 11052 | 11775 | $type = $module['class']; |
| 11053 | 11776 | unset($module['class']); |
| 11054 | 11777 | $properties = array(); |
@@ -11071,25 +11794,28 @@ discard block |
||
| 11071 | 11794 | $properties=$element->getAttributes(); |
| 11072 | 11795 | $id=$properties->itemAt('id'); |
| 11073 | 11796 | $type=$properties->remove('class'); |
| 11074 | - if($type===null) |
|
| 11075 | - throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
| 11797 | + if($type===null) { |
|
| 11798 | + throw new TConfigurationException('appconfig_moduletype_required',$id); |
|
| 11799 | + } |
|
| 11076 | 11800 | $element->setParent(null); |
| 11077 | - if($id===null) |
|
| 11078 | - $this->_modules[]=array($type,$properties->toArray(),$element); |
|
| 11079 | - else |
|
| 11080 | - $this->_modules[$id]=array($type,$properties->toArray(),$element); |
|
| 11801 | + if($id===null) { |
|
| 11802 | + $this->_modules[]=array($type,$properties->toArray(),$element); |
|
| 11803 | + } else { |
|
| 11804 | + $this->_modules[$id]=array($type,$properties->toArray(),$element); |
|
| 11805 | + } |
|
| 11081 | 11806 | $this->_empty=false; |
| 11807 | + } else { |
|
| 11808 | + throw new TConfigurationException('appconfig_modules_invalid',$element->getTagName()); |
|
| 11082 | 11809 | } |
| 11083 | - else |
|
| 11084 | - throw new TConfigurationException('appconfig_modules_invalid',$element->getTagName()); |
|
| 11085 | 11810 | } |
| 11086 | 11811 | } |
| 11087 | 11812 | protected function loadServicesPhp($servicesNode,$configPath) |
| 11088 | 11813 | { |
| 11089 | 11814 | foreach($servicesNode as $id => $service) |
| 11090 | 11815 | { |
| 11091 | - if(!isset($service['class'])) |
|
| 11092 | - throw new TConfigurationException('appconfig_servicetype_required'); |
|
| 11816 | + if(!isset($service['class'])) { |
|
| 11817 | + throw new TConfigurationException('appconfig_servicetype_required'); |
|
| 11818 | + } |
|
| 11093 | 11819 | $type = $service['class']; |
| 11094 | 11820 | $properties = isset($service['properties']) ? $service['properties'] : array(); |
| 11095 | 11821 | unset($service['properties']); |
@@ -11105,16 +11831,18 @@ discard block |
||
| 11105 | 11831 | if($element->getTagName()==='service') |
| 11106 | 11832 | { |
| 11107 | 11833 | $properties=$element->getAttributes(); |
| 11108 | - if(($id=$properties->itemAt('id'))===null) |
|
| 11109 | - throw new TConfigurationException('appconfig_serviceid_required'); |
|
| 11110 | - if(($type=$properties->remove('class'))===null) |
|
| 11111 | - throw new TConfigurationException('appconfig_servicetype_required',$id); |
|
| 11834 | + if(($id=$properties->itemAt('id'))===null) { |
|
| 11835 | + throw new TConfigurationException('appconfig_serviceid_required'); |
|
| 11836 | + } |
|
| 11837 | + if(($type=$properties->remove('class'))===null) { |
|
| 11838 | + throw new TConfigurationException('appconfig_servicetype_required',$id); |
|
| 11839 | + } |
|
| 11112 | 11840 | $element->setParent(null); |
| 11113 | 11841 | $this->_services[$id]=array($type,$properties->toArray(),$element); |
| 11114 | 11842 | $this->_empty=false; |
| 11843 | + } else { |
|
| 11844 | + throw new TConfigurationException('appconfig_services_invalid',$element->getTagName()); |
|
| 11115 | 11845 | } |
| 11116 | - else |
|
| 11117 | - throw new TConfigurationException('appconfig_services_invalid',$element->getTagName()); |
|
| 11118 | 11846 | } |
| 11119 | 11847 | } |
| 11120 | 11848 | protected function loadParametersPhp($parametersNode,$configPath) |
@@ -11131,8 +11859,7 @@ discard block |
||
| 11131 | 11859 | $properties['id'] = $id; |
| 11132 | 11860 | $this->_parameters[$id] = array($type,$properties); |
| 11133 | 11861 | } |
| 11134 | - } |
|
| 11135 | - else |
|
| 11862 | + } else |
|
| 11136 | 11863 | { |
| 11137 | 11864 | $this->_parameters[$id] = $parameter; |
| 11138 | 11865 | } |
@@ -11145,21 +11872,23 @@ discard block |
||
| 11145 | 11872 | if($element->getTagName()==='parameter') |
| 11146 | 11873 | { |
| 11147 | 11874 | $properties=$element->getAttributes(); |
| 11148 | - if(($id=$properties->remove('id'))===null) |
|
| 11149 | - throw new TConfigurationException('appconfig_parameterid_required'); |
|
| 11875 | + if(($id=$properties->remove('id'))===null) { |
|
| 11876 | + throw new TConfigurationException('appconfig_parameterid_required'); |
|
| 11877 | + } |
|
| 11150 | 11878 | if(($type=$properties->remove('class'))===null) |
| 11151 | 11879 | { |
| 11152 | - if(($value=$properties->remove('value'))===null) |
|
| 11153 | - $this->_parameters[$id]=$element; |
|
| 11154 | - else |
|
| 11155 | - $this->_parameters[$id]=$value; |
|
| 11880 | + if(($value=$properties->remove('value'))===null) { |
|
| 11881 | + $this->_parameters[$id]=$element; |
|
| 11882 | + } else { |
|
| 11883 | + $this->_parameters[$id]=$value; |
|
| 11884 | + } |
|
| 11885 | + } else { |
|
| 11886 | + $this->_parameters[$id]=array($type,$properties->toArray()); |
|
| 11156 | 11887 | } |
| 11157 | - else |
|
| 11158 | - $this->_parameters[$id]=array($type,$properties->toArray()); |
|
| 11159 | 11888 | $this->_empty=false; |
| 11889 | + } else { |
|
| 11890 | + throw new TConfigurationException('appconfig_parameters_invalid',$element->getTagName()); |
|
| 11160 | 11891 | } |
| 11161 | - else |
|
| 11162 | - throw new TConfigurationException('appconfig_parameters_invalid',$element->getTagName()); |
|
| 11163 | 11892 | } |
| 11164 | 11893 | } |
| 11165 | 11894 | protected function loadExternalPhp($includeNode,$configPath) |
@@ -11167,26 +11896,31 @@ discard block |
||
| 11167 | 11896 | foreach($includeNode as $include) |
| 11168 | 11897 | { |
| 11169 | 11898 | $when = isset($include['when'])?true:false; |
| 11170 | - if(!isset($include['file'])) |
|
| 11171 | - throw new TConfigurationException('appconfig_includefile_required'); |
|
| 11899 | + if(!isset($include['file'])) { |
|
| 11900 | + throw new TConfigurationException('appconfig_includefile_required'); |
|
| 11901 | + } |
|
| 11172 | 11902 | $filePath = $include['file']; |
| 11173 | - if(isset($this->_includes[$filePath])) |
|
| 11174 | - $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')'; |
|
| 11175 | - else |
|
| 11176 | - $$this->_includes[$filePath]=$when; |
|
| 11903 | + if(isset($this->_includes[$filePath])) { |
|
| 11904 | + $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')'; |
|
| 11905 | + } else { |
|
| 11906 | + $$this->_includes[$filePath]=$when; |
|
| 11907 | + } |
|
| 11177 | 11908 | $this->_empty=false; |
| 11178 | 11909 | } |
| 11179 | 11910 | } |
| 11180 | 11911 | protected function loadExternalXml($includeNode,$configPath) |
| 11181 | 11912 | { |
| 11182 | - if(($when=$includeNode->getAttribute('when'))===null) |
|
| 11183 | - $when=true; |
|
| 11184 | - if(($filePath=$includeNode->getAttribute('file'))===null) |
|
| 11185 | - throw new TConfigurationException('appconfig_includefile_required'); |
|
| 11186 | - if(isset($this->_includes[$filePath])) |
|
| 11187 | - $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')'; |
|
| 11188 | - else |
|
| 11189 | - $this->_includes[$filePath]=$when; |
|
| 11913 | + if(($when=$includeNode->getAttribute('when'))===null) { |
|
| 11914 | + $when=true; |
|
| 11915 | + } |
|
| 11916 | + if(($filePath=$includeNode->getAttribute('file'))===null) { |
|
| 11917 | + throw new TConfigurationException('appconfig_includefile_required'); |
|
| 11918 | + } |
|
| 11919 | + if(isset($this->_includes[$filePath])) { |
|
| 11920 | + $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')'; |
|
| 11921 | + } else { |
|
| 11922 | + $this->_includes[$filePath]=$when; |
|
| 11923 | + } |
|
| 11190 | 11924 | $this->_empty=false; |
| 11191 | 11925 | } |
| 11192 | 11926 | public function getProperties() |
@@ -11231,14 +11965,15 @@ discard block |
||
| 11231 | 11965 | } |
| 11232 | 11966 | public function load() |
| 11233 | 11967 | { |
| 11234 | - if(($cache=$this->getApplication()->getCache())!==null && ($value=$cache->get(self::CACHE_NAME))!==false) |
|
| 11235 | - return unserialize($value); |
|
| 11236 | - else |
|
| 11968 | + if(($cache=$this->getApplication()->getCache())!==null && ($value=$cache->get(self::CACHE_NAME))!==false) { |
|
| 11969 | + return unserialize($value); |
|
| 11970 | + } else |
|
| 11237 | 11971 | { |
| 11238 | - if(($content=@file_get_contents($this->getStateFilePath()))!==false) |
|
| 11239 | - return unserialize($content); |
|
| 11240 | - else |
|
| 11241 | - return null; |
|
| 11972 | + if(($content=@file_get_contents($this->getStateFilePath()))!==false) { |
|
| 11973 | + return unserialize($content); |
|
| 11974 | + } else { |
|
| 11975 | + return null; |
|
| 11976 | + } |
|
| 11242 | 11977 | } |
| 11243 | 11978 | } |
| 11244 | 11979 | public function save($state) |
@@ -11247,10 +11982,11 @@ discard block |
||
| 11247 | 11982 | $saveFile=true; |
| 11248 | 11983 | if(($cache=$this->getApplication()->getCache())!==null) |
| 11249 | 11984 | { |
| 11250 | - if($cache->get(self::CACHE_NAME)===$content) |
|
| 11251 | - $saveFile=false; |
|
| 11252 | - else |
|
| 11253 | - $cache->set(self::CACHE_NAME,$content); |
|
| 11985 | + if($cache->get(self::CACHE_NAME)===$content) { |
|
| 11986 | + $saveFile=false; |
|
| 11987 | + } else { |
|
| 11988 | + $cache->set(self::CACHE_NAME,$content); |
|
| 11989 | + } |
|
| 11254 | 11990 | } |
| 11255 | 11991 | if($saveFile) |
| 11256 | 11992 | { |