Remove RouteFactoryInterface

This commit is contained in:
PJ Dietz 2020-08-14 07:44:00 -04:00
parent 79c4799a7b
commit 56503da35e
5 changed files with 9 additions and 33 deletions

View File

@ -7,7 +7,7 @@ use WellRESTed\Dispatching\DispatcherInterface;
/**
* @internal
*/
class RouteFactory implements RouteFactoryInterface
class RouteFactory
{
private $dispatcher;
@ -27,7 +27,7 @@ class RouteFactory implements RouteFactoryInterface
* @param string $target Route target or target pattern
* @return Route
*/
public function create($target)
public function create(string $target): Route
{
if ($target[0] === '/') {

View File

@ -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);
}

View File

@ -8,7 +8,6 @@ use WellRESTed\Dispatching\Dispatcher;
use WellRESTed\Dispatching\DispatcherInterface;
use WellRESTed\Routing\Route\Route;
use WellRESTed\Routing\Route\RouteFactory;
use WellRESTed\Routing\Route\RouteFactoryInterface;
class Router
{
@ -16,7 +15,7 @@ class Router
private $pathVariablesAttributeName;
/** @var DispatcherInterface */
private $dispatcher;
/** @var RouteFactoryInterface */
/** @var RouteFactory */
private $factory;
/** @var Route[] Array of Route objects */
private $routes;
@ -202,7 +201,7 @@ class Router
return new Dispatcher();
}
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactoryInterface
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactory
{
return new RouteFactory($dispatcher);
}

View File

@ -17,28 +17,28 @@ class RouteFactoryTest extends TestCase
$this->dispatcher = $this->prophesize(DispatcherInterface::class);
}
public function testCreatesStaticRoute()
public function testCreatesStaticRoute(): void
{
$factory = new RouteFactory($this->dispatcher->reveal());
$route = $factory->create('/cats/');
$this->assertSame(Route::TYPE_STATIC, $route->getType());
}
public function testCreatesPrefixRoute()
public function testCreatesPrefixRoute(): void
{
$factory = new RouteFactory($this->dispatcher->reveal());
$route = $factory->create('/cats/*');
$this->assertSame(Route::TYPE_PREFIX, $route->getType());
}
public function testCreatesRegexRoute()
public function testCreatesRegexRoute(): void
{
$factory = new RouteFactory($this->dispatcher->reveal());
$route = $factory->create('~/cat/[0-9]+~');
$this->assertSame(Route::TYPE_PATTERN, $route->getType());
}
public function testCreatesTemplateRoute()
public function testCreatesTemplateRoute(): void
{
$factory = new RouteFactory($this->dispatcher->reveal());
$route = $factory->create('/cat/{id}');

View File

@ -10,7 +10,6 @@ use WellRESTed\Message\Response;
use WellRESTed\Message\ServerRequest;
use WellRESTed\Routing\Route\Route;
use WellRESTed\Routing\Route\RouteFactory;
use WellRESTed\Routing\Route\RouteFactoryInterface;
use WellRESTed\Test\Doubles\NextMock;
use WellRESTed\Test\TestCase;
@ -449,7 +448,7 @@ class RouterWithFactory extends Router
{
public static $routeFactory;
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactoryInterface
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactory
{
return self::$routeFactory;
}