first commit

This commit is contained in:
salam committed 2026-10-19 08:18:39 +02:00
commit 1218dd1517
12716 files changed
+989233

No files matched your search

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Routing\Exception;
use TYPO3\CMS\Core\Exception;
/**
* Exception thrown when route requires referrer, which does not match current base URL.
*/
class InvalidReferrerException extends Exception
{
}
@@ -0,0 +1,22 @@
<?php
namespace TYPO3\CMS\Backend\Routing\Exception;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Exception thrown when request token was invalid
*/
class InvalidRequestTokenException extends \TYPO3\CMS\Core\Exception
{
}
@@ -0,0 +1,25 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Routing\Exception;
use TYPO3\CMS\Core\Exception;
/**
* Exception thrown when route requires referrer, which is missing.
*/
class MissingReferrerException extends Exception
{
}
@@ -0,0 +1,22 @@
<?php
namespace TYPO3\CMS\Backend\Routing\Exception;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Exception thrown when a resource was not found.
*/
class ResourceNotFoundException extends \TYPO3\CMS\Core\Exception
{
}
@@ -0,0 +1,22 @@
<?php
namespace TYPO3\CMS\Backend\Routing\Exception;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Exception thrown when a route does not exist
*/
class RouteNotFoundException extends \TYPO3\CMS\Core\Routing\RouteNotFoundException
{
}
@@ -0,0 +1,131 @@
<?php
namespace TYPO3\CMS\Backend\Routing;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This is a single entity for a Route.
*
* The architecture is highly inspired by the Symfony Routing Component.
*/
class Route
{
/**
* @var string
*/
protected $path = '/';
/**
* @var array
*/
protected $options = [];
/**
* Constructor setting up the required path and options
*
* @param string $path The path pattern to match
* @param array $options An array of options
*/
public function __construct($path, $options)
{
$this->setPath($path)->setOptions($options);
}
/**
* Returns the path
*
* @return string The path pattern
*/
public function getPath()
{
return $this->path;
}
/**
* Sets the pattern for the path
* A pattern must start with a slash and must not have multiple slashes at the beginning because the
* generated path for this route would be confused with a network path, e.g. '//domain.com/path'.
*
* This method implements a fluent interface.
*
* @param string $pattern The path pattern
* @return Route The current Route instance
*/
public function setPath($pattern)
{
$this->path = '/' . ltrim(trim($pattern), '/');
return $this;
}
/**
* Returns the options set
*
* @return array The options
*/
public function getOptions()
{
return $this->options;
}
/**
* Sets the options
*
* This method implements a fluent interface.
*
* @param array $options The options
* @return Route The current Route instance
*/
public function setOptions(array $options)
{
$this->options = $options;
return $this;
}
/**
* Sets an option value
*
* This method implements a fluent interface.
*
* @param string $name An option name
* @param mixed $value The option value
* @return Route The current Route instance
*/
public function setOption($name, $value)
{
$this->options[$name] = $value;
return $this;
}
/**
* Get an option value
*
* @param string $name An option name
* @return mixed The option value or NULL when not given
*/
public function getOption($name)
{
return $this->options[$name] ?? null;
}
/**
* Checks if an option has been set
*
* @param string $name An option name
* @return bool TRUE if the option is set, FALSE otherwise
*/
public function hasOption($name)
{
return array_key_exists($name, $this->options);
}
}
@@ -0,0 +1,91 @@
<?php
namespace TYPO3\CMS\Backend\Routing;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\Exception\ResourceNotFoundException;
/**
* Implementation of a class for adding routes, collecting throughout the Bootstrap
* to register all sorts of Backend Routes, and to fetch the main Collection in order
* to resolve a route (see ->match() and ->matchRequest()).
*
* Ideally, the Router is solely instantiated and accessed via the Bootstrap, the RequestHandler and the UriBuilder.
*
* See \TYPO3\CMS\Backend\Http\RequestHandler for more details on route matching() and Bootstrap->initializeBackendRouting().
*
* The architecture is inspired by the Symfony Routing Component.
*/
class Router implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* All routes used in the Backend
*
* @var Route[]
*/
protected $routes = [];
/**
* Adds a new route with the identifiers
*
* @param string $routeIdentifier
* @param Route $route
*/
public function addRoute($routeIdentifier, $route)
{
$this->routes[$routeIdentifier] = $route;
}
/**
* Fetch all registered routes, only use in UriBuilder
*
* @return Route[]
*/
public function getRoutes()
{
return $this->routes;
}
/**
* Tries to match a URL path with a set of routes.
*
* @param string $pathInfo The path info to be parsed
* @return Route the first Route object found
* @throws ResourceNotFoundException If the resource could not be found
*/
public function match($pathInfo)
{
foreach ($this->routes as $routeIdentifier => $route) {
// This check is done in a simple way as there are no parameters yet (get parameters only)
if ($route->getPath() === $pathInfo) {
// Store the name of the Route in the _identifier option so the token can be checked against that
$route->setOption('_identifier', $routeIdentifier);
return $route;
}
}
throw new ResourceNotFoundException('The requested resource "' . $pathInfo . '" was not found.', 1425389240);
}
/**
* Tries to match a URI against the registered routes
*
* @param ServerRequestInterface $request
* @return Route the first Route object found
*/
public function matchRequest(ServerRequestInterface $request)
{
return $this->match($request->getAttribute('routePath'));
}
}
@@ -0,0 +1,171 @@
<?php
namespace TYPO3\CMS\Backend\Routing;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Main UrlGenerator for creating URLs for the Backend. Generates a URL based on
* an identifier defined by Configuration/Backend/Routes.php of an extension,
* and adds some more parameters to the URL.
*
* Currently only available and useful when called from Router->generate() as the information
* about possible routes needs to be handed over.
*/
class UriBuilder implements SingletonInterface
{
/**
* Generates an absolute URL
*/
const ABSOLUTE_URL = 'url';
/**
* Generates an absolute path
*/
const ABSOLUTE_PATH = 'absolute';
/**
* @var Router
*/
protected $router;
/**
* @var array
*/
protected $generated = [];
/**
* Loads the router to fetch the available routes from the Router to be used for generating routes
* @param Router|null $router
*/
public function __construct(Router $router = null)
{
$this->router = $router ?? GeneralUtility::makeInstance(Router::class);
}
/**
* Generates a URL or path for a specific route based on the given route.
* Currently used to link to the current script, it is encouraged to use "buildUriFromRoute" if possible.
*
* If there is no route with the given name, the generator throws the RouteNotFoundException.
*
* @param string $pathInfo The path to the route
* @param array $parameters An array of parameters
* @param string $referenceType The type of reference to be generated (one of the constants)
* @return Uri The generated Uri
* @throws RouteNotFoundException If the named route doesn't exist
*/
public function buildUriFromRoutePath($pathInfo, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
{
$router = GeneralUtility::makeInstance(Router::class);
$route = $router->match($pathInfo);
return $this->buildUriFromRoute($route->getOption('_identifier'), $parameters, $referenceType);
}
/**
* Generates a URL or path for a specific route based on the given parameters.
* When the route is configured with "access=public" then the token generation is left out.
*
* If there is no route with the given name, the generator throws the RouteNotFoundException.
*
* @param string $name The name of the route
* @param array $parameters An array of parameters
* @param string $referenceType The type of reference to be generated (one of the constants)
* @return Uri The generated Uri
* @throws RouteNotFoundException If the named route doesn't exist
*/
public function buildUriFromRoute($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
{
$cacheIdentifier = 'route' . $name . serialize($parameters) . $referenceType;
if (isset($this->generated[$cacheIdentifier])) {
return $this->generated[$cacheIdentifier];
}
if (!isset($this->router->getRoutes()[$name])) {
throw new RouteNotFoundException('Unable to generate a URL for the named route "' . $name . '" because this route was not found.', 1476050190);
}
$route = $this->router->getRoutes()[$name];
$parameters = array_merge(
$route->getOptions()['parameters'] ?? [],
$parameters
);
// If the route has the "public" option set, no token is generated.
if ($route->getOption('access') !== 'public') {
$parameters = [
'token' => FormProtectionFactory::get('backend')->generateToken('route', $name)
] + $parameters;
}
// Add the Route path as &route=XYZ
$parameters = [
'route' => $route->getPath()
] + $parameters;
$this->generated[$cacheIdentifier] = $this->buildUri($parameters, $referenceType);
return $this->generated[$cacheIdentifier];
}
/**
* Generate a URI for a backend module, does not check if a module is available though
*
* @param string $moduleName The name of the module
* @param array $parameters An array of parameters
* @param string $referenceType The type of reference to be generated (one of the constants)
*
* @return Uri The generated Uri
* @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.0. Use buildUriFromRoute() instead.
*/
public function buildUriFromModule($moduleName, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
{
trigger_error('UriBuilder->buildUriFromModule() will be removed in TYPO3 v10.0, use buildUriFromRoute() instead.', E_USER_DEPRECATED);
$cacheIdentifier = 'module' . $moduleName . serialize($parameters) . $referenceType;
if (isset($this->generated[$cacheIdentifier])) {
return $this->generated[$cacheIdentifier];
}
$parameters = [
'route' => $moduleName,
'token' => FormProtectionFactory::get('backend')->generateToken('route', $moduleName)
] + $parameters;
$this->generated[$cacheIdentifier] = $this->buildUri($parameters, $referenceType);
return $this->generated[$cacheIdentifier];
}
/**
* Internal method building a Uri object, merging the GET parameters array into a flat queryString
*
* @param array $parameters An array of GET parameters
* @param string $referenceType The type of reference to be generated (one of the constants)
*
* @return Uri
*/
protected function buildUri($parameters, $referenceType)
{
$uri = 'index.php' . HttpUtility::buildQueryString($parameters, '?');
if ($referenceType === self::ABSOLUTE_PATH) {
$uri = PathUtility::getAbsoluteWebPath(Environment::getBackendPath() . '/' . $uri);
} else {
$uri = GeneralUtility::getIndpEnv('TYPO3_REQUEST_DIR') . $uri;
}
return GeneralUtility::makeInstance(Uri::class, $uri);
}
}