Remove RouteFactoryInterface
This commit is contained in:
parent
79c4799a7b
commit
56503da35e
|
|
@ -7,7 +7,7 @@ use WellRESTed\Dispatching\DispatcherInterface;
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class RouteFactory implements RouteFactoryInterface
|
class RouteFactory
|
||||||
{
|
{
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ class RouteFactory implements RouteFactoryInterface
|
||||||
* @param string $target Route target or target pattern
|
* @param string $target Route target or target pattern
|
||||||
* @return Route
|
* @return Route
|
||||||
*/
|
*/
|
||||||
public function create($target)
|
public function create(string $target): Route
|
||||||
{
|
{
|
||||||
if ($target[0] === '/') {
|
if ($target[0] === '/') {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace WellRESTed\Routing\Route;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
interface RouteFactoryInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Creates a route for the given target.
|
|
||||||
*
|
|
||||||
* - Targets with no special characters will create StaticRoutes
|
|
||||||
* - Targets ending with * will create PrefixRoutes
|
|
||||||
* - Targets containing URI variables (e.g., {id}) will create TemplateRoutes
|
|
||||||
* - Regular expressions will create RegexRoutes
|
|
||||||
*
|
|
||||||
* @param string $target Route target or target pattern
|
|
||||||
* @return Route
|
|
||||||
*/
|
|
||||||
public function create($target);
|
|
||||||
}
|
|
||||||
|
|
@ -8,7 +8,6 @@ use WellRESTed\Dispatching\Dispatcher;
|
||||||
use WellRESTed\Dispatching\DispatcherInterface;
|
use WellRESTed\Dispatching\DispatcherInterface;
|
||||||
use WellRESTed\Routing\Route\Route;
|
use WellRESTed\Routing\Route\Route;
|
||||||
use WellRESTed\Routing\Route\RouteFactory;
|
use WellRESTed\Routing\Route\RouteFactory;
|
||||||
use WellRESTed\Routing\Route\RouteFactoryInterface;
|
|
||||||
|
|
||||||
class Router
|
class Router
|
||||||
{
|
{
|
||||||
|
|
@ -16,7 +15,7 @@ class Router
|
||||||
private $pathVariablesAttributeName;
|
private $pathVariablesAttributeName;
|
||||||
/** @var DispatcherInterface */
|
/** @var DispatcherInterface */
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
/** @var RouteFactoryInterface */
|
/** @var RouteFactory */
|
||||||
private $factory;
|
private $factory;
|
||||||
/** @var Route[] Array of Route objects */
|
/** @var Route[] Array of Route objects */
|
||||||
private $routes;
|
private $routes;
|
||||||
|
|
@ -202,7 +201,7 @@ class Router
|
||||||
return new Dispatcher();
|
return new Dispatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactoryInterface
|
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactory
|
||||||
{
|
{
|
||||||
return new RouteFactory($dispatcher);
|
return new RouteFactory($dispatcher);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,28 +17,28 @@ class RouteFactoryTest extends TestCase
|
||||||
$this->dispatcher = $this->prophesize(DispatcherInterface::class);
|
$this->dispatcher = $this->prophesize(DispatcherInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreatesStaticRoute()
|
public function testCreatesStaticRoute(): void
|
||||||
{
|
{
|
||||||
$factory = new RouteFactory($this->dispatcher->reveal());
|
$factory = new RouteFactory($this->dispatcher->reveal());
|
||||||
$route = $factory->create('/cats/');
|
$route = $factory->create('/cats/');
|
||||||
$this->assertSame(Route::TYPE_STATIC, $route->getType());
|
$this->assertSame(Route::TYPE_STATIC, $route->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreatesPrefixRoute()
|
public function testCreatesPrefixRoute(): void
|
||||||
{
|
{
|
||||||
$factory = new RouteFactory($this->dispatcher->reveal());
|
$factory = new RouteFactory($this->dispatcher->reveal());
|
||||||
$route = $factory->create('/cats/*');
|
$route = $factory->create('/cats/*');
|
||||||
$this->assertSame(Route::TYPE_PREFIX, $route->getType());
|
$this->assertSame(Route::TYPE_PREFIX, $route->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreatesRegexRoute()
|
public function testCreatesRegexRoute(): void
|
||||||
{
|
{
|
||||||
$factory = new RouteFactory($this->dispatcher->reveal());
|
$factory = new RouteFactory($this->dispatcher->reveal());
|
||||||
$route = $factory->create('~/cat/[0-9]+~');
|
$route = $factory->create('~/cat/[0-9]+~');
|
||||||
$this->assertSame(Route::TYPE_PATTERN, $route->getType());
|
$this->assertSame(Route::TYPE_PATTERN, $route->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreatesTemplateRoute()
|
public function testCreatesTemplateRoute(): void
|
||||||
{
|
{
|
||||||
$factory = new RouteFactory($this->dispatcher->reveal());
|
$factory = new RouteFactory($this->dispatcher->reveal());
|
||||||
$route = $factory->create('/cat/{id}');
|
$route = $factory->create('/cat/{id}');
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ use WellRESTed\Message\Response;
|
||||||
use WellRESTed\Message\ServerRequest;
|
use WellRESTed\Message\ServerRequest;
|
||||||
use WellRESTed\Routing\Route\Route;
|
use WellRESTed\Routing\Route\Route;
|
||||||
use WellRESTed\Routing\Route\RouteFactory;
|
use WellRESTed\Routing\Route\RouteFactory;
|
||||||
use WellRESTed\Routing\Route\RouteFactoryInterface;
|
|
||||||
use WellRESTed\Test\Doubles\NextMock;
|
use WellRESTed\Test\Doubles\NextMock;
|
||||||
use WellRESTed\Test\TestCase;
|
use WellRESTed\Test\TestCase;
|
||||||
|
|
||||||
|
|
@ -449,7 +448,7 @@ class RouterWithFactory extends Router
|
||||||
{
|
{
|
||||||
public static $routeFactory;
|
public static $routeFactory;
|
||||||
|
|
||||||
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactoryInterface
|
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactory
|
||||||
{
|
{
|
||||||
return self::$routeFactory;
|
return self::$routeFactory;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue