Attributes

path
stateless
format
accessGroups
bypass404
getRenderFullHtml
includeEasyAssets
cacheLifetime
includeCsrf
options

path

Type: String


The relative path to the page.


Important: The path must always start with a forward slash (/).


Example:

#[Route(path: '/path/to/the/page')]

stateless

Type: Boolean


Determines whether the page should be cached by TYPO3.
Set this to false if the response needs to be processed on every request.
Default: true


Example:

#[Route(path: '/path/to/the/page', stateless: false)]

format

Type: String (keyword)


The response format. Possible keywords are: 'html', 'json', 'file' or 'custom'.
If unset 'custom' will be used as default.

htmljson

This keyword instructs the method to render a template file.

Use the path as the first parameter.

$this->render('/path/to/the/template.html');

Use this keyword if you want to return data in JSON format.

 

$this->render(['answer' => 43]);
filecustom

As the name suggests, this keyword instructs the controller

to respond with a file using RAM-friendly chunked transfer encoding.

$this->render('/var/www/html/public/fileadmin/img/avatar.png');

This is the default behavior.

The render keyword accepts raw output as its first parameter.

$response = '<p>It weights 4 courics</p>'; 
$this->render($response);

accessGroups

Type: Array


List of user groups allowed to access the route.
Easy automatically checks whether the visitor is a member of at least one of the required user groups and returns a “deny” error if not.
Furthermore, this setting affects the hasPermission function.
The getAccessGroups method returns the complete list defined in this configuration.


Example:

#[Route('/path/to/the/page', format: 'html', accessGroups: ['registeredUser', 'admin'])]

bypass404

Type: Boolean


Determines whether to bypass TYPO3’s 404 error handling for this route.
Note: It is possible to access pages that are not created in the TYPO3 backend; however, this is not recommended.

getRenderFullHtml

Type: Boolean


Determines whether to render and wrap the body around the response.
When this option and the getIncludeEasyAssets setting are both set to true, Easy assets will also be included (requires Easy to be installed).

includeEasyAssets

Type: Boolean


Determines whether to automatically include Easy extension assets (JS/CSS). Easy must be installed for this to take effect.

cacheLifetime

Type: Integer


Cache lifetime in seconds for this route.

IMPORTANT: The 'stateless' route setting must be set to false for this setting taking effect. If stateless is true, no caching happens at all.


Example:

#[Route('/path/to/page', cacheLifetime: 86400, stateless: false)]

includeCsrf

Type: Boolean


Determines whether CSRF protection should be enabled for this route.
You can obtain the token by calling the getCsrfToken method in your custom controller.
To verify the token, use the isValidCsrfToken method.

options

Type: Array


Processes route options and applies configurations such as file block size, file redirects, allowed HTTP methods, and CORS headers.
Available options:

fileBlockSize: Size of the block to read when serving a file as response.


fileRedirect: File redirect method (none, apache, nginx). Used for automatic server-side file handling. Possible values: 1 (FILE_REDIRECT_NONE), 2 (FILE_REDIRECT_APACHE), 3 (FILE_REDIRECT_NGINX).


fileRedirectMask: File redirect mask for Nginx X-Accel-Redirect (e.g., masked/path/to/private/files/).


fileRedirectRelDir: Relative directory to hide for Nginx X-Accel-Redirect (e.g., real/path/to/the/files).


allowedMethods: Allowed HTTP methods for the request. Comma-separated list (e.g., GET,POST).


corsOrigin: Sets Access-Control-Allow-Origin header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin


corsMethods: Sets Access-Control-Allow-Methods header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods


corsHeaders: Sets Access-Control-Allow-Headers header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Headers


corsCredentials: Sets Access-Control-Allow-Credentials header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Credentials


Example:

Example: Using NGINX's X-Accel-Redirect feature.

<?php

namespace DS\Sample\Controller;

use Ds\Easy\Attribute\Route;
use Ds\Easy\Controller\EasyController;
use Psr\Http\Message\ResponseInterface;

class DemoController extends EasyController
{

    #[Route('/path/to/my/page', format: 'file', options: ['fileRedirect' => 3, 'fileRedirectMask' => '/my/hidden/path/', 'fileRedirectRelDir' => '/var/www/html/public/fileadmin/img/'])]
    public function getImage(): ?ResponseInterface
    {
        return $this->render('/var/www/html/public/fileadmin/img/avatar.png');
    }
}

The corresponding NGINX configuration would look like this:

location /my/hidden/path/ {
	internal;
	alias /var/www/html/public/fileadmin/img/;
}