@@ -33,18 +33,28 @@ abstract class Presenter extends Control implements Application\IPresenter
3333{
3434 /** bad link handling {@link Presenter::$invalidLinkMode} */
3535 public const
36- INVALID_LINK_SILENT = 0b0000 ,
37- INVALID_LINK_WARNING = 0b0001 ,
38- INVALID_LINK_EXCEPTION = 0b0010 ,
39- INVALID_LINK_TEXTUAL = 0b0100 ;
36+ InvalidLinkSilent = 0b0000 ,
37+ InvalidLinkWarning = 0b0001 ,
38+ InvalidLinkException = 0b0010 ,
39+ InvalidLinkTextual = 0b0100 ;
4040
4141 /** @internal special parameter key */
4242 public const
43- PRESENTER_KEY = 'presenter ' ,
44- SIGNAL_KEY = 'do ' ,
45- ACTION_KEY = 'action ' ,
46- FLASH_KEY = '_fid ' ,
47- DEFAULT_ACTION = 'default ' ;
43+ PresenterKey = 'presenter ' ,
44+ SignalKey = 'do ' ,
45+ ActionKey = 'action ' ,
46+ FlashKey = '_fid ' ,
47+ DefaultAction = 'default ' ;
48+
49+ public const INVALID_LINK_SILENT = self ::InvalidLinkSilent;
50+ public const INVALID_LINK_WARNING = self ::InvalidLinkWarning;
51+ public const INVALID_LINK_EXCEPTION = self ::InvalidLinkException;
52+ public const INVALID_LINK_TEXTUAL = self ::InvalidLinkTextual;
53+ public const PRESENTER_KEY = self ::PresenterKey;
54+ public const SIGNAL_KEY = self ::SignalKey;
55+ public const ACTION_KEY = self ::ActionKey;
56+ public const FLASH_KEY = self ::FlashKey;
57+ public const DEFAULT_ACTION = self ::DefaultAction;
4858
4959 /** @var int */
5060 public $ invalidLinkMode ;
@@ -879,7 +889,7 @@ protected function createRequest(
879889 // PROCESS ARGUMENTS
880890 if (is_subclass_of ($ presenterClass , self ::class)) {
881891 if ($ action === '' ) {
882- $ action = self ::DEFAULT_ACTION ;
892+ $ action = self ::DefaultAction ;
883893 }
884894
885895 $ current = ($ action === '* ' || strcasecmp ($ action , (string ) $ this ->action ) === 0 ) && $ presenterClass === static ::class;
@@ -947,16 +957,16 @@ protected function createRequest(
947957
948958 // ADD ACTION & SIGNAL & FLASH
949959 if ($ action ) {
950- $ args [self ::ACTION_KEY ] = $ action ;
960+ $ args [self ::ActionKey ] = $ action ;
951961 }
952962
953963 if (!empty ($ signal )) {
954- $ args [self ::SIGNAL_KEY ] = $ component ->getParameterId ($ signal );
955- $ current = $ current && $ args [self ::SIGNAL_KEY ] === $ this ->getParameter (self ::SIGNAL_KEY );
964+ $ args [self ::SignalKey ] = $ component ->getParameterId ($ signal );
965+ $ current = $ current && $ args [self ::SignalKey ] === $ this ->getParameter (self ::SignalKey );
956966 }
957967
958968 if (($ mode === 'redirect ' || $ mode === 'forward ' ) && $ this ->hasFlashSession ()) {
959- $ args [self ::FLASH_KEY ] = $ this ->getFlashKey ();
969+ $ args [self ::FlashKey ] = $ this ->getFlashKey ();
960970 }
961971
962972 $ this ->lastCreatedRequest = new Application \Request ($ presenter , Application \Request::FORWARD , $ args );
@@ -1011,7 +1021,7 @@ protected function requestToUrl(Application\Request $request, ?bool $relative =
10111021 $ url = $ this ->router ->constructUrl ($ request ->toArray (), $ this ->refUrlCache );
10121022 if ($ url === null ) {
10131023 $ params = $ request ->getParameters ();
1014- unset($ params [self ::ACTION_KEY ], $ params [self ::PRESENTER_KEY ]);
1024+ unset($ params [self ::ActionKey ], $ params [self ::PresenterKey ]);
10151025 $ params = urldecode (http_build_query ($ params , '' , ', ' ));
10161026 throw new InvalidLinkException ("No route for {$ request ->getPresenterName ()}: {$ request ->getParameter ('action ' )}( $ params) " );
10171027 }
@@ -1104,13 +1114,13 @@ public static function argsToParams(
11041114 */
11051115 protected function handleInvalidLink (InvalidLinkException $ e ): string
11061116 {
1107- if ($ this ->invalidLinkMode & self ::INVALID_LINK_EXCEPTION ) {
1117+ if ($ this ->invalidLinkMode & self ::InvalidLinkException ) {
11081118 throw $ e ;
1109- } elseif ($ this ->invalidLinkMode & self ::INVALID_LINK_WARNING ) {
1119+ } elseif ($ this ->invalidLinkMode & self ::InvalidLinkWarning ) {
11101120 trigger_error ('Invalid link: ' . $ e ->getMessage (), E_USER_WARNING );
11111121 }
11121122
1113- return $ this ->invalidLinkMode & self ::INVALID_LINK_TEXTUAL
1123+ return $ this ->invalidLinkMode & self ::InvalidLinkTextual
11141124 ? '#error: ' . $ e ->getMessage ()
11151125 : '# ' ;
11161126 }
@@ -1149,7 +1159,7 @@ public function restoreRequest(string $key): void
11491159 $ request = clone $ session [$ key ][1 ];
11501160 unset($ session [$ key ]);
11511161 $ params = $ request ->getParameters ();
1152- $ params [self ::FLASH_KEY ] = $ this ->getFlashKey ();
1162+ $ params [self ::FlashKey ] = $ this ->getFlashKey ();
11531163 $ request ->setParameters ($ params );
11541164 if ($ request ->isMethod ('POST ' )) {
11551165 $ request ->setFlag (Application \Request::RESTORED , true );
@@ -1284,12 +1294,12 @@ private function initGlobalParameters(): void
12841294 $ selfParams = [];
12851295
12861296 $ params = $ this ->request ->getParameters ();
1287- if (($ tmp = $ this ->request ->getPost ('_ ' . self ::SIGNAL_KEY )) !== null ) {
1288- $ params [self ::SIGNAL_KEY ] = $ tmp ;
1297+ if (($ tmp = $ this ->request ->getPost ('_ ' . self ::SignalKey )) !== null ) {
1298+ $ params [self ::SignalKey ] = $ tmp ;
12891299 } elseif ($ this ->isAjax ()) {
12901300 $ params += $ this ->request ->getPost ();
1291- if (($ tmp = $ this ->request ->getPost (self ::SIGNAL_KEY )) !== null ) {
1292- $ params [self ::SIGNAL_KEY ] = $ tmp ;
1301+ if (($ tmp = $ this ->request ->getPost (self ::SignalKey )) !== null ) {
1302+ $ params [self ::SignalKey ] = $ tmp ;
12931303 }
12941304 }
12951305
@@ -1304,7 +1314,7 @@ private function initGlobalParameters(): void
13041314 }
13051315
13061316 // init & validate $this->action & $this->view
1307- $ action = $ selfParams [self ::ACTION_KEY ] ?? self ::DEFAULT_ACTION ;
1317+ $ action = $ selfParams [self ::ActionKey ] ?? self ::DefaultAction ;
13081318 if (!is_string ($ action ) || !Nette \Utils \Strings::match ($ action , '#^[a-zA-Z0-9][a-zA-Z0-9_\x7f-\xff]*$#D ' )) {
13091319 $ this ->error ('Action name is not valid. ' );
13101320 }
@@ -1313,8 +1323,8 @@ private function initGlobalParameters(): void
13131323
13141324 // init $this->signalReceiver and key 'signal' in appropriate params array
13151325 $ this ->signalReceiver = $ this ->getUniqueId ();
1316- if (isset ($ selfParams [self ::SIGNAL_KEY ])) {
1317- $ param = $ selfParams [self ::SIGNAL_KEY ];
1326+ if (isset ($ selfParams [self ::SignalKey ])) {
1327+ $ param = $ selfParams [self ::SignalKey ];
13181328 if (!is_string ($ param )) {
13191329 $ this ->error ('Signal name is not string. ' );
13201330 }
@@ -1354,7 +1364,7 @@ final public function popGlobalParameters(string $id): array
13541364
13551365 private function getFlashKey (): ?string
13561366 {
1357- $ flashKey = $ this ->getParameter (self ::FLASH_KEY );
1367+ $ flashKey = $ this ->getParameter (self ::FlashKey );
13581368 return is_string ($ flashKey ) && $ flashKey !== ''
13591369 ? $ flashKey
13601370 : null ;
@@ -1379,7 +1389,7 @@ public function getFlashSession(): Http\SessionSection
13791389 {
13801390 $ flashKey = $ this ->getFlashKey ();
13811391 if ($ flashKey === null ) {
1382- $ this ->params [self ::FLASH_KEY ] = $ flashKey = Nette \Utils \Random::generate (4 );
1392+ $ this ->params [self ::FlashKey ] = $ flashKey = Nette \Utils \Random::generate (4 );
13831393 }
13841394
13851395 return $ this ->getSession ('Nette.Application.Flash/ ' . $ flashKey );
0 commit comments