Skip to content

Commit

Permalink
Merge pull request #83 from fredemmott/fastroute-hhi
Browse files Browse the repository at this point in the history
HHI: Change the options arrays for dispatchers to shapes
  • Loading branch information
nikic committed Dec 20, 2015
2 parents 864fab0 + 9922e64 commit 8164b4a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 5 deletions.
1 change: 1 addition & 0 deletions .hhconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assume_php=false
22 changes: 17 additions & 5 deletions FastRoute.hhi
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,27 @@ namespace FastRoute {

function simpleDispatcher(
(function(RouteCollector): void) $routeDefinitionCallback,
array<string, string> $options = []): Dispatcher;
shape(
'routeParser' => ?classname<RouteParser>,
'dataGenerator' => ?classname<DataGenerator>,
'dispatcher' => ?classname<Dispatcher>,
'routeCollector' => ?classname<RouteCollector>,
) $options = shape()): Dispatcher;

function cachedDispatcher(
(function(RouteCollector): void) $routeDefinitionCallback,
array<string, string> $options = []): Dispatcher;
shape(
'routeParser' => ?classname<RouteParser>,
'dataGenerator' => ?classname<DataGenerator>,
'dispatcher' => ?classname<Dispatcher>,
'routeCollector' => ?classname<RouteCollector>,
'cacheDisabled' => ?bool,
'cacheFile' => ?string,
) $options = shape()): Dispatcher;
}

namespace FastRoute\DataGenerator {
abstract class RegexBasedAbstract implements DataGenerator {
abstract class RegexBasedAbstract implements \FastRoute\DataGenerator {
protected abstract function getApproxChunkSize();
protected abstract function processChunk($regexToRoutesMap);

Expand Down Expand Up @@ -71,7 +83,7 @@ namespace FastRoute\DataGenerator {
}

namespace FastRoute\Dispatcher {
abstract class RegexBasedAbstract implements Dispatcher {
abstract class RegexBasedAbstract implements \FastRoute\Dispatcher {
protected abstract function dispatchVariableRoute(array<array> $routeData, string $uri): array;

public function dispatch(string $httpMethod, string $uri): array;
Expand Down Expand Up @@ -99,7 +111,7 @@ namespace FastRoute\Dispatcher {
}

namespace FastRoute\RouteParser {
class Std implements RouteParser {
class Std implements \FastRoute\RouteParser {
const string VARIABLE_REGEX = <<<'REGEX'
\{
\s* ([a-zA-Z][a-zA-Z0-9_]*) \s*
Expand Down
39 changes: 39 additions & 0 deletions test/HackTypechecker/HackTypecheckerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace FastRoute;

class HackTypecheckerTest extends \PhpUnit_Framework_TestCase {
const SERVER_ALREADY_RUNNING_CODE = 77;
public function testTypechecks($recurse = true) {
if (!defined('HHVM_VERSION')) {
$this->markTestSkipped("HHVM only");
}
if (!version_compare(HHVM_VERSION, '3.9.0', '>=')) {
$this->markTestSkipped('classname<T> requires HHVM 3.9+');
}

// The typechecker recurses the whole tree, so it makes sure
// that everything in fixtures/ is valid when this runs.

$output = array();
$exit_code = null;
exec(
'hh_server --check '.escapeshellarg(__DIR__.'/../../').' 2>&1',
$output,
$exit_code
);
if ($exit_code === self::SERVER_ALREADY_RUNNING_CODE) {
$this->assertTrue(
$recurse,
"Typechecker still running after running hh_client stop"
);
// Server already running - 3.10 => 3.11 regression:
// https://github.com/facebook/hhvm/issues/6646
exec('hh_client stop 2>/dev/null');
$this->testTypechecks(/* recurse = */ false);
return;

}
$this->assertSame(0, $exit_code, implode("\n", $output));
}
}
29 changes: 29 additions & 0 deletions test/HackTypechecker/fixtures/all_options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?hh

namespace FastRoute\TestFixtures;

function all_options_simple(): \FastRoute\Dispatcher {
return \FastRoute\simpleDispatcher(
$collector ==> {},
shape(
'routeParser' => \FastRoute\RouteParser\Std::class,
'dataGenerator' => \FastRoute\DataGenerator\GroupCountBased::class,
'dispatcher' => \FastRoute\Dispatcher\GroupCountBased::class,
'routeCollector' => \FastRoute\RouteCollector::class,
),
);
}

function all_options_cached(): \FastRoute\Dispatcher {
return \FastRoute\cachedDispatcher(
$collector ==> {},
shape(
'routeParser' => \FastRoute\RouteParser\Std::class,
'dataGenerator' => \FastRoute\DataGenerator\GroupCountBased::class,
'dispatcher' => \FastRoute\Dispatcher\GroupCountBased::class,
'routeCollector' => \FastRoute\RouteCollector::class,
'cacheFile' => '/dev/null',
'cacheDisabled' => false,
),
);
}
11 changes: 11 additions & 0 deletions test/HackTypechecker/fixtures/empty_options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?hh

namespace FastRoute\TestFixtures;

function empty_options_simple(): \FastRoute\Dispatcher {
return \FastRoute\simpleDispatcher($collector ==> {}, shape());
}

function empty_options_cached(): \FastRoute\Dispatcher {
return \FastRoute\cachedDispatcher($collector ==> {}, shape());
}
11 changes: 11 additions & 0 deletions test/HackTypechecker/fixtures/no_options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?hh

namespace FastRoute\TestFixtures;

function no_options_simple(): \FastRoute\Dispatcher {
return \FastRoute\simpleDispatcher($collector ==> {});
}

function no_options_cached(): \FastRoute\Dispatcher {
return \FastRoute\cachedDispatcher($collector ==> {});
}

0 comments on commit 8164b4a

Please sign in to comment.