Jet\MVC_Router
You already know what a router is and what its role is. Now let's take a detailed look at what information it provides. That is, the methods of the Jet\MVC_Router class and also the Jet\MVC_Router_Interface interface.
The class is instantiated principally using factories
Basic methods
| Method | Meaning of |
|---|---|
| public resolve( string $request_URL ): void |
Carry out the resolving process. So, based on the URL, it finds the corresponding base, locale and page and also asks the page to complete the resollving. This means that the resolvers of the controllers will also be called here content. In practice, this means, for example,resolving the rest of the URL that the router didn't catch (part of the URL no longer belongs to any page), which may belong to, for example, an article, a specific item in an e-shop, etc. |
| public getSetSystemLocale( ): bool |
Indicates whether the router should set the localization to the Locale class immediately after detecting the localization - i.e. the current system localization. Setting the system locale can be important for the evaluation process. Therefore, this setting can be done immediately by the router. Default state: true |
| public setSetSystemLocale( bool $set_system_locale ): void |
Sets whether or not to immediately set the detected locale to the Locale class - i.e. the current system locale. |
| public getSetTranslatorLocale( ): bool |
Indicates whether the router should set the localization to the Translator class immediately after detecting the localization. Setting the translator localization can be important for the evaluation process. Therefore, this setting can be done immediately by the router. Default state: true |
| public setSetTranslatorLocale( bool $set_translator_locale ): void |
Nastavuje zda ihned nastavovat / nenastavovat zjištěnou lokalizaci překladači - třídě Translator. |
Methods for determining the assessed status
| Method | Meaning of |
|---|---|
| public getIs404( ): bool |
Indicates whether the URL has been evaluated as a non-existent page. |
| public getIsRedirect( ): bool |
Indicates whether a redirect to another URL is requested. |
| public getRedirectTargetURL( ): string |
If a redirect is requested, then it returns the destination URL. |
| public getRedirectType( ): int |
If a redirect is requested, then it returns its type - http code. |
| public getLoginRequired( ): bool |
Indicates whether a user login is required (the page is secret and the user is not logged in). |
| public getAccessNotAllowed( ): bool |
Indicates that the user is logged in, but does not have permission to view/use the page. |
| public getUrlPath( ): string |
Example: the request URL is: https://domain/path-a/path-b/ Then this method returns /path-a/path-b/ |
| public getUsedUrlPath( ): string |
Returns the path from the URL that the router was already informed about as used (see the setUsedUrlPath method) |
| public getHasUnusedUrlPath( ): bool |
Indicates whether the router still has any unprocessed (and unused) part of the URL path. |
| public getValidUrl( ): string |
Returns a URL that should be valid (does not contain unused parts, has a default base URL, etc.) |
| public getBase( ): ?MVC_Base_Interface |
Returns an instance of the found base. |
| public getLocale( ): ?Locale |
Returns an instance of the found locale. |
| public getPage( ): ?MVC_Page_Interface |
Returns an instance of the found page. |
Methods used in the resolving process
As you already know, the router will determine the base, locale and page, but it will also let the page (and especially its content) re-evaluate the whole situation. Therefore, the router must have methods to get feedback from the resolving process.
| Method | Meaning of |
|---|---|
| public setIs404( ): void |
Sets that this is a request for a non-existent page (404). |
| public setLocale( Locale $locale ): void |
During initialization (calling the initialization method), it is additionally possible to change the Locale specified by the router. |
| public setUsedUrlPath( string $used_path ): void |
Important method! If your application processes parts of the URL, it must let the router know that it has indeed used that part of the URL and that it is therefore no longer unknown. If your application does not do this, the router will consider that part of the URL as ballast and will eventually set the redirect to the last known valid URL. |
| public setIsRedirect( string $target_URL, int $http_code = Http_Headers::CODE_302_MOVED_TEMPORARY ) |
It sets that redirection is required and passes redirection parameters (to what URL, with what http code). |
| public setAccessNotAllowed( ): void |
Sets that the user cannot access the page due to insufficient privileges. |
| public setLoginRequired( ): void |
Nastavuje že bude požadováno přihlášení (stránka je tajná, ale uživatel není přihlášen) |
| public tryDirectFiles( ?array $allowed_files=null ): void |
It will try to find and output files located in the root directory of the pages. These can be files such as robots.txt, security.txt, sitemap.xml and others. For security reasons, this method is not called automatically, but is called in the database initializer only if we expect this behavior for the given base. The $allowed_files parameter can either have a null value or explicitly list the names of files that can be sent this way. If the value is null, then all files in the root directory are automatically allowed except files with the .php extension. |