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: * NPresenter object represents a webpage instance. It executes all the logic for the request.
- 30: *
- 34: *
- 43: */
- 45: {
- 46: /**#@+ life cycle phases {@link NPresenter::getPhase()} */
- 51: /**#@-*/
- 53: /**#@+ bad link handling {@link NPresenter::$invalidLinkMode} */
- 57: /**#@-*/
- 59: /**#@+ special parameter key */
- 63: /**#@-*/
- 71: /** @var array of function(NPresenter $sender, IPresenterResponse $response = NULL); Occurs when the presenter is shutting down */
- 133: /**
- 135: */
- 137: {
- 139: }
- 143: /**
- 144: * Returns self.
- 146: */
- 148: {
- 150: }
- 154: /**
- 155: * Returns a name that uniquely identifies component.
- 157: */
- 159: {
- 161: }
- 165: /********************* interface IPresenter ****************d*g**/
- 169: /**
- 172: */
- 174: {
- 176: // PHASE 1: STARTUP
- 186: trigger_error("Method $class::startup() or its descendant doesn't call parent::startup().", E_USER_WARNING);
- 187: }
- 188: // calls $this->action<Action>()
- 193: }
- 196: }
- 198: // back compatibility
- 201: trigger_error('beforePrepare() is deprecated; use createComponent{Name}() instead.', E_USER_WARNING);
- 202: }
- 204: trigger_error('prepare' . ucfirst($this->getView()) . '() is deprecated; use createComponent{Name}() instead.', E_USER_WARNING);
- 205: }
- 207: // PHASE 2: SIGNAL HANDLING
- 209: // calls $this->handle<Signal>()
- 212: // PHASE 3: RENDERING VIEW
- 216: // calls $this->render<View>()
- 220: // save component tree persistent state
- 224: }
- 226: // finish template rendering
- 230: // continue with shutting down
- 233: // PHASE 4: SHUTDOWN
- 236: // back compatibility for use terminate() instead of sendPayload()
- 237: if ($this->isAjax() && !($this->response instanceof NForwardingResponse || $this->response instanceof NJsonResponse) && (array) $this->payload) {
- 240: }
- 243: $this->getFlashSession()->setExpiration($this->response instanceof NRedirectingResponse ? '+ 30 seconds': '+ 3 seconds');
- 244: }
- 250: }
- 251: }
- 255: /**
- 256: * Returns current presenter life cycle phase.
- 258: */
- 260: {
- 262: }
- 266: /**
- 268: */
- 270: {
- 272: }
- 276: /**
- 277: * Common render method.
- 279: */
- 281: {
- 282: }
- 286: /**
- 287: * Common render method.
- 289: */
- 291: {
- 292: }
- 296: /**
- 299: */
- 301: {
- 302: }
- 306: /********************* signal handling ****************d*g**/
- 310: /**
- 313: */
- 315: {
- 318: $component = $this->signalReceiver === '' ? $this : $this->getComponent($this->signalReceiver, FALSE);
- 320: throw new NBadSignalException("The signal receiver component '$this->signalReceiver' is not found.");
- 323: throw new NBadSignalException("The signal receiver component '$this->signalReceiver' is not ISignalReceiver implementor.");
- 324: }
- 326: // auto invalidate
- 329: }
- 333: }
- 337: /**
- 338: * Returns pair signal receiver and name.
- 340: */
- 342: {
- 344: }
- 348: /**
- 349: * Checks if the signal receiver is the given one.
- 353: */
- 355: {
- 358: }
- 372: }
- 373: }
- 377: /********************* rendering ****************d*g**/
- 381: /**
- 382: * Returns current action name.
- 384: */
- 386: {
- 388: }
- 392: /**
- 393: * Changes current action. Only alphanumeric characters are allowed.
- 396: */
- 398: {
- 405: }
- 406: }
- 410: /**
- 411: * Returns current view.
- 413: */
- 415: {
- 417: }
- 421: /**
- 422: * Changes current view. Any name is allowed.
- 425: */
- 427: {
- 430: }
- 434: /**
- 435: * Returns current layout name.
- 437: */
- 439: {
- 441: }
- 445: /**
- 446: * Changes or disables layout.
- 449: */
- 451: {
- 454: }
- 458: /**
- 462: */
- 464: {
- 470: // content template
- 476: }
- 477: }
- 482: }
- 484: // layout template
- 493: }
- 495: }
- 496: }
- 497: }
- 498: }
- 504: }
- 507: }
- 511: /**
- 512: * Formats layout template file names.
- 516: */
- 518: {
- 529: }
- 530: }
- 538: }
- 542: /**
- 543: * Formats view template file names.
- 547: */
- 549: {
- 555: $presenter = $pos === FALSE ? 'templates/' . $presenter : substr_replace($presenter, '/templates', $pos, 0);
- 557: }
- 563: }
- 567: /**
- 568: * Formats action method name.
- 571: */
- 573: {
- 575: }
- 579: /**
- 580: * Formats render view method name.
- 583: */
- 585: {
- 587: }
- 591: /**
- 593: */
- 595: {
- 596: throw new DeprecatedException(__METHOD__ . '() is deprecated; use $presenter->sendTemplate() instead.');
- 597: }
- 601: /********************* partial AJAX rendering ****************d*g**/
- 605: /**
- 607: */
- 609: {
- 611: }
- 615: /**
- 616: * Is AJAX request?
- 618: */
- 620: {
- 623: }
- 625: }
- 629: /**
- 630: * Sends AJAX payload to the output.
- 633: */
- 635: {
- 637: }
- 641: /**
- 643: */
- 645: {
- 646: throw new DeprecatedException(__METHOD__ . '() is deprecated; use $presenter->payload instead.');
- 647: }
- 651: /********************* navigation & flow ****************d*g**/
- 655: /**
- 656: * Forward to another presenter or action.
- 661: */
- 663: {
- 670: }
- 674: }
- 678: /**
- 679: * Redirect to another URL and ends presenter execution.
- 684: */
- 686: {
- 692: $code = $this->getHttpRequest()->isMethod('post') ? IHttpResponse::S303_POST_GET : IHttpResponse::S302_FOUND;
- 693: }
- 695: }
- 699: /**
- 700: * NLink to myself.
- 702: */
- 704: {
- 706: }
- 710: /**
- 711: * Returns the last created NPresenterRequest.
- 713: */
- 715: {
- 717: }
- 721: /**
- 722: * Returns the last created NPresenterRequest flag.
- 725: */
- 727: {
- 729: }
- 733: /**
- 734: * Correctly terminates presenter.
- 738: */
- 740: {
- 743: }
- 747: /**
- 748: * Conditional redirect to canonicalized URI.
- 751: */
- 753: {
- 755: $uri = $this->createRequest($this, $this->action, $this->getGlobalState() + $this->request->params, 'redirectX');
- 758: }
- 759: }
- 760: }
- 764: /**
- 765: * Attempts to cache the sent entity by its last modification date
- 771: */
- 773: {
- 776: }
- 783: }
- 788: }
- 792: }
- 798: }
- 809: }
- 810: }
- 818: }
- 819: }
- 828: }
- 831: }
- 835: /**
- 836: * PresenterRequest/URL factory.
- 844: */
- 846: {
- 847: // note: createRequest supposes that saveState(), run() & tryCall() behaviour is final
- 849: // cached services for better performance
- 855: }
- 859: // PARSE DESTINATION
- 860: // 1) fragment
- 867: }
- 869: // 2) ?query syntax
- 874: }
- 876: // 3) URL scheme
- 883: }
- 885: // 4) signal or empty
- 892: }
- 895: }
- 897: }
- 901: }
- 903: // 5) presenter: action
- 916: }
- 926: }
- 927: }
- 929: }
- 931: // PROCESS SIGNAL ARGUMENTS
- 938: }
- 941: // counterpart of signalReceived() & tryCall()
- 945: }
- 948: }
- 949: }
- 951: // counterpart of IStatePersistent
- 954: }
- 961: }
- 962: }
- 963: }
- 965: // PROCESS ARGUMENTS
- 968: /*$action = $presenterClass::$defaultAction;*/ // in PHP 5.3
- 970: }
- 975: // counterpart of run() & tryCall()
- 976: // in PHP 5.3
- 979: // in PHP 5.3
- 983: }
- 984: }
- 986: // convert indexed parameters to named
- 990: }
- 997: }
- 998: }
- 1000: // counterpart of IStatePersistent
- 1001: if ($args && array_intersect_key($args, NPresenterHelpers::getPersistentParams($presenterClass))) {
- 1003: }
- 1012: }
- 1013: }
- 1014: }
- 1016: }
- 1018: // ADD ACTION & SIGNAL & FLASH
- 1023: }
- 1026: }
- 1039: // CONSTRUCT URL
- 1045: }
- 1047: // make URL relative if possible
- 1052: }
- 1053: }
- 1056: }
- 1060: /**
- 1061: * Invalid link handler. Descendant can override this method to change default behaviour.
- 1065: */
- 1067: {
- 1071: }
- 1081: }
- 1082: }
- 1086: /********************* interface IStatePersistent ****************d*g**/
- 1090: /**
- 1091: * Returns array of persistent components.
- 1092: * This default implementation detects components by class-level annotation @persistent(cmp1, cmp2).
- 1094: */
- 1096: {
- 1098: }
- 1102: /**
- 1103: * Saves state information for all subcomponents to $this->globalState.
- 1105: */
- 1107: {
- 1113: }
- 1120: }
- 1121: }
- 1128: }
- 1129: }
- 1134: {
- 1136: // counts with RecursiveIteratorIterator::SELF_FIRST
- 1137: $since = isset($components[$name]['since']) ? $components[$name]['since'] : FALSE; // FALSE = nonpersistent
- 1138: }
- 1145: }
- 1146: }
- 1150: }
- 1159: }
- 1163: }
- 1166: }
- 1167: }
- 1168: }
- 1171: }
- 1175: /**
- 1176: * Permanently saves state information for all subcomponents to $this->globalState.
- 1178: */
- 1180: {
- 1181: // load lazy components
- 1184: }
- 1188: }
- 1192: /**
- 1193: * Initializes $this->globalParams, $this->signal & $this->signalReceiver, $this->action, $this->view. Called by run().
- 1196: */
- 1198: {
- 1199: // init $this->globalParams
- 1206: }
- 1214: }
- 1215: }
- 1217: // init & validate $this->action & $this->view
- 1218: $this->changeAction(isset($selfParams[self::ACTION_KEY]) ? $selfParams[self::ACTION_KEY] : self::$defaultAction);
- 1220: // init $this->signalReceiver and key 'signal' in appropriate params array
- 1231: }
- 1234: }
- 1235: }
- 1238: }
- 1242: /**
- 1243: * Pops parameters for specified component.
- 1246: */
- 1248: {
- 1256: }
- 1257: }
- 1261: /********************* flash session ****************d*g**/
- 1265: /**
- 1266: * Checks if a flash session namespace exists.
- 1268: */
- 1270: {
- 1273: }
- 1277: /**
- 1278: * Returns session namespace provided to pass temporary data between redirects.
- 1280: */
- 1282: {
- 1285: }
- 1287: }
- 1291: /********************* backend ****************d*g**/
- 1295: /**
- 1297: */
- 1299: {
- 1301: }
- 1305: /**
- 1307: */
- 1309: {
- 1311: }
- 1315: /**
- 1317: */
- 1319: {
- 1321: }
- 1325: /**
- 1327: */
- 1329: {
- 1331: }
- 1333: }