Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

PHP 7.1+ support #177

Merged
merged 9 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

# ignore lock file since we have no extra dependencies
composer.lock
phpunit.xml
1 change: 0 additions & 1 deletion .hhconfig

This file was deleted.

13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ sudo: false
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm
- 7.3
- 7.4snapshot
- nightly

script:
- ./vendor/bin/phpunit
Expand All @@ -18,3 +16,8 @@ before_install:

install:
- composer install

jobs:
allow_failures:
- php: 7.4snapshot
- php: nightly
126 changes: 0 additions & 126 deletions FastRoute.hhi

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
}
},
"require": {
"php": ">=5.4.0"
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35|~5.7"
"phpunit/phpunit": "^7.5"
},
"extra": {
"branch-alias": {
Expand Down
17 changes: 7 additions & 10 deletions phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
syntaxCheck="false"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
verbose="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
>
<testsuites>
<testsuite name="FastRoute Tests">
<directory>./test/</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/DataGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface DataGenerator
* @param array $routeData
* @param mixed $handler
*/
public function addRoute($httpMethod, $routeData, $handler);
public function addRoute(string $httpMethod, array $routeData, $handler):void;

/**
* Returns dispatcher data in some unspecified format, which
Expand Down
4 changes: 2 additions & 2 deletions src/DataGenerator/CharCountBased.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class CharCountBased extends RegexBasedAbstract
{
protected function getApproxChunkSize()
protected function getApproxChunkSize():int
{
return 30;
}

protected function processChunk($regexToRoutesMap)
protected function processChunk(array $regexToRoutesMap):array
{
$routeMap = [];
$regexes = [];
Expand Down
4 changes: 2 additions & 2 deletions src/DataGenerator/GroupCountBased.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class GroupCountBased extends RegexBasedAbstract
{
protected function getApproxChunkSize()
protected function getApproxChunkSize():int
{
return 10;
}

protected function processChunk($regexToRoutesMap)
protected function processChunk(array $regexToRoutesMap):array
{
$routeMap = [];
$regexes = [];
Expand Down
4 changes: 2 additions & 2 deletions src/DataGenerator/GroupPosBased.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class GroupPosBased extends RegexBasedAbstract
{
protected function getApproxChunkSize()
protected function getApproxChunkSize():int
{
return 10;
}

protected function processChunk($regexToRoutesMap)
protected function processChunk(array $regexToRoutesMap):array
{
$routeMap = [];
$regexes = [];
Expand Down
4 changes: 2 additions & 2 deletions src/DataGenerator/MarkBased.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class MarkBased extends RegexBasedAbstract
{
protected function getApproxChunkSize()
protected function getApproxChunkSize():int
{
return 30;
}

protected function processChunk($regexToRoutesMap)
protected function processChunk(array $regexToRoutesMap):array
{
$routeMap = [];
$regexes = [];
Expand Down
26 changes: 13 additions & 13 deletions src/DataGenerator/RegexBasedAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ abstract class RegexBasedAbstract implements DataGenerator
/**
* @return int
*/
abstract protected function getApproxChunkSize();
abstract protected function getApproxChunkSize():int;

/**
* @return mixed[]
*/
abstract protected function processChunk($regexToRoutesMap);
abstract protected function processChunk(array $regexToRoutesMap):array;

public function addRoute($httpMethod, $routeData, $handler)
public function addRoute(string $httpMethod, array $routeData, $handler):void
{
if ($this->isStaticRoute($routeData)) {
$this->addStaticRoute($httpMethod, $routeData, $handler);
Expand All @@ -36,7 +36,7 @@ public function addRoute($httpMethod, $routeData, $handler)
/**
* @return mixed[]
*/
public function getData()
public function getData():array
{
if (empty($this->methodToRegexToRoutesMap)) {
return [$this->staticRoutes, []];
Expand All @@ -48,7 +48,7 @@ public function getData()
/**
* @return mixed[]
*/
private function generateVariableRouteData()
private function generateVariableRouteData():array
{
$data = [];
foreach ($this->methodToRegexToRoutesMap as $method => $regexToRoutesMap) {
Expand All @@ -63,7 +63,7 @@ private function generateVariableRouteData()
* @param int
* @return int
*/
private function computeChunkSize($count)
private function computeChunkSize(int $count):int
{
$numParts = max(1, round($count / $this->getApproxChunkSize()));
return (int) ceil($count / $numParts);
Expand All @@ -73,12 +73,12 @@ private function computeChunkSize($count)
* @param mixed[]
* @return bool
*/
private function isStaticRoute($routeData)
private function isStaticRoute(array $routeData):bool
{
return count($routeData) === 1 && is_string($routeData[0]);
}

private function addStaticRoute($httpMethod, $routeData, $handler)
private function addStaticRoute(string $httpMethod, array $routeData, $handler):void
{
$routeStr = $routeData[0];

Expand All @@ -103,9 +103,9 @@ private function addStaticRoute($httpMethod, $routeData, $handler)
$this->staticRoutes[$httpMethod][$routeStr] = $handler;
}

private function addVariableRoute($httpMethod, $routeData, $handler)
private function addVariableRoute(string $httpMethod, array $routeData, $handler):void
{
list($regex, $variables) = $this->buildRegexForRoute($routeData);
[$regex, $variables] = $this->buildRegexForRoute($routeData);

if (isset($this->methodToRegexToRoutesMap[$httpMethod][$regex])) {
throw new BadRouteException(sprintf(
Expand All @@ -123,7 +123,7 @@ private function addVariableRoute($httpMethod, $routeData, $handler)
* @param mixed[]
* @return mixed[]
*/
private function buildRegexForRoute($routeData)
private function buildRegexForRoute(array $routeData):array
{
$regex = '';
$variables = [];
Expand All @@ -133,7 +133,7 @@ private function buildRegexForRoute($routeData)
continue;
}

list($varName, $regexPart) = $part;
[$varName, $regexPart] = $part;

if (isset($variables[$varName])) {
throw new BadRouteException(sprintf(
Expand All @@ -159,7 +159,7 @@ private function buildRegexForRoute($routeData)
* @param string
* @return bool
*/
private function regexHasCapturingGroups($regex)
private function regexHasCapturingGroups(string $regex):bool
{
if (false === strpos($regex, '(')) {
// Needs to have at least a ( to contain a capturing group
Expand Down
2 changes: 1 addition & 1 deletion src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ interface Dispatcher
*
* @return array
*/
public function dispatch($httpMethod, $uri);
public function dispatch(string $httpMethod, string $uri):array;
}
9 changes: 2 additions & 7 deletions src/Dispatcher/CharCountBased.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@

class CharCountBased extends RegexBasedAbstract
{
public function __construct($data)
{
list($this->staticRouteMap, $this->variableRouteData) = $data;
}

protected function dispatchVariableRoute($routeData, $uri)
protected function dispatchVariableRoute(array $routeData, string $uri):array
{
foreach ($routeData as $data) {
if (!preg_match($data['regex'], $uri . $data['suffix'], $matches)) {
continue;
}

list($handler, $varNames) = $data['routeMap'][end($matches)];
[$handler, $varNames] = $data['routeMap'][end($matches)];

$vars = [];
$i = 0;
Expand Down
Loading