Skip to content

Commit

Permalink
Merge pull request #3192 from ashleycoles/routingTypes
Browse files Browse the repository at this point in the history
Routing types
  • Loading branch information
l0gicgate committed May 5, 2022
2 parents ebc1602 + d8bbc7f commit 1eab45e
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 163 deletions.
10 changes: 2 additions & 8 deletions Slim/Routing/Dispatcher.php
Expand Up @@ -12,15 +12,9 @@

class Dispatcher implements DispatcherInterface
{
/**
* @var RouteCollectorInterface
*/
private $routeCollector;
private RouteCollectorInterface $routeCollector;

/**
* @var FastRouteDispatcher|null
*/
private $dispatcher;
private ?FastRouteDispatcher $dispatcher = null;

/**
* @param RouteCollectorInterface $routeCollector
Expand Down
2 changes: 1 addition & 1 deletion Slim/Routing/FastRouteDispatcher.php
Expand Up @@ -17,7 +17,7 @@ class FastRouteDispatcher extends GroupCountBased
/**
* @var string[][]
*/
private $allowedMethods = [];
private array $allowedMethods = [];

/**
* @param string $httpMethod
Expand Down
44 changes: 13 additions & 31 deletions Slim/Routing/Route.php
Expand Up @@ -40,59 +40,52 @@ class Route implements RouteInterface, RequestHandlerInterface
*
* @var string[]
*/
protected $methods = [];
protected array $methods = [];

/**
* Route identifier
*
* @var string
*/
protected $identifier;
protected string $identifier;

/**
* Route name
*
* @var null|string
*/
protected $name;
protected ?string $name = null;

/**
* Parent route groups
*
* @var RouteGroupInterface[]
*/
protected $groups;
protected array $groups;

/**
* @var InvocationStrategyInterface
*/
protected $invocationStrategy;
protected InvocationStrategyInterface $invocationStrategy;

/**
* Route parameters
*
* @var array<string, string>
*/
protected $arguments = [];
protected array $arguments = [];

/**
* Route arguments parameters
*
* @var string[]
*/
protected $savedArguments = [];
protected array $savedArguments = [];

/**
* Container
*
* @var ContainerInterface|null
*/
protected $container;
protected ?ContainerInterface $container = null;

/**
* @var MiddlewareDispatcher
*/
protected $middlewareDispatcher;
protected MiddlewareDispatcher $middlewareDispatcher;

/**
* Route callable
Expand All @@ -101,27 +94,16 @@ class Route implements RouteInterface, RequestHandlerInterface
*/
protected $callable;

/**
* @var CallableResolverInterface
*/
protected $callableResolver;
protected CallableResolverInterface $callableResolver;

/**
* @var ResponseFactoryInterface
*/
protected $responseFactory;
protected ResponseFactoryInterface $responseFactory;

/**
* Route pattern
*
* @var string
*/
protected $pattern;
protected string $pattern;

/**
* @var bool
*/
protected $groupMiddlewareAppended = false;
protected bool $groupMiddlewareAppended = false;

/**
* @param string[] $methods The route HTTP methods
Expand Down
41 changes: 10 additions & 31 deletions Slim/Routing/RouteCollector.php
Expand Up @@ -34,65 +34,44 @@
*/
class RouteCollector implements RouteCollectorInterface
{
/**
* @var RouteParserInterface
*/
protected $routeParser;
protected RouteParserInterface $routeParser;

/**
* @var CallableResolverInterface
*/
protected $callableResolver;
protected CallableResolverInterface $callableResolver;

/**
* @var ContainerInterface|null
*/
protected $container;
protected ?ContainerInterface $container = null;

/**
* @var InvocationStrategyInterface
*/
protected $defaultInvocationStrategy;
protected InvocationStrategyInterface $defaultInvocationStrategy;

/**
* Base path used in pathFor()
*
* @var string
*/
protected $basePath = '';
protected string $basePath = '';

/**
* Path to fast route cache file. Set to null to disable route caching
*
* @var string|null
*/
protected $cacheFile;
protected ?string $cacheFile = null;

/**
* Routes
*
* @var RouteInterface[]
*/
protected $routes = [];
protected array $routes = [];

/**
* Route groups
*
* @var RouteGroup[]
*/
protected $routeGroups = [];
protected array $routeGroups = [];

/**
* Route counter incrementer
*
* @var int
*/
protected $routeCounter = 0;
protected int $routeCounter = 0;

/**
* @var ResponseFactoryInterface
*/
protected $responseFactory;
protected ResponseFactoryInterface $responseFactory;

/**
* @param ResponseFactoryInterface $responseFactory
Expand Down
25 changes: 5 additions & 20 deletions Slim/Routing/RouteCollectorProxy.php
Expand Up @@ -20,30 +20,15 @@

class RouteCollectorProxy implements RouteCollectorProxyInterface
{
/**
* @var ResponseFactoryInterface
*/
protected $responseFactory;
protected ResponseFactoryInterface $responseFactory;

/**
* @var CallableResolverInterface
*/
protected $callableResolver;
protected CallableResolverInterface $callableResolver;

/**
* @var ContainerInterface|null
*/
protected $container;
protected ?ContainerInterface $container = null;

/**
* @var RouteCollectorInterface
*/
protected $routeCollector;
protected RouteCollectorInterface $routeCollector;

/**
* @var string
*/
protected $groupPattern;
protected string $groupPattern;

/**
* @param ResponseFactoryInterface $responseFactory
Expand Down
20 changes: 4 additions & 16 deletions Slim/Routing/RouteContext.php
Expand Up @@ -47,25 +47,13 @@ public static function fromRequest(ServerRequestInterface $serverRequest): self
return new self($route, $routeParser, $routingResults, $basePath);
}

/**
* @var RouteInterface|null
*/
private $route;
private ?RouteInterface $route;

/**
* @var RouteParserInterface
*/
private $routeParser;
private RouteParserInterface $routeParser;

/**
* @var RoutingResults
*/
private $routingResults;
private RoutingResults $routingResults;

/**
* @var string|null
*/
private $basePath;
private ?string $basePath;

/**
* @param RouteInterface|null $route
Expand Down
17 changes: 4 additions & 13 deletions Slim/Routing/RouteGroup.php
Expand Up @@ -24,25 +24,16 @@ class RouteGroup implements RouteGroupInterface
*/
protected $callable;

/**
* @var CallableResolverInterface
*/
protected $callableResolver;
protected CallableResolverInterface $callableResolver;

/**
* @var RouteCollectorProxyInterface
*/
protected $routeCollectorProxy;
protected RouteCollectorProxyInterface $routeCollectorProxy;

/**
* @var MiddlewareInterface[]|string[]|callable[]
*/
protected $middleware = [];
protected array $middleware = [];

/**
* @var string
*/
protected $pattern;
protected string $pattern;

/**
* @param string $pattern
Expand Down
10 changes: 2 additions & 8 deletions Slim/Routing/RouteParser.php
Expand Up @@ -24,15 +24,9 @@

class RouteParser implements RouteParserInterface
{
/**
* @var RouteCollectorInterface
*/
private $routeCollector;
private RouteCollectorInterface $routeCollector;

/**
* @var Std
*/
private $routeParser;
private Std $routeParser;

/**
* @param RouteCollectorInterface $routeCollector
Expand Down
5 changes: 1 addition & 4 deletions Slim/Routing/RouteResolver.php
Expand Up @@ -24,10 +24,7 @@
*/
class RouteResolver implements RouteResolverInterface
{
/**
* @var RouteCollectorInterface
*/
protected $routeCollector;
protected RouteCollectorInterface $routeCollector;

/**
* @var DispatcherInterface
Expand Down
15 changes: 3 additions & 12 deletions Slim/Routing/RouteRunner.php
Expand Up @@ -22,20 +22,11 @@

class RouteRunner implements RequestHandlerInterface
{
/**
* @var RouteResolverInterface
*/
private $routeResolver;
private RouteResolverInterface $routeResolver;

/**
* @var RouteParserInterface
*/
private $routeParser;
private RouteParserInterface $routeParser;

/**
* @var RouteCollectorProxyInterface|null
*/
private $routeCollectorProxy;
private ?RouteCollectorProxyInterface $routeCollectorProxy;

/**
* @param RouteResolverInterface $routeResolver
Expand Down
25 changes: 6 additions & 19 deletions Slim/Routing/RoutingResults.php
Expand Up @@ -20,39 +20,26 @@ class RoutingResults
public const FOUND = 1;
public const METHOD_NOT_ALLOWED = 2;

/**
* @var DispatcherInterface
*/
protected $dispatcher;
protected DispatcherInterface $dispatcher;

/**
* @var string
*/
protected $method;
protected string $method;

/**
* @var string
*/
protected $uri;
protected string $uri;

/**
* @var int
* The status is one of the constants shown above
* NOT_FOUND = 0
* FOUND = 1
* METHOD_NOT_ALLOWED = 2
*/
protected $routeStatus;
protected int $routeStatus;

/**
* @var null|string
*/
protected $routeIdentifier;
protected ?string $routeIdentifier = null;

/**
* @var array<string, string>
*/
protected $routeArguments;
protected array $routeArguments;

/**
* @param DispatcherInterface $dispatcher
Expand Down

0 comments on commit 1eab45e

Please sign in to comment.