Complex classes like TApplication often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TApplication, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 94 | class TApplication extends \Prado\TComponent |
||
| 95 | { |
||
| 96 | /** |
||
| 97 | * Page service ID |
||
| 98 | */ |
||
| 99 | const PAGE_SERVICE_ID = 'page'; |
||
| 100 | /** |
||
| 101 | * Application configuration file name |
||
| 102 | */ |
||
| 103 | const CONFIG_FILE_XML = 'application.xml'; |
||
| 104 | /** |
||
| 105 | * File extension for external config files |
||
| 106 | */ |
||
| 107 | const CONFIG_FILE_EXT_XML = '.xml'; |
||
| 108 | /** |
||
| 109 | * Configuration file type, application.xml and config.xml |
||
| 110 | */ |
||
| 111 | const CONFIG_TYPE_XML = 'xml'; |
||
| 112 | /** |
||
| 113 | * Application configuration file name |
||
| 114 | */ |
||
| 115 | const CONFIG_FILE_PHP = 'application.php'; |
||
| 116 | /** |
||
| 117 | * File extension for external config files |
||
| 118 | */ |
||
| 119 | const CONFIG_FILE_EXT_PHP = '.php'; |
||
| 120 | /** |
||
| 121 | * Configuration file type, application.php and config.php |
||
| 122 | */ |
||
| 123 | const CONFIG_TYPE_PHP = 'php'; |
||
| 124 | /** |
||
| 125 | * Runtime directory name |
||
| 126 | */ |
||
| 127 | const RUNTIME_PATH = 'runtime'; |
||
| 128 | /** |
||
| 129 | * Config cache file |
||
| 130 | */ |
||
| 131 | const CONFIGCACHE_FILE = 'config.cache'; |
||
| 132 | /** |
||
| 133 | * Global data file |
||
| 134 | */ |
||
| 135 | const GLOBAL_FILE = 'global.cache'; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var array list of events that define application lifecycles |
||
| 139 | */ |
||
| 140 | private static $_steps = [ |
||
| 141 | 'onBeginRequest', |
||
| 142 | 'onLoadState', |
||
| 143 | 'onLoadStateComplete', |
||
| 144 | 'onAuthentication', |
||
| 145 | 'onAuthenticationComplete', |
||
| 146 | 'onAuthorization', |
||
| 147 | 'onAuthorizationComplete', |
||
| 148 | 'onPreRunService', |
||
| 149 | 'runService', |
||
| 150 | 'onSaveState', |
||
| 151 | 'onSaveStateComplete', |
||
| 152 | 'onPreFlushOutput', |
||
| 153 | 'flushOutput' |
||
| 154 | ]; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @var string application ID |
||
| 158 | */ |
||
| 159 | private $_id; |
||
| 160 | /** |
||
| 161 | * @var string unique application ID |
||
| 162 | */ |
||
| 163 | private $_uniqueID; |
||
| 164 | /** |
||
| 165 | * @var bool whether the request is completed |
||
| 166 | */ |
||
| 167 | private $_requestCompleted = false; |
||
| 168 | /** |
||
| 169 | * @var int application state |
||
| 170 | */ |
||
| 171 | private $_step; |
||
| 172 | /** |
||
| 173 | * @var array available services and their configurations indexed by service IDs |
||
| 174 | */ |
||
| 175 | private $_services; |
||
| 176 | /** |
||
| 177 | * @var IService current service instance |
||
| 178 | */ |
||
| 179 | private $_service; |
||
| 180 | /** |
||
| 181 | * @var array list of loaded application modules |
||
| 182 | */ |
||
| 183 | private $_modules = []; |
||
| 184 | /** |
||
| 185 | * @var array list of application modules yet to be loaded |
||
| 186 | */ |
||
| 187 | private $_lazyModules = []; |
||
| 188 | /** |
||
| 189 | * @var \Prado\Collections\TMap list of application parameters |
||
| 190 | */ |
||
| 191 | private $_parameters; |
||
| 192 | /** |
||
| 193 | * @var string configuration file |
||
| 194 | */ |
||
| 195 | private $_configFile; |
||
| 196 | /** |
||
| 197 | * @var string configuration file extension |
||
| 198 | */ |
||
| 199 | private $_configFileExt; |
||
| 200 | /** |
||
| 201 | * @var string configuration type |
||
| 202 | */ |
||
| 203 | private $_configType; |
||
| 204 | /** |
||
| 205 | * @var string application base path |
||
| 206 | */ |
||
| 207 | private $_basePath; |
||
| 208 | /** |
||
| 209 | * @var string directory storing application state |
||
| 210 | */ |
||
| 211 | private $_runtimePath; |
||
| 212 | /** |
||
| 213 | * @var bool if any global state is changed during the current request |
||
| 214 | */ |
||
| 215 | private $_stateChanged = false; |
||
| 216 | /** |
||
| 217 | * @var array global variables (persistent across sessions, requests) |
||
| 218 | */ |
||
| 219 | private $_globals = []; |
||
| 220 | /** |
||
| 221 | * @var string cache file |
||
| 222 | */ |
||
| 223 | private $_cacheFile; |
||
| 224 | /** |
||
| 225 | * @var TErrorHandler error handler module |
||
| 226 | */ |
||
| 227 | private $_errorHandler; |
||
| 228 | /** |
||
| 229 | * @var THttpRequest request module |
||
| 230 | */ |
||
| 231 | private $_request; |
||
| 232 | /** |
||
| 233 | * @var THttpResponse response module |
||
| 234 | */ |
||
| 235 | private $_response; |
||
| 236 | /** |
||
| 237 | * @var THttpSession session module, could be null |
||
| 238 | */ |
||
| 239 | private $_session; |
||
| 240 | /** |
||
| 241 | * @var ICache cache module, could be null |
||
| 242 | */ |
||
| 243 | private $_cache; |
||
| 244 | /** |
||
| 245 | * @var IStatePersister application state persister |
||
| 246 | */ |
||
| 247 | private $_statePersister; |
||
| 248 | /** |
||
| 249 | * @var IUser user instance, could be null |
||
| 250 | */ |
||
| 251 | private $_user; |
||
| 252 | /** |
||
| 253 | * @var TGlobalization module, could be null |
||
| 254 | */ |
||
| 255 | private $_globalization; |
||
| 256 | /** |
||
| 257 | * @var TSecurityManager security manager module |
||
| 258 | */ |
||
| 259 | private $_security; |
||
| 260 | /** |
||
| 261 | * @var TAssetManager asset manager module |
||
| 262 | */ |
||
| 263 | private $_assetManager; |
||
| 264 | /** |
||
| 265 | * @var TAuthorizationRuleCollection collection of authorization rules |
||
| 266 | */ |
||
| 267 | private $_authRules; |
||
| 268 | /** |
||
| 269 | * @var TApplicationMode application mode |
||
| 270 | */ |
||
| 271 | private $_mode = TApplicationMode::Debug; |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @var string Customizable page service ID |
||
| 275 | */ |
||
| 276 | private $_pageServiceID = self::PAGE_SERVICE_ID; |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Constructor. |
||
| 280 | * Sets application base path and initializes the application singleton. |
||
| 281 | * Application base path refers to the root directory storing application |
||
| 282 | * data and code not directly accessible by Web users. |
||
| 283 | * By default, the base path is assumed to be the <b>protected</b> |
||
| 284 | * directory under the directory containing the current running script. |
||
| 285 | * @param string $basePath application base path or configuration file path. |
||
| 286 | * If the parameter is a file, it is assumed to be the application |
||
| 287 | * configuration file, and the directory containing the file is treated |
||
| 288 | * as the application base path. |
||
| 289 | * If it is a directory, it is assumed to be the application base path, |
||
| 290 | * and within that directory, a file named <b>application.xml</b> |
||
| 291 | * will be looked for. If found, the file is considered as the application |
||
| 292 | * configuration file. |
||
| 293 | * @param bool $cacheConfig whether to cache application configuration. Defaults to true. |
||
| 294 | * @param int $configType configuration type. Defaults to CONFIG_TYPE_XML. |
||
| 295 | * @throws TConfigurationException if configuration file cannot be read or the runtime path is invalid. |
||
| 296 | */ |
||
| 297 | public function __construct($basePath = 'protected', $cacheConfig = true, $configType = self::CONFIG_TYPE_XML) |
||
| 298 | { |
||
| 299 | // register application as a singleton |
||
| 300 | Prado::setApplication($this); |
||
| 301 | $this->setConfigurationType($configType); |
||
| 302 | $this->resolvePaths($basePath); |
||
| 303 | |||
| 304 | if ($cacheConfig) { |
||
| 305 | $this->_cacheFile = $this->_runtimePath . DIRECTORY_SEPARATOR . self::CONFIGCACHE_FILE; |
||
| 306 | } |
||
| 307 | |||
| 308 | // generates unique ID by hashing the runtime path |
||
| 309 | $this->_uniqueID = md5($this->_runtimePath); |
||
| 310 | $this->_parameters = new \Prado\Collections\TMap; |
||
| 311 | $this->_services = [$this->getPageServiceID() => ['TPageService', [], null]]; |
||
| 312 | |||
| 313 | Prado::setPathOfAlias('Application', $this->_basePath); |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Resolves application-relevant paths. |
||
| 318 | * This method is invoked by the application constructor |
||
| 319 | * to determine the application configuration file, |
||
| 320 | * application root path and the runtime path. |
||
| 321 | * @param string $basePath the application root path or the application configuration file |
||
| 322 | * @see setBasePath |
||
| 323 | * @see setRuntimePath |
||
| 324 | * @see setConfigurationFile |
||
| 325 | */ |
||
| 326 | protected function resolvePaths($basePath) |
||
| 327 | { |
||
| 328 | // determine configuration path and file |
||
| 329 | if (empty($basePath) || ($basePath = realpath($basePath)) === false) { |
||
| 330 | throw new TConfigurationException('application_basepath_invalid', $basePath); |
||
| 331 | } |
||
| 332 | if (is_dir($basePath) && is_file($basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName())) { |
||
| 333 | $configFile = $basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName(); |
||
| 334 | } elseif (is_file($basePath)) { |
||
| 335 | $configFile = $basePath; |
||
| 336 | $basePath = dirname($configFile); |
||
| 337 | } else { |
||
| 338 | $configFile = null; |
||
| 339 | } |
||
| 340 | |||
| 341 | // determine runtime path |
||
| 342 | $runtimePath = $basePath . DIRECTORY_SEPARATOR . self::RUNTIME_PATH; |
||
| 343 | if (is_writable($runtimePath)) { |
||
| 344 | if ($configFile !== null) { |
||
| 345 | $runtimePath .= DIRECTORY_SEPARATOR . basename($configFile) . '-' . Prado::getVersion(); |
||
| 346 | if (!is_dir($runtimePath)) { |
||
| 347 | if (@mkdir($runtimePath) === false) { |
||
| 348 | throw new TConfigurationException('application_runtimepath_failed', $runtimePath); |
||
| 349 | } |
||
| 350 | @chmod($runtimePath, PRADO_CHMOD); //make it deletable |
||
|
|
|||
| 351 | } |
||
| 352 | $this->setConfigurationFile($configFile); |
||
| 353 | } |
||
| 354 | $this->setBasePath($basePath); |
||
| 355 | $this->setRuntimePath($runtimePath); |
||
| 356 | } else { |
||
| 357 | throw new TConfigurationException('application_runtimepath_invalid', $runtimePath); |
||
| 358 | } |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Executes the lifecycles of the application. |
||
| 363 | * This is the main entry function that leads to the running of the whole |
||
| 364 | * Prado application. |
||
| 365 | */ |
||
| 366 | public function run() |
||
| 367 | { |
||
| 368 | try { |
||
| 369 | $this->initApplication(); |
||
| 370 | $n = count(self::$_steps); |
||
| 371 | $this->_step = 0; |
||
| 372 | $this->_requestCompleted = false; |
||
| 373 | while ($this->_step < $n) { |
||
| 374 | if ($this->_mode === TApplicationMode::Off) { |
||
| 375 | throw new THttpException(503, 'application_unavailable'); |
||
| 376 | } |
||
| 377 | if ($this->_requestCompleted) { |
||
| 378 | break; |
||
| 379 | } |
||
| 380 | $method = self::$_steps[$this->_step]; |
||
| 381 | Prado::trace("Executing $method()", 'Prado\TApplication'); |
||
| 382 | $this->$method(); |
||
| 383 | $this->_step++; |
||
| 384 | } |
||
| 385 | } catch (\Exception $e) { |
||
| 386 | $this->onError($e); |
||
| 387 | } |
||
| 388 | $this->onEndRequest(); |
||
| 389 | } |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Completes current request processing. |
||
| 393 | * This method can be used to exit the application lifecycles after finishing |
||
| 394 | * the current cycle. |
||
| 395 | */ |
||
| 396 | public function completeRequest() |
||
| 397 | { |
||
| 398 | $this->_requestCompleted = true; |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @return bool whether the current request is processed. |
||
| 403 | */ |
||
| 404 | public function getRequestCompleted() |
||
| 405 | { |
||
| 406 | return $this->_requestCompleted; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Returns a global value. |
||
| 411 | * |
||
| 412 | * A global value is one that is persistent across users sessions and requests. |
||
| 413 | * @param string $key the name of the value to be returned |
||
| 414 | * @param mixed $defaultValue the default value. If $key is not found, $defaultValue will be returned |
||
| 415 | * @return mixed the global value corresponding to $key |
||
| 416 | */ |
||
| 417 | public function getGlobalState($key, $defaultValue = null) |
||
| 418 | { |
||
| 419 | return isset($this->_globals[$key]) ? $this->_globals[$key] : $defaultValue; |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Sets a global value. |
||
| 424 | * |
||
| 425 | * A global value is one that is persistent across users sessions and requests. |
||
| 426 | * Make sure that the value is serializable and unserializable. |
||
| 427 | * @param string $key the name of the value to be set |
||
| 428 | * @param mixed $value the global value to be set |
||
| 429 | * @param null|mixed $defaultValue the default value. If $key is not found, $defaultValue will be returned |
||
| 430 | * @param bool $forceSave wheter to force an immediate GlobalState save. defaults to false |
||
| 431 | */ |
||
| 432 | public function setGlobalState($key, $value, $defaultValue = null, $forceSave = false) |
||
| 433 | { |
||
| 434 | $this->_stateChanged = true; |
||
| 435 | if ($value === $defaultValue) { |
||
| 436 | unset($this->_globals[$key]); |
||
| 437 | } else { |
||
| 438 | $this->_globals[$key] = $value; |
||
| 439 | } |
||
| 440 | if ($forceSave) { |
||
| 441 | $this->saveGlobals(); |
||
| 442 | } |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Clears a global value. |
||
| 447 | * |
||
| 448 | * The value cleared will no longer be available in this request and the following requests. |
||
| 449 | * @param string $key the name of the value to be cleared |
||
| 450 | */ |
||
| 451 | public function clearGlobalState($key) |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Loads global values from persistent storage. |
||
| 459 | * This method is invoked when {@link onLoadState OnLoadState} event is raised. |
||
| 460 | * After this method, values that are stored in previous requests become |
||
| 461 | * available to the current request via {@link getGlobalState}. |
||
| 462 | */ |
||
| 463 | protected function loadGlobals() |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Saves global values into persistent storage. |
||
| 470 | * This method is invoked when {@link onSaveState OnSaveState} event is raised. |
||
| 471 | */ |
||
| 472 | protected function saveGlobals() |
||
| 473 | { |
||
| 474 | if ($this->_stateChanged) { |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @return string application ID |
||
| 482 | */ |
||
| 483 | public function getID() |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @param string $value application ID |
||
| 490 | */ |
||
| 491 | public function setID($value) |
||
| 495 | |||
| 496 | /** |
||
| 497 | * @return string page service ID |
||
| 498 | */ |
||
| 499 | public function getPageServiceID() |
||
| 503 | |||
| 504 | /** |
||
| 505 | * @param string $value page service ID |
||
| 506 | */ |
||
| 507 | public function setPageServiceID($value) |
||
| 511 | |||
| 512 | /** |
||
| 513 | * @return string an ID that uniquely identifies this Prado application from the others |
||
| 514 | */ |
||
| 515 | public function getUniqueID() |
||
| 519 | |||
| 520 | /** |
||
| 521 | * @return TApplicationMode application mode. Defaults to TApplicationMode::Debug. |
||
| 522 | */ |
||
| 523 | public function getMode() |
||
| 527 | |||
| 528 | /** |
||
| 529 | * @param TApplicationMode $value application mode |
||
| 530 | */ |
||
| 531 | public function setMode($value) |
||
| 535 | |||
| 536 | /** |
||
| 537 | * @return string the directory containing the application configuration file (absolute path) |
||
| 538 | */ |
||
| 539 | public function getBasePath() |
||
| 543 | |||
| 544 | /** |
||
| 545 | * @param string $value the directory containing the application configuration file |
||
| 546 | */ |
||
| 547 | public function setBasePath($value) |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @return string the application configuration file (absolute path) |
||
| 554 | */ |
||
| 555 | public function getConfigurationFile() |
||
| 559 | |||
| 560 | /** |
||
| 561 | * @param string $value the application configuration file (absolute path) |
||
| 562 | */ |
||
| 563 | public function setConfigurationFile($value) |
||
| 567 | |||
| 568 | /** |
||
| 569 | * @return string the application configuration file (absolute path) |
||
| 570 | */ |
||
| 571 | public function getConfigurationType() |
||
| 575 | |||
| 576 | /** |
||
| 577 | * @param string $value the application configuration type. 'xml' and 'php' are valid values |
||
| 578 | */ |
||
| 579 | public function setConfigurationType($value) |
||
| 583 | |||
| 584 | /** |
||
| 585 | * @return string the application configuration type. default is 'xml' |
||
| 586 | */ |
||
| 587 | public function getConfigurationFileExt() |
||
| 600 | |||
| 601 | /** |
||
| 602 | * @return string the default configuration file name |
||
| 603 | */ |
||
| 604 | public function getConfigurationFileName() |
||
| 618 | |||
| 619 | /** |
||
| 620 | * @return string the directory storing cache data and application-level persistent data. (absolute path) |
||
| 621 | */ |
||
| 622 | public function getRuntimePath() |
||
| 626 | |||
| 627 | /** |
||
| 628 | * @param string $value the directory storing cache data and application-level persistent data. (absolute path) |
||
| 629 | */ |
||
| 630 | public function setRuntimePath($value) |
||
| 639 | |||
| 640 | /** |
||
| 641 | * @return IService the currently requested service |
||
| 642 | */ |
||
| 643 | public function getService() |
||
| 647 | |||
| 648 | /** |
||
| 649 | * @param IService $value the currently requested service |
||
| 650 | */ |
||
| 651 | public function setService($value) |
||
| 655 | |||
| 656 | /** |
||
| 657 | * Adds a module to application. |
||
| 658 | * Note, this method does not do module initialization. |
||
| 659 | * @param string $id ID of the module |
||
| 660 | * @param null|IModule $module module object or null if the module has not been loaded yet |
||
| 661 | */ |
||
| 662 | public function setModule($id, IModule $module = null) |
||
| 670 | |||
| 671 | /** |
||
| 672 | * @param mixed $id |
||
| 673 | * @return IModule the module with the specified ID, null if not found |
||
| 674 | */ |
||
| 675 | public function getModule($id) |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Returns a list of application modules indexed by module IDs. |
||
| 692 | * Modules that have not been loaded yet are returned as null objects. |
||
| 693 | * @return array list of loaded application modules, indexed by module IDs |
||
| 694 | */ |
||
| 695 | public function getModules() |
||
| 699 | |||
| 700 | /** |
||
| 701 | * Returns the list of application parameters. |
||
| 702 | * Since the parameters are returned as a {@link \Prado\Collections\TMap} object, you may use |
||
| 703 | * the returned result to access, add or remove individual parameters. |
||
| 704 | * @return \Prado\Collections\TMap the list of application parameters |
||
| 705 | */ |
||
| 706 | public function getParameters() |
||
| 710 | |||
| 711 | /** |
||
| 712 | * @return THttpRequest the request module |
||
| 713 | */ |
||
| 714 | public function getRequest() |
||
| 722 | |||
| 723 | /** |
||
| 724 | * @param THttpRequest $request the request module |
||
| 725 | */ |
||
| 726 | public function setRequest(THttpRequest $request) |
||
| 730 | |||
| 731 | /** |
||
| 732 | * @return THttpResponse the response module |
||
| 733 | */ |
||
| 734 | public function getResponse() |
||
| 742 | |||
| 743 | /** |
||
| 744 | * @param THttpRequest $response the request module |
||
| 745 | */ |
||
| 746 | public function setResponse(THttpResponse $response) |
||
| 750 | |||
| 751 | /** |
||
| 752 | * @return THttpSession the session module, null if session module is not installed |
||
| 753 | */ |
||
| 754 | public function getSession() |
||
| 762 | |||
| 763 | /** |
||
| 764 | * @param THttpSession $session the session module |
||
| 765 | */ |
||
| 766 | public function setSession(THttpSession $session) |
||
| 770 | |||
| 771 | /** |
||
| 772 | * @return TErrorHandler the error handler module |
||
| 773 | */ |
||
| 774 | public function getErrorHandler() |
||
| 782 | |||
| 783 | /** |
||
| 784 | * @param TErrorHandler $handler the error handler module |
||
| 785 | */ |
||
| 786 | public function setErrorHandler(TErrorHandler $handler) |
||
| 790 | |||
| 791 | /** |
||
| 792 | * @return TSecurityManager the security manager module |
||
| 793 | */ |
||
| 794 | public function getSecurityManager() |
||
| 802 | |||
| 803 | /** |
||
| 804 | * @param TSecurityManager $sm the security manager module |
||
| 805 | */ |
||
| 806 | public function setSecurityManager(TSecurityManager $sm) |
||
| 810 | |||
| 811 | /** |
||
| 812 | * @return TAssetManager asset manager |
||
| 813 | */ |
||
| 814 | public function getAssetManager() |
||
| 822 | |||
| 823 | /** |
||
| 824 | * @param TAssetManager $value asset manager |
||
| 825 | */ |
||
| 826 | public function setAssetManager(TAssetManager $value) |
||
| 830 | |||
| 831 | /** |
||
| 832 | * @return IStatePersister application state persister |
||
| 833 | */ |
||
| 834 | public function getApplicationStatePersister() |
||
| 842 | |||
| 843 | /** |
||
| 844 | * @param IStatePersister $persister application state persister |
||
| 845 | */ |
||
| 846 | public function setApplicationStatePersister(IStatePersister $persister) |
||
| 850 | |||
| 851 | /** |
||
| 852 | * @return ICache the cache module, null if cache module is not installed |
||
| 853 | */ |
||
| 854 | public function getCache() |
||
| 858 | |||
| 859 | /** |
||
| 860 | * @param \Prado\Caching\ICache $cache the cache module |
||
| 861 | */ |
||
| 862 | public function setCache(\Prado\Caching\ICache $cache) |
||
| 866 | |||
| 867 | /** |
||
| 868 | * @return IUser the application user |
||
| 869 | */ |
||
| 870 | public function getUser() |
||
| 874 | |||
| 875 | /** |
||
| 876 | * @param \Prado\Security\IUser $user the application user |
||
| 877 | */ |
||
| 878 | public function setUser(\Prado\Security\IUser $user) |
||
| 882 | |||
| 883 | /** |
||
| 884 | * @param bool $createIfNotExists whether to create globalization if it does not exist |
||
| 885 | * @return TGlobalization globalization module |
||
| 886 | */ |
||
| 887 | public function getGlobalization($createIfNotExists = true) |
||
| 895 | |||
| 896 | /** |
||
| 897 | * @param \Prado\I18N\TGlobalization $glob globalization module |
||
| 898 | */ |
||
| 899 | public function setGlobalization(\Prado\I18N\TGlobalization $glob) |
||
| 903 | |||
| 904 | /** |
||
| 905 | * @return TAuthorizationRuleCollection list of authorization rules for the current request |
||
| 906 | */ |
||
| 907 | public function getAuthorizationRules() |
||
| 914 | |||
| 915 | protected function getApplicationConfigurationClass() |
||
| 919 | |||
| 920 | protected function internalLoadModule($id, $force = false) |
||
| 943 | /** |
||
| 944 | * Applies an application configuration. |
||
| 945 | * @param TApplicationConfiguration $config the configuration |
||
| 946 | * @param bool $withinService whether the configuration is specified within a service. |
||
| 947 | */ |
||
| 948 | public function applyConfiguration($config, $withinService = false) |
||
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Loads configuration and initializes application. |
||
| 1025 | * Configuration file will be read and parsed (if a valid cached version exists, |
||
| 1026 | * it will be used instead). Then, modules are created and initialized; |
||
| 1027 | * Afterwards, the requested service is created and initialized. |
||
| 1028 | * @throws TConfigurationException if module is redefined of invalid type, or service not defined or of invalid type |
||
| 1029 | */ |
||
| 1030 | protected function initApplication() |
||
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Starts the specified service. |
||
| 1057 | * The service instance will be created. Its properties will be initialized |
||
| 1058 | * and the configurations will be applied, if any. |
||
| 1059 | * @param string $serviceID service ID |
||
| 1060 | */ |
||
| 1061 | public function startService($serviceID) |
||
| 1094 | |||
| 1095 | /** |
||
| 1096 | * Raises OnError event. |
||
| 1097 | * This method is invoked when an exception is raised during the lifecycles |
||
| 1098 | * of the application. |
||
| 1099 | * @param mixed $param event parameter |
||
| 1100 | */ |
||
| 1101 | public function onError($param) |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Raises OnBeginRequest event. |
||
| 1110 | * At the time when this method is invoked, application modules are loaded |
||
| 1111 | * and initialized, user request is resolved and the corresponding service |
||
| 1112 | * is loaded and initialized. The application is about to start processing |
||
| 1113 | * the user request. |
||
| 1114 | */ |
||
| 1115 | public function onBeginRequest() |
||
| 1119 | |||
| 1120 | /** |
||
| 1121 | * Raises OnAuthentication event. |
||
| 1122 | * This method is invoked when the user request needs to be authenticated. |
||
| 1123 | */ |
||
| 1124 | public function onAuthentication() |
||
| 1128 | |||
| 1129 | /** |
||
| 1130 | * Raises OnAuthenticationComplete event. |
||
| 1131 | * This method is invoked right after the user request is authenticated. |
||
| 1132 | */ |
||
| 1133 | public function onAuthenticationComplete() |
||
| 1137 | |||
| 1138 | /** |
||
| 1139 | * Raises OnAuthorization event. |
||
| 1140 | * This method is invoked when the user request needs to be authorized. |
||
| 1141 | */ |
||
| 1142 | public function onAuthorization() |
||
| 1146 | |||
| 1147 | /** |
||
| 1148 | * Raises OnAuthorizationComplete event. |
||
| 1149 | * This method is invoked right after the user request is authorized. |
||
| 1150 | */ |
||
| 1151 | public function onAuthorizationComplete() |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Raises OnLoadState event. |
||
| 1158 | * This method is invoked when the application needs to load state (probably stored in session). |
||
| 1159 | */ |
||
| 1160 | public function onLoadState() |
||
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Raises OnLoadStateComplete event. |
||
| 1168 | * This method is invoked right after the application state has been loaded. |
||
| 1169 | */ |
||
| 1170 | public function onLoadStateComplete() |
||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Raises OnPreRunService event. |
||
| 1177 | * This method is invoked right before the service is to be run. |
||
| 1178 | */ |
||
| 1179 | public function onPreRunService() |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * Runs the requested service. |
||
| 1186 | */ |
||
| 1187 | public function runService() |
||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * Raises OnSaveState event. |
||
| 1196 | * This method is invoked when the application needs to save state (probably stored in session). |
||
| 1197 | */ |
||
| 1198 | public function onSaveState() |
||
| 1203 | |||
| 1204 | /** |
||
| 1205 | * Raises OnSaveStateComplete event. |
||
| 1206 | * This method is invoked right after the application state has been saved. |
||
| 1207 | */ |
||
| 1208 | public function onSaveStateComplete() |
||
| 1212 | |||
| 1213 | /** |
||
| 1214 | * Raises OnPreFlushOutput event. |
||
| 1215 | * This method is invoked right before the application flushes output to client. |
||
| 1216 | */ |
||
| 1217 | public function onPreFlushOutput() |
||
| 1221 | |||
| 1222 | /** |
||
| 1223 | * Flushes output to client side. |
||
| 1224 | * @param bool $continueBuffering whether to continue buffering after flush if buffering was active |
||
| 1225 | */ |
||
| 1226 | public function flushOutput($continueBuffering = true) |
||
| 1230 | |||
| 1231 | /** |
||
| 1232 | * Raises OnEndRequest event. |
||
| 1233 | * This method is invoked when the application completes the processing of the request. |
||
| 1234 | */ |
||
| 1235 | public function onEndRequest() |
||
| 1241 | } |
||
| 1242 |
If you suppress an error, we recommend checking for the error condition explicitly: