@@ -26,8 +26,9 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public static function contains($haystack, $needle, $caseSensitive = true) |
| 28 | 28 | { |
| 29 | - if (empty($needle)) |
|
| 30 | - return true; |
|
| 29 | + if (empty($needle)) { |
|
| 30 | + return true; |
|
| 31 | + } |
|
| 31 | 32 | return $caseSensitive |
| 32 | 33 | ? strpos($haystack, $needle) !== false |
| 33 | 34 | : stripos($haystack, $needle) !== false; |
@@ -63,7 +64,9 @@ discard block |
||
| 63 | 64 | } |
| 64 | 65 | |
| 65 | 66 | // @CHANGE LDR |
| 66 | - if (!is_string($haystack)) return false; |
|
| 67 | + if (!is_string($haystack)) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | return (substr($haystack, -$length) === $needle); |
| 69 | 72 | } |
@@ -556,7 +556,9 @@ |
||
| 556 | 556 | case 'string': |
| 557 | 557 | case 'password': //password fields with string |
| 558 | 558 | case 'search': //search field with string |
| 559 | - if (is_bool($input)) $input = $input ? 'true' : 'false'; |
|
| 559 | + if (is_bool($input)) { |
|
| 560 | + $input = $input ? 'true' : 'false'; |
|
| 561 | + } |
|
| 560 | 562 | if (!is_string($input)) { |
| 561 | 563 | $error .= '. Expecting alpha numeric value'; |
| 562 | 564 | break; |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | array($dir, '..', '..', '..', 'php'), |
| 54 | 54 | array($dir, 'vendor', 'php')) |
| 55 | 55 | as $includePath |
| 56 | - ) |
|
| 57 | - if ( |
|
| 56 | + ) { |
|
| 57 | + if ( |
|
| 58 | 58 | false !== $path = stream_resolve_include_path( |
| 59 | 59 | implode($slash, $includePath) |
| 60 | 60 | ) |
@@ -68,18 +68,22 @@ discard block |
||
| 68 | 68 | static::seen(static::loadFile( |
| 69 | 69 | $classmapPath |
| 70 | 70 | )); |
| 71 | + } |
|
| 71 | 72 | $paths = array_merge( |
| 72 | 73 | $paths, |
| 73 | 74 | array_values(static::loadFile( |
| 74 | 75 | "$path{$slash}autoload_namespaces.php" |
| 75 | 76 | )) |
| 76 | 77 | ); |
| 77 | - } else $paths[] = $path; |
|
| 78 | + } else { |
|
| 79 | + $paths[] = $path; |
|
| 80 | + } |
|
| 78 | 81 | |
| 79 | 82 | $paths = array_filter(array_map( |
| 80 | 83 | function ($path) { |
| 81 | - if (false == $realPath = @realpath($path)) |
|
| 82 | - return null; |
|
| 84 | + if (false == $realPath = @realpath($path)) { |
|
| 85 | + return null; |
|
| 86 | + } |
|
| 83 | 87 | return $realPath . DIRECTORY_SEPARATOR; |
| 84 | 88 | }, |
| 85 | 89 | $paths |
@@ -118,12 +122,14 @@ discard block |
||
| 118 | 122 | return false; |
| 119 | 123 | } |
| 120 | 124 | |
| 121 | - if (empty(static::$classMap[$key])) |
|
| 122 | - static::$classMap[$key] = $value; |
|
| 125 | + if (empty(static::$classMap[$key])) { |
|
| 126 | + static::$classMap[$key] = $value; |
|
| 127 | + } |
|
| 123 | 128 | |
| 124 | - if (is_string($alias = static::$classMap[$key])) |
|
| 125 | - if (isset(static::$classMap[$alias])) |
|
| 129 | + if (is_string($alias = static::$classMap[$key])) { |
|
| 130 | + if (isset(static::$classMap[$alias])) |
|
| 126 | 131 | return static::$classMap[$alias]; |
| 132 | + } |
|
| 127 | 133 | |
| 128 | 134 | return static::$classMap[$key]; |
| 129 | 135 | } |
@@ -163,18 +169,21 @@ discard block |
||
| 163 | 169 | */ |
| 164 | 170 | public static function thereCanBeOnlyOne() |
| 165 | 171 | { |
| 166 | - if (static::$perfectLoaders === spl_autoload_functions()) |
|
| 167 | - return static::$instance; |
|
| 172 | + if (static::$perfectLoaders === spl_autoload_functions()) { |
|
| 173 | + return static::$instance; |
|
| 174 | + } |
|
| 168 | 175 | |
| 169 | - if (false !== $loaders = spl_autoload_functions()) |
|
| 170 | - if (0 < $count = count($loaders)) |
|
| 176 | + if (false !== $loaders = spl_autoload_functions()) { |
|
| 177 | + if (0 < $count = count($loaders)) |
|
| 171 | 178 | for ( |
| 172 | 179 | $i = 0, static::$rogueLoaders += $loaders; |
| 180 | + } |
|
| 173 | 181 | $i < $count && false != ($loader = $loaders[$i]); |
| 174 | 182 | $i++ |
| 175 | - ) |
|
| 176 | - if ($loader !== static::$perfectLoaders[0]) |
|
| 183 | + ) { |
|
| 184 | + if ($loader !== static::$perfectLoaders[0]) |
|
| 177 | 185 | spl_autoload_unregister($loader); |
| 186 | + } |
|
| 178 | 187 | |
| 179 | 188 | return static::$instance; |
| 180 | 189 | } |
@@ -192,9 +201,11 @@ discard block |
||
| 192 | 201 | */ |
| 193 | 202 | public static function addPath($path) |
| 194 | 203 | { |
| 195 | - if (false === $path = stream_resolve_include_path($path)) |
|
| 196 | - return false; |
|
| 197 | - else set_include_path($path . PATH_SEPARATOR . get_include_path()); |
|
| 204 | + if (false === $path = stream_resolve_include_path($path)) { |
|
| 205 | + return false; |
|
| 206 | + } else { |
|
| 207 | + set_include_path($path . PATH_SEPARATOR . get_include_path()); |
|
| 208 | + } |
|
| 198 | 209 | return $path; |
| 199 | 210 | } |
| 200 | 211 | |
@@ -207,22 +218,27 @@ discard block |
||
| 207 | 218 | */ |
| 208 | 219 | public function __invoke($className) |
| 209 | 220 | { |
| 210 | - if (empty($className)) |
|
| 211 | - return false; |
|
| 221 | + if (empty($className)) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 212 | 224 | |
| 213 | - if (false !== $includeReference = $this->discover($className)) |
|
| 214 | - return $includeReference; |
|
| 225 | + if (false !== $includeReference = $this->discover($className)) { |
|
| 226 | + return $includeReference; |
|
| 227 | + } |
|
| 215 | 228 | |
| 216 | 229 | //static::thereCanBeOnlyOne(); |
| 217 | 230 | |
| 218 | - if (false !== $includeReference = $this->loadAliases($className)) |
|
| 219 | - return $includeReference; |
|
| 231 | + if (false !== $includeReference = $this->loadAliases($className)) { |
|
| 232 | + return $includeReference; |
|
| 233 | + } |
|
| 220 | 234 | |
| 221 | - if (false !== $includeReference = $this->loadPrefixes($className)) |
|
| 222 | - return $includeReference; |
|
| 235 | + if (false !== $includeReference = $this->loadPrefixes($className)) { |
|
| 236 | + return $includeReference; |
|
| 237 | + } |
|
| 223 | 238 | |
| 224 | - if (false !== $includeReference = $this->loadLastResort($className)) |
|
| 225 | - return $includeReference; |
|
| 239 | + if (false !== $includeReference = $this->loadLastResort($className)) { |
|
| 240 | + return $includeReference; |
|
| 241 | + } |
|
| 226 | 242 | |
| 227 | 243 | static::seen($className, true); |
| 228 | 244 | return null; |
@@ -243,11 +259,12 @@ discard block |
||
| 243 | 259 | |
| 244 | 260 | /** The short version we've done this before and found it in cache */ |
| 245 | 261 | if (false !== $file = static::seen($className)) { |
| 246 | - if (!$this->exists($className)) |
|
| 247 | - if (is_callable($file)) |
|
| 262 | + if (!$this->exists($className)) { |
|
| 263 | + if (is_callable($file)) |
|
| 248 | 264 | $file = $this->loadLastResort($className, $file); |
| 249 | - elseif ($file = stream_resolve_include_path($file)) |
|
| 250 | - $file = static::loadFile($file); |
|
| 265 | + } elseif ($file = stream_resolve_include_path($file)) { |
|
| 266 | + $file = static::loadFile($file); |
|
| 267 | + } |
|
| 251 | 268 | |
| 252 | 269 | $this->alias($className, $currentClass); |
| 253 | 270 | return $file; |
@@ -257,15 +274,17 @@ discard block |
||
| 257 | 274 | |
| 258 | 275 | /** replace \ with / and _ in CLASS NAME with / = PSR-0 in 3 lines */ |
| 259 | 276 | $file = preg_replace("/\\\|_(?=\w+$)/", DIRECTORY_SEPARATOR, $className); |
| 260 | - if (false === $file = stream_resolve_include_path("$file.php")) |
|
| 261 | - return false; |
|
| 277 | + if (false === $file = stream_resolve_include_path("$file.php")) { |
|
| 278 | + return false; |
|
| 279 | + } |
|
| 262 | 280 | |
| 263 | 281 | /** have we loaded this file before could this be an alias */ |
| 264 | 282 | if (in_array($file, get_included_files())) { |
| 265 | - if (false !== $sameFile = array_search($file, static::$classMap)) |
|
| 266 | - if (!$this->exists($className, $file)) |
|
| 283 | + if (false !== $sameFile = array_search($file, static::$classMap)) { |
|
| 284 | + if (!$this->exists($className, $file)) |
|
| 267 | 285 | if (false !== strpos($sameFile, $className)) |
| 268 | 286 | $this->alias($sameFile, $className); |
| 287 | + } |
|
| 269 | 288 | |
| 270 | 289 | return $file; |
| 271 | 290 | } |
@@ -273,19 +292,21 @@ discard block |
||
| 273 | 292 | $state = array_merge(get_declared_classes(), get_declared_interfaces()); |
| 274 | 293 | |
| 275 | 294 | if (false !== $result = static::loadFile($file)) { |
| 276 | - if ($this->exists($className, $file)) |
|
| 277 | - $this->alias($className, $currentClass); |
|
| 278 | - elseif ( |
|
| 295 | + if ($this->exists($className, $file)) { |
|
| 296 | + $this->alias($className, $currentClass); |
|
| 297 | + } elseif ( |
|
| 279 | 298 | false != $diff = array_diff( |
| 280 | 299 | array_merge(get_declared_classes(), get_declared_interfaces()), $state) |
| 281 | - ) |
|
| 282 | - foreach ($diff as $autoLoaded) |
|
| 300 | + ) { |
|
| 301 | + foreach ($diff as $autoLoaded) |
|
| 283 | 302 | if ($this->exists($autoLoaded, $file)) |
| 284 | 303 | if (false !== strpos($autoLoaded, $className)) |
| 285 | 304 | $this->alias($autoLoaded, $className); |
| 305 | + } |
|
| 286 | 306 | |
| 287 | - if (!$this->exists($currentClass)) |
|
| 288 | - $result = false; |
|
| 307 | + if (!$this->exists($currentClass)) { |
|
| 308 | + $result = false; |
|
| 309 | + } |
|
| 289 | 310 | } |
| 290 | 311 | |
| 291 | 312 | return $result; |
@@ -305,10 +326,12 @@ discard block |
||
| 305 | 326 | if ( |
| 306 | 327 | class_exists($className, false) |
| 307 | 328 | || interface_exists($className, false) |
| 308 | - ) |
|
| 309 | - if (isset($mapping)) |
|
| 329 | + ) { |
|
| 330 | + if (isset($mapping)) |
|
| 310 | 331 | return static::seen($className, $mapping); |
| 311 | - else return true; |
|
| 332 | + } else { |
|
| 333 | + return true; |
|
| 334 | + } |
|
| 312 | 335 | return false; |
| 313 | 336 | } |
| 314 | 337 | |
@@ -328,13 +351,15 @@ discard block |
||
| 328 | 351 | { |
| 329 | 352 | $loaders = array_unique(static::$rogueLoaders, SORT_REGULAR); |
| 330 | 353 | if (isset($loader)) { |
| 331 | - if (false === array_search($loader, $loaders)) |
|
| 332 | - static::$rogueLoaders[] = $loader; |
|
| 354 | + if (false === array_search($loader, $loaders)) { |
|
| 355 | + static::$rogueLoaders[] = $loader; |
|
| 356 | + } |
|
| 333 | 357 | return $this->loadThisLoader($className, $loader); |
| 334 | 358 | } |
| 335 | - foreach ($loaders as $loader) |
|
| 336 | - if (false !== $file = $this->loadThisLoader($className, $loader)) |
|
| 359 | + foreach ($loaders as $loader) { |
|
| 360 | + if (false !== $file = $this->loadThisLoader($className, $loader)) |
|
| 337 | 361 | return $file; |
| 362 | + } |
|
| 338 | 363 | |
| 339 | 364 | return false; |
| 340 | 365 | } |
@@ -413,17 +438,22 @@ discard block |
||
| 413 | 438 | */ |
| 414 | 439 | private function alias($className, $currentClass) |
| 415 | 440 | { |
| 416 | - if ($className == 'Luracast\Restler\string') return; |
|
| 417 | - if ($className == 'Luracast\Restler\mixed') return; |
|
| 441 | + if ($className == 'Luracast\Restler\string') { |
|
| 442 | + return; |
|
| 443 | + } |
|
| 444 | + if ($className == 'Luracast\Restler\mixed') { |
|
| 445 | + return; |
|
| 446 | + } |
|
| 418 | 447 | if ( |
| 419 | 448 | $className != $currentClass |
| 420 | 449 | && false !== strpos($className, $currentClass) |
| 421 | - ) |
|
| 422 | - if ( |
|
| 450 | + ) { |
|
| 451 | + if ( |
|
| 423 | 452 | !class_exists($currentClass, false) |
| 424 | 453 | && class_alias($className, $currentClass) |
| 425 | 454 | ) |
| 426 | 455 | static::seen($currentClass, $className); |
| 456 | + } |
|
| 427 | 457 | } |
| 428 | 458 | |
| 429 | 459 | /** |
@@ -436,12 +466,13 @@ discard block |
||
| 436 | 466 | private function loadAliases($className) |
| 437 | 467 | { |
| 438 | 468 | $file = false; |
| 439 | - if (preg_match('/(.+)(\\\\\w+$)/U', $className, $parts)) |
|
| 440 | - for ( |
|
| 469 | + if (preg_match('/(.+)(\\\\\w+$)/U', $className, $parts)) { |
|
| 470 | + for ( |
|
| 441 | 471 | $i = 0, |
| 442 | 472 | $aliases = isset(static::$aliases[$parts[1]]) |
| 443 | 473 | ? static::$aliases[$parts[1]] : array(), |
| 444 | 474 | $count = count($aliases); |
| 475 | + } |
|
| 445 | 476 | $i < $count && false === $file; |
| 446 | 477 | $file = $this->discover( |
| 447 | 478 | "{$aliases[$i++]}$parts[2]", |
@@ -462,9 +493,11 @@ discard block |
||
| 462 | 493 | private function loadPrefixes($className) |
| 463 | 494 | { |
| 464 | 495 | $currentClass = $className; |
| 465 | - if (false !== $pos = strrpos($className, '\\')) |
|
| 466 | - $className = substr($className, $pos); |
|
| 467 | - else $className = "\\$className"; |
|
| 496 | + if (false !== $pos = strrpos($className, '\\')) { |
|
| 497 | + $className = substr($className, $pos); |
|
| 498 | + } else { |
|
| 499 | + $className = "\\$className"; |
|
| 500 | + } |
|
| 468 | 501 | |
| 469 | 502 | for ( |
| 470 | 503 | $i = 0, |
@@ -124,9 +124,10 @@ discard block |
||
| 124 | 124 | $metadata['param'] = array(); |
| 125 | 125 | } |
| 126 | 126 | if (isset($metadata['return']['type'])) { |
| 127 | - if ($qualified = Scope::resolve($metadata['return']['type'], $scope)) |
|
| 128 | - list($metadata['return']['type'], $metadata['return']['children']) = |
|
| 127 | + if ($qualified = Scope::resolve($metadata['return']['type'], $scope)) { |
|
| 128 | + list($metadata['return']['type'], $metadata['return']['children']) = |
|
| 129 | 129 | static::getTypeAndModel(new ReflectionClass($qualified), $scope); |
| 130 | + } |
|
| 130 | 131 | } else { |
| 131 | 132 | //assume return type is array |
| 132 | 133 | $metadata['return']['type'] = 'array'; |
@@ -147,8 +148,9 @@ discard block |
||
| 147 | 148 | $m[$dataName] = array(); |
| 148 | 149 | } |
| 149 | 150 | $p = &$m[$dataName]; |
| 150 | - if (empty($m['label'])) |
|
| 151 | - $m['label'] = Text::title($m['name']); |
|
| 151 | + if (empty($m['label'])) { |
|
| 152 | + $m['label'] = Text::title($m['name']); |
|
| 153 | + } |
|
| 152 | 154 | if (is_null($type) && isset($m['type'])) { |
| 153 | 155 | $type = $m['type']; |
| 154 | 156 | } |
@@ -307,8 +309,9 @@ discard block |
||
| 307 | 309 | } |
| 308 | 310 | $lastPathParam = end($pathParams); |
| 309 | 311 | foreach ($pathParams as $position) { |
| 310 | - if (!empty($url)) |
|
| 311 | - $url .= '/'; |
|
| 312 | + if (!empty($url)) { |
|
| 313 | + $url .= '/'; |
|
| 314 | + } |
|
| 312 | 315 | $url .= '{' . |
| 313 | 316 | static::typeChar(isset($call['metadata']['param'][$position]['type']) |
| 314 | 317 | ? $call['metadata']['param'][$position]['type'] |
@@ -356,8 +359,9 @@ discard block |
||
| 356 | 359 | } else { |
| 357 | 360 | static::$routes["v$version"][$path][$httpMethod] = $call; |
| 358 | 361 | //create an alias with index if the method name is index |
| 359 | - if ($call['methodName'] == 'index') |
|
| 360 | - static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call; |
|
| 362 | + if ($call['methodName'] == 'index') { |
|
| 363 | + static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call; |
|
| 364 | + } |
|
| 361 | 365 | } |
| 362 | 366 | } |
| 363 | 367 | |
@@ -407,8 +411,9 @@ discard block |
||
| 407 | 411 | } |
| 408 | 412 | //================== dynamic routes ============================= |
| 409 | 413 | //add newline char if trailing slash is found |
| 410 | - if (substr($path, -1) == '/') |
|
| 411 | - $path .= PHP_EOL; |
|
| 414 | + if (substr($path, -1) == '/') { |
|
| 415 | + $path .= PHP_EOL; |
|
| 416 | + } |
|
| 412 | 417 | //if double slash is found fill in newline char; |
| 413 | 418 | $path = str_replace('//', '/' . PHP_EOL . '/', $path); |
| 414 | 419 | ksort($p); |
@@ -474,8 +479,9 @@ discard block |
||
| 474 | 479 | } |
| 475 | 480 | foreach ($excludedPaths as $exclude) { |
| 476 | 481 | if (empty($exclude)) { |
| 477 | - if ($fullPath == $exclude || $fullPath == 'index') |
|
| 478 | - continue 2; |
|
| 482 | + if ($fullPath == $exclude || $fullPath == 'index') { |
|
| 483 | + continue 2; |
|
| 484 | + } |
|
| 479 | 485 | } elseif (Text::beginsWith($fullPath, $exclude)) { |
| 480 | 486 | continue 2; |
| 481 | 487 | } |
@@ -495,13 +501,15 @@ discard block |
||
| 495 | 501 | |
| 496 | 502 | public static function verifyAccess($route) |
| 497 | 503 | { |
| 498 | - if ($route['accessLevel'] < 2) |
|
| 499 | - return true; |
|
| 504 | + if ($route['accessLevel'] < 2) { |
|
| 505 | + return true; |
|
| 506 | + } |
|
| 500 | 507 | /** @var Restler $r */ |
| 501 | 508 | $r = Scope::get('Restler'); |
| 502 | 509 | $authenticated = $r->_authenticated; |
| 503 | - if (!$authenticated && $route['accessLevel'] > 1) |
|
| 504 | - return false; |
|
| 510 | + if (!$authenticated && $route['accessLevel'] > 1) { |
|
| 511 | + return false; |
|
| 512 | + } |
|
| 505 | 513 | if ( |
| 506 | 514 | $authenticated && |
| 507 | 515 | Defaults::$accessControlFunction && |
@@ -568,8 +576,9 @@ discard block |
||
| 568 | 576 | $modifier = "_modify_{$r->methodName}_api"; |
| 569 | 577 | if (method_exists($r->className, $modifier)) { |
| 570 | 578 | $stage = end(Scope::get('Restler')->getEvents()); |
| 571 | - if (empty($stage)) |
|
| 572 | - $stage = 'setup'; |
|
| 579 | + if (empty($stage)) { |
|
| 580 | + $stage = 'setup'; |
|
| 581 | + } |
|
| 573 | 582 | $r = Scope::get($r->className)->$modifier($r, $stage) ? : $r; |
| 574 | 583 | } |
| 575 | 584 | return $r; |
@@ -758,10 +767,18 @@ discard block |
||
| 758 | 767 | |
| 759 | 768 | public static function type($var) |
| 760 | 769 | { |
| 761 | - if (is_object($var)) return get_class($var); |
|
| 762 | - if (is_array($var)) return 'array'; |
|
| 763 | - if (is_bool($var)) return 'boolean'; |
|
| 764 | - if (is_numeric($var)) return is_float($var) ? 'float' : 'int'; |
|
| 770 | + if (is_object($var)) { |
|
| 771 | + return get_class($var); |
|
| 772 | + } |
|
| 773 | + if (is_array($var)) { |
|
| 774 | + return 'array'; |
|
| 775 | + } |
|
| 776 | + if (is_bool($var)) { |
|
| 777 | + return 'boolean'; |
|
| 778 | + } |
|
| 779 | + if (is_numeric($var)) { |
|
| 780 | + return is_float($var) ? 'float' : 'int'; |
|
| 781 | + } |
|
| 765 | 782 | return 'string'; |
| 766 | 783 | } |
| 767 | 784 | |
@@ -782,8 +799,9 @@ discard block |
||
| 782 | 799 | if ($reading && ',' == $token) { |
| 783 | 800 | //===== STOP =====// |
| 784 | 801 | $reading = false; |
| 785 | - if (!empty($namespace)) |
|
| 786 | - $imports[$alias] = trim($namespace, '\\'); |
|
| 802 | + if (!empty($namespace)) { |
|
| 803 | + $imports[$alias] = trim($namespace, '\\'); |
|
| 804 | + } |
|
| 787 | 805 | //===== START =====// |
| 788 | 806 | $reading = true; |
| 789 | 807 | $namespace = ''; |
@@ -791,8 +809,9 @@ discard block |
||
| 791 | 809 | } else { |
| 792 | 810 | //===== STOP =====// |
| 793 | 811 | $reading = false; |
| 794 | - if (!empty($namespace)) |
|
| 795 | - $imports[$alias] = trim($namespace, '\\'); |
|
| 812 | + if (!empty($namespace)) { |
|
| 813 | + $imports[$alias] = trim($namespace, '\\'); |
|
| 814 | + } |
|
| 796 | 815 | } |
| 797 | 816 | } elseif (T_USE == $token[0]) { |
| 798 | 817 | //===== START =====// |
@@ -89,10 +89,16 @@ discard block |
||
| 89 | 89 | { |
| 90 | 90 | // To provide debug information on line number processed |
| 91 | 91 | global $count; |
| 92 | - if (empty($count)) $count = 1; |
|
| 93 | - else $count++; |
|
| 92 | + if (empty($count)) { |
|
| 93 | + $count = 1; |
|
| 94 | + } else { |
|
| 95 | + $count++; |
|
| 96 | + } |
|
| 94 | 97 | |
| 95 | - if (empty($this->savxml)) $this->savxml = $this->xml; // Sav content of line at first line merged, so we will reuse original for next steps |
|
| 98 | + if (empty($this->savxml)) { |
|
| 99 | + $this->savxml = $this->xml; |
|
| 100 | + } |
|
| 101 | + // Sav content of line at first line merged, so we will reuse original for next steps |
|
| 96 | 102 | $this->xml = $this->savxml; |
| 97 | 103 | $tmpvars = $this->vars; // Store into $tmpvars so we won't modify this->vars when completing data with empty values |
| 98 | 104 | |
@@ -124,7 +130,9 @@ discard block |
||
| 124 | 130 | $reg = '@\[!--\sIF\s' . $key . '\s--\](.*)(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
| 125 | 131 | preg_match_all($reg, $this->xml, $matches, PREG_SET_ORDER); |
| 126 | 132 | foreach ($matches as $match) { // For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause |
| 127 | - if (!empty($match[3])) $this->xml = str_replace($match[0], $match[3], $this->xml); |
|
| 133 | + if (!empty($match[3])) { |
|
| 134 | + $this->xml = str_replace($match[0], $match[3], $this->xml); |
|
| 135 | + } |
|
| 128 | 136 | } |
| 129 | 137 | // Cleanup the other conditional blocks (all the others where there were no ELSE clause, we can just remove them altogether) |
| 130 | 138 | $this->xml = preg_replace($reg, '', $this->xml); |
@@ -1,6 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (! defined('ODTPHP_PATHTOPCLZIP')) define('ODTPHP_PATHTOPCLZIP', 'pclzip/'); |
|
| 3 | +if (! defined('ODTPHP_PATHTOPCLZIP')) { |
|
| 4 | + define('ODTPHP_PATHTOPCLZIP', 'pclzip/'); |
|
| 5 | +} |
|
| 4 | 6 | require_once ODTPHP_PATHTOPCLZIP . 'pclzip.lib.php'; |
| 5 | 7 | require_once 'ZipInterface.php'; |
| 6 | 8 | class PclZipProxyException extends Exception |
@@ -34,7 +36,10 @@ discard block |
||
| 34 | 36 | throw new PclZipProxyException('PclZip class not loaded - PclZip library |
| 35 | 37 | is required for using PclZipProxy'); ; |
| 36 | 38 | } |
| 37 | - if ($forcedir) $this->tmpdir = preg_replace('|[//\/]$|', '', $forcedir); // $this->tmpdir must not contains / at the end |
|
| 39 | + if ($forcedir) { |
|
| 40 | + $this->tmpdir = preg_replace('|[//\/]$|', '', $forcedir); |
|
| 41 | + } |
|
| 42 | + // $this->tmpdir must not contains / at the end |
|
| 38 | 43 | } |
| 39 | 44 | |
| 40 | 45 | /** |
@@ -78,7 +78,10 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | $md5uniqid = md5(uniqid()); |
| 81 | - if ($this->config['PATH_TO_TMP']) $this->tmpdir = preg_replace('|[\/]$|', '', $this->config['PATH_TO_TMP']); // Remove last \ or / |
|
| 81 | + if ($this->config['PATH_TO_TMP']) { |
|
| 82 | + $this->tmpdir = preg_replace('|[\/]$|', '', $this->config['PATH_TO_TMP']); |
|
| 83 | + } |
|
| 84 | + // Remove last \ or / |
|
| 82 | 85 | $this->tmpdir .= ($this->tmpdir ? '/' : '') . $md5uniqid; |
| 83 | 86 | $this->tmpfile = $this->tmpdir . '/' . $md5uniqid . '.odt'; // We keep .odt extension to allow OpenOffice usage during debug. |
| 84 | 87 | |
@@ -94,7 +97,9 @@ discard block |
||
| 94 | 97 | |
| 95 | 98 | // Load zip proxy |
| 96 | 99 | $zipHandler = $this->config['ZIP_PROXY']; |
| 97 | - if (!defined('PCLZIP_TEMPORARY_DIR')) define('PCLZIP_TEMPORARY_DIR', $this->tmpdir); |
|
| 100 | + if (!defined('PCLZIP_TEMPORARY_DIR')) { |
|
| 101 | + define('PCLZIP_TEMPORARY_DIR', $this->tmpdir); |
|
| 102 | + } |
|
| 98 | 103 | include_once 'zip/' . $zipHandler . '.php'; |
| 99 | 104 | if (! class_exists($this->config['ZIP_PROXY'])) { |
| 100 | 105 | throw new OdfException($this->config['ZIP_PROXY'] . ' class not found - check your php settings'); |
@@ -236,8 +241,12 @@ discard block |
||
| 236 | 241 | */ |
| 237 | 242 | private function _replaceHtmlWithOdtTag($tags, &$customStyles, &$fontDeclarations, $encode = false, $charset = '') |
| 238 | 243 | { |
| 239 | - if ($customStyles == null) $customStyles = array(); |
|
| 240 | - if ($fontDeclarations == null) $fontDeclarations = array(); |
|
| 244 | + if ($customStyles == null) { |
|
| 245 | + $customStyles = array(); |
|
| 246 | + } |
|
| 247 | + if ($fontDeclarations == null) { |
|
| 248 | + $fontDeclarations = array(); |
|
| 249 | + } |
|
| 241 | 250 | |
| 242 | 251 | $odtResult = ''; |
| 243 | 252 | |
@@ -556,10 +565,15 @@ discard block |
||
| 556 | 565 | */ |
| 557 | 566 | private function _parse($type = 'content') |
| 558 | 567 | { |
| 559 | - if ($type == 'content') $xml = &$this->contentXml; |
|
| 560 | - elseif ($type == 'styles') $xml = &$this->stylesXml; |
|
| 561 | - elseif ($type == 'meta') $xml = &$this->metaXml; |
|
| 562 | - else return; |
|
| 568 | + if ($type == 'content') { |
|
| 569 | + $xml = &$this->contentXml; |
|
| 570 | + } elseif ($type == 'styles') { |
|
| 571 | + $xml = &$this->stylesXml; |
|
| 572 | + } elseif ($type == 'meta') { |
|
| 573 | + $xml = &$this->metaXml; |
|
| 574 | + } else { |
|
| 575 | + return; |
|
| 576 | + } |
|
| 563 | 577 | |
| 564 | 578 | // Search all tags found into condition to complete $this->vars, so we will proceed all tests even if not defined |
| 565 | 579 | $reg = '@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; |
@@ -600,7 +614,9 @@ discard block |
||
| 600 | 614 | $reg = '@\[!--\sIF\s' . $key . '\s--\](.*)(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
| 601 | 615 | preg_match_all($reg, $xml, $matches, PREG_SET_ORDER); |
| 602 | 616 | foreach ($matches as $match) { // For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause |
| 603 | - if (!empty($match[3])) $xml = str_replace($match[0], $match[3], $xml); |
|
| 617 | + if (!empty($match[3])) { |
|
| 618 | + $xml = str_replace($match[0], $match[3], $xml); |
|
| 619 | + } |
|
| 604 | 620 | } |
| 605 | 621 | // Cleanup the other conditional blocks (all the others where there were no ELSE clause, we can just remove them altogether) |
| 606 | 622 | $xml = preg_replace($reg, '', $xml); |
@@ -754,7 +770,9 @@ discard block |
||
| 754 | 770 | */ |
| 755 | 771 | public function setMetaData() |
| 756 | 772 | { |
| 757 | - if (empty($this->creator)) $this->creator = ''; |
|
| 773 | + if (empty($this->creator)) { |
|
| 774 | + $this->creator = ''; |
|
| 775 | + } |
|
| 758 | 776 | |
| 759 | 777 | $this->metaXml = preg_replace('/<dc:date>.*<\/dc:date>/', '<dc:date>' . gmdate("Y-m-d\TH:i:s") . '</dc:date>', $this->metaXml); |
| 760 | 778 | $this->metaXml = preg_replace('/<dc:creator>.*<\/dc:creator>/', '<dc:creator>' . htmlspecialchars($this->creator) . '</dc:creator>', $this->metaXml); |
@@ -822,7 +840,9 @@ discard block |
||
| 822 | 840 | { |
| 823 | 841 | global $conf; |
| 824 | 842 | |
| 825 | - if ($name == "") $name = "temp" . md5(uniqid()); |
|
| 843 | + if ($name == "") { |
|
| 844 | + $name = "temp" . md5(uniqid()); |
|
| 845 | + } |
|
| 826 | 846 | |
| 827 | 847 | dol_syslog(get_class($this) . '::exportAsAttachedPDF $name=' . $name, LOG_DEBUG); |
| 828 | 848 | $this->saveToDisk($name); |
@@ -6506,16 +6506,14 @@ discard block |
||
| 6506 | 6506 | $eName, |
| 6507 | 6507 | isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], |
| 6508 | 6508 | $v, $use, $encodingStyle, $unqualified); |
| 6509 | - } |
|
| 6510 | - elseif (isset($attrs['type']) || isset($attrs['ref'])) |
|
| 6509 | + } elseif (isset($attrs['type']) || isset($attrs['ref'])) |
|
| 6511 | 6510 | { |
| 6512 | 6511 | // serialize schema-defined type |
| 6513 | 6512 | $xml .= $this->serializeType( |
| 6514 | 6513 | $eName, |
| 6515 | 6514 | isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], |
| 6516 | 6515 | $v, $use, $encodingStyle, $unqualified); |
| 6517 | - } |
|
| 6518 | - else |
|
| 6516 | + } else |
|
| 6519 | 6517 | { |
| 6520 | 6518 | // serialize generic type (can this ever really happen?) |
| 6521 | 6519 | $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
@@ -7017,8 +7015,7 @@ discard block |
||
| 7017 | 7015 | if (isset($this->namespaces[$value_prefix])) |
| 7018 | 7016 | { |
| 7019 | 7017 | $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix]; |
| 7020 | - } |
|
| 7021 | - elseif (isset($attrs['xmlns:' . $value_prefix])) |
|
| 7018 | + } elseif (isset($attrs['xmlns:' . $value_prefix])) |
|
| 7022 | 7019 | { |
| 7023 | 7020 | $this->message[$pos]['type_namespace'] = $attrs['xmlns:' . $value_prefix]; |
| 7024 | 7021 | } |
@@ -60,7 +60,9 @@ |
||
| 60 | 60 | |
| 61 | 61 | public function envelope() |
| 62 | 62 | { |
| 63 | - if ($this->isEmpty()) return new Polygon(); |
|
| 63 | + if ($this->isEmpty()) { |
|
| 64 | + return new Polygon(); |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | if ($this->geos()) { |
| 66 | 68 | return geoPHP::geosToGeometry($this->geos()->envelope()); |