Hypolite Petovan
61b6ab7e3e
- Create new Friendica\App\Router class - Add route_collection hook - Add route dispatching in App->runFrontend
43 lines
No EOL
961 B
PHP
43 lines
No EOL
961 B
PHP
<?php
|
|
|
|
namespace Friendica\App;
|
|
|
|
|
|
use FastRoute\DataGenerator\GroupCountBased;
|
|
use FastRoute\Dispatcher;
|
|
use FastRoute\RouteCollector;
|
|
use FastRoute\RouteParser\Std;
|
|
use Friendica\Module\Itemsource;
|
|
|
|
class Router
|
|
{
|
|
/** @var RouteCollector */
|
|
public $routeCollector;
|
|
|
|
public function __construct(RouteCollector $routeCollector = null)
|
|
{
|
|
if (!$routeCollector) {
|
|
$routeCollector = new RouteCollector(new Std(), new GroupCountBased());
|
|
}
|
|
|
|
$this->routeCollector = $routeCollector;
|
|
}
|
|
|
|
public function getModuleClass($cmd)
|
|
{
|
|
$cmd = '/' . ltrim($cmd, '/');
|
|
|
|
$dispatcher = new \FastRoute\Dispatcher\GroupCountBased($this->routeCollector->getData());
|
|
|
|
$moduleClass = null;
|
|
|
|
// @TODO: Enable method-specific modules
|
|
$httpMethod = 'GET';
|
|
$routeInfo = $dispatcher->dispatch($httpMethod, $cmd);
|
|
if ($routeInfo[0] === Dispatcher::FOUND) {
|
|
$moduleClass = $routeInfo[1];
|
|
}
|
|
|
|
return $moduleClass;
|
|
}
|
|
} |