Source for file Presenter.php
Documentation is available at Presenter.php
- 1: <?php
- 3: /**
- 4: * Nette Framework
- 5: *
- 6: * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
- 7: *
- 8: * This source file is subject to the "Nette license" that is bundled
- 9: * with this package in the file license.txt.
- 10: *
- 11: * For more information please see http://nettephp.com
- 12: *
- 18: */
- 28: /**
- 29: * Presenter object represents a webpage instance. It executes all the logic for the request.
- 30: *
- 34: *
- 43: */
- 45: {
- 46: /**#@+ life cycle phases {@link Presenter::getPhase()} */
- 51: /**#@-*/
- 53: /**#@+ bad link handling {@link Presenter::$invalidLinkMode} */
- 57: /**#@-*/
- 59: /**#@+ @ignore internal special parameter key */
- 63: /**#@-*/
- 71: /** @var array of function(Presenter $sender, IPresenterResponse $response = NULL); Occurs when the presenter is shutting down */
- 136: /**
- 138: */
- 140: {
- 142: }
- 146: /**
- 147: * Returns self.
- 149: */
- 151: {
- 153: }
- 157: /**
- 158: * Returns a name that uniquely identifies component.
- 160: */
- 162: {
- 164: }
- 168: /********************* interface IPresenter ****************d*g**/
- 172: /**
- 175: */
- 177: {
- 179: // PHASE 1: STARTUP
- 189: trigger_error("Method $class::startup() or its descendant doesn't call parent::startup().", E_USER_WARNING);
- 190: }
- 191: // calls $this->action<Action>()
- 196: }
- 199: }
- 201: // back compatibility
- 204: trigger_error('beforePrepare() is deprecated; use createComponent{Name}() instead.', E_USER_WARNING);
- 205: }
- 207: trigger_error('prepare' . ucfirst($this->getView()) . '() is deprecated; use createComponent{Name}() instead.', E_USER_WARNING);
- 208: }
- 210: // PHASE 2: SIGNAL HANDLING
- 212: // calls $this->handle<Signal>()
- 215: // PHASE 3: RENDERING VIEW
- 219: // calls $this->render<View>()
- 223: // save component tree persistent state
- 227: }
- 229: // finish template rendering
- 233: // continue with shutting down
- 236: // PHASE 4: SHUTDOWN
- 241: if ($this->response instanceof RenderResponse && ($this->isControlInvalid() || $hasPayload)) { // snippets - TODO
- 246: } elseif (!$this->response && $hasPayload) { // back compatibility for use terminate() instead of sendPayload()
- 248: }
- 252: $this->getFlashSession()->setExpiration($this->response instanceof RedirectingResponse ? '+ 30 seconds': '+ 3 seconds');
- 253: }
- 259: }
- 260: }
- 264: /**
- 265: * Returns current presenter life cycle phase.
- 267: */
- 269: {
- 271: }
- 275: /**
- 277: */
- 279: {
- 281: }
- 285: /**
- 286: * Common render method.
- 288: */
- 290: {
- 291: }
- 295: /**
- 296: * Common render method.
- 298: */
- 300: {
- 301: }
- 305: /**
- 308: */
- 310: {
- 311: }
- 315: /********************* signal handling ****************d*g**/
- 319: /**
- 322: */
- 324: {
- 327: $component = $this->signalReceiver === '' ? $this : $this->getComponent($this->signalReceiver, FALSE);
- 329: throw new BadSignalException("The signal receiver component '$this->signalReceiver' is not found.");
- 332: throw new BadSignalException("The signal receiver component '$this->signalReceiver' is not ISignalReceiver implementor.");
- 333: }
- 335: // auto invalidate
- 338: }
- 342: }
- 346: /**
- 347: * Returns pair signal receiver and name.
- 349: */
- 351: {
- 353: }
- 357: /**
- 358: * Checks if the signal receiver is the given one.
- 362: */
- 364: {
- 367: }
- 381: }
- 382: }
- 386: /********************* rendering ****************d*g**/
- 390: /**
- 391: * Returns current action name.
- 393: */
- 395: {
- 397: }
- 401: /**
- 402: * Changes current action. Only alphanumeric characters are allowed.
- 405: */
- 407: {
- 414: }
- 415: }
- 419: /**
- 420: * Returns current view.
- 422: */
- 424: {
- 426: }
- 430: /**
- 431: * Changes current view. Any name is allowed.
- 434: */
- 436: {
- 439: }
- 443: /**
- 444: * Returns current layout name.
- 446: */
- 448: {
- 450: }
- 454: /**
- 455: * Changes or disables layout.
- 458: */
- 460: {
- 463: }
- 467: /**
- 471: */
- 473: {
- 479: // content template
- 485: }
- 486: }
- 491: }
- 493: // layout template
- 495: $files = $this->formatLayoutTemplateFiles($this->getName(), $this->layout ? $this->layout : 'layout');
- 504: }
- 506: }
- 507: }
- 512: }
- 513: }
- 514: }
- 517: }
- 521: /**
- 522: * Formats layout template file names.
- 526: */
- 528: {
- 530: $root = Environment::getVariable('templatesDir', Environment::getVariable('appDir') . '/templates'); // back compatibility
- 540: }
- 541: }
- 548: }
- 559: }
- 561: }
- 565: /**
- 566: * Formats view template file names.
- 570: */
- 572: {
- 574: $root = Environment::getVariable('templatesDir', Environment::getVariable('appDir') . '/templates'); // back compatibility
- 579: $presenter = $pos === FALSE ? 'templates/' . $presenter : substr_replace($presenter, '/templates', $pos, 0);
- 581: }
- 587: }
- 598: }
- 602: /**
- 603: * Formats action method name.
- 606: */
- 608: {
- 610: }
- 614: /**
- 615: * Formats render view method name.
- 618: */
- 620: {
- 622: }
- 626: /**
- 628: */
- 630: {
- 631: throw new DeprecatedException(__METHOD__ . '() is deprecated; use $presenter->sendTemplate() instead.');
- 632: }
- 636: /********************* partial AJAX rendering ****************d*g**/
- 640: /**
- 642: */
- 644: {
- 646: }
- 650: /**
- 651: * Is AJAX request?
- 653: */
- 655: {
- 658: }
- 660: }
- 664: /**
- 665: * Sends AJAX payload to the output.
- 668: */
- 670: {
- 672: }
- 676: /**
- 678: */
- 680: {
- 681: throw new DeprecatedException(__METHOD__ . '() is deprecated; use $presenter->payload instead.');
- 682: }
- 686: /********************* navigation & flow ****************d*g**/
- 690: /**
- 691: * Forward to another presenter or action.
- 696: */
- 698: {
- 705: }
- 709: }
- 713: /**
- 714: * Redirect to another URL and ends presenter execution.
- 719: */
- 721: {
- 727: $code = $this->getHttpRequest()->isMethod('post') ? IHttpResponse::S303_POST_GET : IHttpResponse::S302_FOUND;
- 728: }
- 730: }
- 734: /**
- 735: * Link to myself.
- 737: */
- 739: {
- 741: }
- 745: /**
- 746: * Returns the last created PresenterRequest.
- 748: */
- 750: {
- 752: }
- 756: /**
- 757: * Returns the last created PresenterRequest flag.
- 760: */
- 762: {
- 764: }
- 768: /**
- 769: * Correctly terminates presenter.
- 773: */
- 775: {
- 778: }
- 782: /**
- 783: * Conditional redirect to canonicalized URI.
- 786: */
- 788: {
- 790: $uri = $this->createRequest($this, $this->action, $this->getGlobalState() + $this->request->params, 'redirectX');
- 793: }
- 794: }
- 795: }
- 799: /**
- 800: * Attempts to cache the sent entity by its last modification date
- 806: */
- 808: {
- 811: }
- 818: }
- 823: }
- 827: }
- 833: }
- 844: }
- 845: }
- 853: }
- 854: }
- 863: }
- 866: }
- 870: /**
- 871: * PresenterRequest/URL factory.
- 879: */
- 881: {
- 882: // note: createRequest supposes that saveState(), run() & tryCall() behaviour is final
- 884: // cached services for better performance
- 890: }
- 894: // PARSE DESTINATION
- 895: // 1) fragment
- 902: }
- 904: // 2) ?query syntax
- 909: }
- 911: // 3) URL scheme
- 918: }
- 920: // 4) signal or empty
- 927: }
- 930: }
- 932: }
- 936: }
- 938: // 5) presenter: action
- 951: }
- 961: }
- 962: }
- 964: }
- 966: // PROCESS SIGNAL ARGUMENTS
- 973: }
- 976: // counterpart of signalReceived() & tryCall()
- 980: }
- 983: }
- 984: }
- 986: // counterpart of IStatePersistent
- 989: }
- 996: }
- 997: }
- 998: }
- 1000: // PROCESS ARGUMENTS
- 1003: /*$action = $presenterClass::$defaultAction;*/ // in PHP 5.3
- 1005: }
- 1010: // counterpart of run() & tryCall()
- 1011: // in PHP 5.3
- 1014: // in PHP 5.3
- 1018: }
- 1019: }
- 1021: // convert indexed parameters to named
- 1025: }
- 1032: }
- 1033: }
- 1035: // counterpart of IStatePersistent
- 1036: if ($args && array_intersect_key($args, PresenterHelpers::getPersistentParams($presenterClass))) {
- 1038: }
- 1047: }
- 1048: }
- 1049: }
- 1051: }
- 1053: // ADD ACTION & SIGNAL & FLASH
- 1058: }
- 1061: }
- 1074: // CONSTRUCT URL
- 1080: }
- 1082: // make URL relative if possible
- 1087: }
- 1088: }
- 1091: }
- 1095: /**
- 1096: * Invalid link handler. Descendant can override this method to change default behaviour.
- 1100: */
- 1102: {
- 1106: }
- 1116: }
- 1117: }
- 1121: /********************* interface IStatePersistent ****************d*g**/
- 1125: /**
- 1126: * Returns array of persistent components.
- 1127: * This default implementation detects components by class-level annotation @persistent(cmp1, cmp2).
- 1129: */
- 1131: {
- 1133: }
- 1137: /**
- 1138: * Saves state information for all subcomponents to $this->globalState.
- 1140: */
- 1142: {
- 1148: }
- 1155: }
- 1156: }
- 1163: }
- 1164: }
- 1169: {
- 1171: // counts with RecursiveIteratorIterator::SELF_FIRST
- 1172: $since = isset($components[$name]['since']) ? $components[$name]['since'] : FALSE; // FALSE = nonpersistent
- 1173: }
- 1180: }
- 1181: }
- 1185: }
- 1194: }
- 1198: }
- 1201: }
- 1202: }
- 1203: }
- 1206: }
- 1210: /**
- 1211: * Permanently saves state information for all subcomponents to $this->globalState.
- 1213: */
- 1215: {
- 1216: // load lazy components
- 1219: }
- 1223: }
- 1227: /**
- 1228: * Initializes $this->globalParams, $this->signal & $this->signalReceiver, $this->action, $this->view. Called by run().
- 1231: */
- 1233: {
- 1234: // init $this->globalParams
- 1241: }
- 1249: }
- 1250: }
- 1252: // init & validate $this->action & $this->view
- 1253: $this->changeAction(isset($selfParams[self::ACTION_KEY]) ? $selfParams[self::ACTION_KEY] : self::$defaultAction);
- 1255: // init $this->signalReceiver and key 'signal' in appropriate params array
- 1266: }
- 1269: }
- 1270: }
- 1273: }
- 1277: /**
- 1278: * Pops parameters for specified component.
- 1281: */
- 1283: {
- 1291: }
- 1292: }
- 1296: /********************* flash session ****************d*g**/
- 1300: /**
- 1301: * Checks if a flash session namespace exists.
- 1303: */
- 1305: {
- 1307: && $this->getSession()->hasNamespace('Nette.Application.Flash/' . $this->params[self::FLASH_KEY]);
- 1308: }
- 1312: /**
- 1313: * Returns session namespace provided to pass temporary data between redirects.
- 1315: */
- 1317: {
- 1320: }
- 1322: }
- 1326: /********************* backend ****************d*g**/
- 1330: /**
- 1332: */
- 1334: {
- 1336: }
- 1340: /**
- 1342: */
- 1344: {
- 1346: }
- 1350: /**
- 1352: */
- 1354: {
- 1356: }
- 1360: /**
- 1362: */
- 1364: {
- 1366: }
- 1370: /**
- 1372: */
- 1374: {
- 1376: }
- 1378: }