N°6935 - Deprecate own router system in favor of Symfony's

This commit is contained in:
Molkobain
2023-12-14 15:03:06 +01:00
parent 1fee4372eb
commit 43d3a3bc67
8 changed files with 82 additions and 40 deletions

View File

@@ -389,7 +389,6 @@ return array(
'Combodo\\iTop\\Application\\WebPage\\iTopWebPage' => $baseDir . '/sources/Application/WebPage/iTopWebPage.php',
'Combodo\\iTop\\Application\\WebPage\\iTopWizardWebPage' => $baseDir . '/sources/Application/WebPage/iTopWizardWebPage.php',
'Combodo\\iTop\\Composer\\iTopComposer' => $baseDir . '/sources/Composer/iTopComposer.php',
'Combodo\\iTop\\Controller\\AbstractAppController' => $baseDir . '/sources/Controller/AbstractAppController.php',
'Combodo\\iTop\\Controller\\AbstractController' => $baseDir . '/sources/Controller/AbstractController.php',
'Combodo\\iTop\\Controller\\AjaxRenderController' => $baseDir . '/sources/Controller/AjaxRenderController.php',
'Combodo\\iTop\\Controller\\Base\\Layout\\ActivityPanelController' => $baseDir . '/sources/Controller/Base/Layout/ActivityPanelController.php',

View File

@@ -764,7 +764,6 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
'Combodo\\iTop\\Application\\WebPage\\iTopWebPage' => __DIR__ . '/../..' . '/sources/Application/WebPage/iTopWebPage.php',
'Combodo\\iTop\\Application\\WebPage\\iTopWizardWebPage' => __DIR__ . '/../..' . '/sources/Application/WebPage/iTopWizardWebPage.php',
'Combodo\\iTop\\Composer\\iTopComposer' => __DIR__ . '/../..' . '/sources/Composer/iTopComposer.php',
'Combodo\\iTop\\Controller\\AbstractAppController' => __DIR__ . '/../..' . '/sources/Controller/AbstractAppController.php',
'Combodo\\iTop\\Controller\\AbstractController' => __DIR__ . '/../..' . '/sources/Controller/AbstractController.php',
'Combodo\\iTop\\Controller\\AjaxRenderController' => __DIR__ . '/../..' . '/sources/Controller/AjaxRenderController.php',
'Combodo\\iTop\\Controller\\Base\\Layout\\ActivityPanelController' => __DIR__ . '/../..' . '/sources/Controller/Base/Layout/ActivityPanelController.php',

View File

@@ -1,32 +0,0 @@
<?php
/**
* Copyright (C) 2013-2023 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Controller;
/**
* Class AbstractAppController
*
* @package Combodo\iTop\Controller
* @since 3.2.0
*/
class AbstractAppController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
}

View File

@@ -6,6 +6,9 @@
namespace Combodo\iTop\Controller;
use DeprecatedCallsLog;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as BaseAbstractControllerAlias;
/**
* Class AbstractController
*
@@ -15,14 +18,17 @@ namespace Combodo\iTop\Controller;
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Controller
* @since 3.1.0
* @since 3.2.0 N°6935 Controller is now based on Symfony controller
*/
abstract class AbstractController implements iController
abstract class AbstractController extends BaseAbstractControllerAlias implements iController
{
/**
* @inheritDoc
* @deprecated 3.2.0 N°6935 Use \Symfony\Component\HttpFoundation\Request::isXmlHttpRequest() instead
*/
public function IsHandlingXmlHttpRequest(): bool
{
DeprecatedCallsLog::NotifyDeprecatedPhpMethod("Use \Symfony\Component\HttpFoundation\Request::isXmlHttpRequest() instead");
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
}
}

View File

@@ -6,10 +6,13 @@
namespace Combodo\iTop\Controller;
/**
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @since 3.1.0
* @package Combodo\iTop\Controller
*
* @deprecated 3.2.0 N°6935 As we now use Symfony controller and routing components, extend \Combodo\iTop\Controller\AbstractController instead
*/
interface iController
{

View File

@@ -6,17 +6,42 @@
namespace Combodo\iTop\Service\Router\Exception;
use DeprecatedCallsLog;
/**
* Class RouteNotFoundException
*
* Means that a said route (eg. "object.modify") could not be found
*
* @internal
*
* @deprecated 3.2.0 N°6935 As we now use Symfony routing component, use the corresponding exceptions instead
*
* Note that we can't call \DeprecatedCallsLog::NotifyDeprecatedFile() at the beginning at the file instead.
* Because
* - As the class is part of the autoloader it will be read when something calls \utils::GetClassesForInterface() which will pop the deprecation message (and break redirection)
* - Not all controllers using Combodo\iTop\Service\Router\Router service can be migrated yet for backward compatibility with extensions reasons
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Service\Router\Exception
* @since 3.1.0
* @internal
*/
class RouteNotFoundException extends RouterException
{
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
/**
* @deprecated 3.2.0 N°6935
*
* Note that we can't call \DeprecatedCallsLog::NotifyDeprecatedFile() at the beginning at the file instead.
* Because
* - As the class is part of the autoloader it will be read when something calls \utils::GetClassesForInterface() which will pop the deprecation message (and break redirection)
* - Not all controllers using Combodo\iTop\Service\Router\Router service can be migrated yet for backward compatibility with extensions reasons
*/
DeprecatedCallsLog::NotifyDeprecatedFile("As we now use Symfony routing component, use the corresponding exceptions instead");
parent::__construct($message, $code, $previous);
}
}

View File

@@ -6,19 +6,42 @@
namespace Combodo\iTop\Service\Router\Exception;
use DeprecatedCallsLog;
use Exception;
/**
* Class RouterException
*
* Base router exception class in case we need to catch all kind of router exceptions (see derived exceptions)
*
* @internal
*
* @deprecated 3.2.0 N°6935 As we now use Symfony routing component, use the corresponding exceptions instead
*
* Note that we can't call \DeprecatedCallsLog::NotifyDeprecatedFile() at the beginning at the file instead.
* Because
* - As the class is part of the autoloader it will be read when something calls \utils::GetClassesForInterface() which will pop the deprecation message (and break redirection)
* - Not all controllers using Combodo\iTop\Service\Router\Router service can be migrated yet for backward compatibility with extensions reasons
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Service\Router\Exception
* @since 3.1.0
* @internal
*/
class RouterException extends Exception
{
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
/**
* @deprecated 3.2.0 N°6935
*
* Note that we can't call \DeprecatedCallsLog::NotifyDeprecatedFile() at the beginning at the file instead.
* Because
* - As the class is part of the autoloader it will be read when something calls \utils::GetClassesForInterface() which will pop the deprecation message (and break redirection)
* - Not all controllers using Combodo\iTop\Service\Router\Router service can be migrated yet for backward compatibility with extensions reasons
*/
DeprecatedCallsLog::NotifyDeprecatedFile("As we now use Symfony routing component, use the corresponding exceptions instead");
parent::__construct($message, $code, $previous);
}
}

View File

@@ -7,20 +7,29 @@
namespace Combodo\iTop\Service\Router;
use Combodo\iTop\Service\Router\Exception\RouteNotFoundException;
use DeprecatedCallsLog;
use ReflectionClass;
use ReflectionMethod;
use utils;
use SetupUtils;
/**
* Class Router
*
* Service to find the corresponding controller / method for a given "route" parameter.
*
* @deprecated 3.2.0 N°6935 As we now use Symfony routing component, use the corresponding service instead
*
* Note that we can't call \DeprecatedCallsLog::NotifyDeprecatedFile() at the beginning at the file instead.
* Because
* - As the class is part of the autoloader it will be read when something calls \utils::GetClassesForInterface() which will pop the deprecation message (and break redirection)
* - Not all controllers using Combodo\iTop\Service\Router\Router service can be migrated yet for backward compatibility with extensions reasons
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Service\Router
* @since 3.1.0
* @api
*
* @package Combodo\iTop\Service\Router
*/
class Router
{
@@ -123,6 +132,9 @@ class Router
*/
public function DispatchRoute(string $sRoute)
{
/** @deprecated 3.2.0 N°6935 */
DeprecatedCallsLog::NotifyDeprecatedFile("As we now use Symfony routing component, use the corresponding service instead");
$aMethodSpecs = $this->GetDispatchSpecsForRoute($sRoute);
$mResponse = call_user_func_array([new $aMethodSpecs[0](), $aMethodSpecs[1]], []);
@@ -175,8 +187,15 @@ class Router
// If no cache, force to re-scan for routes
if (count($aRoutes) === 0) {
foreach (utils::GetClassesForInterface('Combodo\iTop\Controller\iController', '', ['[\\\\/]lib[\\\\/]', '[\\\\/]node_modules[\\\\/]', '[\\\\/]test[\\\\/]']) as $sControllerFQCN) {
$sRouteNamespace = $sControllerFQCN::ROUTE_NAMESPACE;
// Ignore controller with no namespace
// - No ROUTE_NAMESPACE constant
// This case could be for controller extending Combodo\iTop\Controller\AbstractController which is still implementing Combodo\iTop\Controller\iController for compatibility reasons
// but have already been migrated to Symfony router (when migrated, constant must be removed from the controller so it doesn't use the compatibility router)
if (false === defined("$sControllerFQCN::ROUTE_NAMESPACE")) {
continue;
}
$sRouteNamespace = $sControllerFQCN::ROUTE_NAMESPACE;
// - Namespace is empty
if (is_null($sRouteNamespace)) {
continue;
}