Skip to content

Commit 8164b4a

Browse files
committed
Merge pull request #83 from fredemmott/fastroute-hhi
HHI: Change the options arrays for dispatchers to shapes
2 parents 864fab0 + 9922e64 commit 8164b4a

File tree

6 files changed

+108
-5
lines changed

6 files changed

+108
-5
lines changed

Diff for: .hhconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assume_php=false

Diff for: FastRoute.hhi

+17-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,27 @@ namespace FastRoute {
3333

3434
function simpleDispatcher(
3535
(function(RouteCollector): void) $routeDefinitionCallback,
36-
array<string, string> $options = []): Dispatcher;
36+
shape(
37+
'routeParser' => ?classname<RouteParser>,
38+
'dataGenerator' => ?classname<DataGenerator>,
39+
'dispatcher' => ?classname<Dispatcher>,
40+
'routeCollector' => ?classname<RouteCollector>,
41+
) $options = shape()): Dispatcher;
3742

3843
function cachedDispatcher(
3944
(function(RouteCollector): void) $routeDefinitionCallback,
40-
array<string, string> $options = []): Dispatcher;
45+
shape(
46+
'routeParser' => ?classname<RouteParser>,
47+
'dataGenerator' => ?classname<DataGenerator>,
48+
'dispatcher' => ?classname<Dispatcher>,
49+
'routeCollector' => ?classname<RouteCollector>,
50+
'cacheDisabled' => ?bool,
51+
'cacheFile' => ?string,
52+
) $options = shape()): Dispatcher;
4153
}
4254

4355
namespace FastRoute\DataGenerator {
44-
abstract class RegexBasedAbstract implements DataGenerator {
56+
abstract class RegexBasedAbstract implements \FastRoute\DataGenerator {
4557
protected abstract function getApproxChunkSize();
4658
protected abstract function processChunk($regexToRoutesMap);
4759

@@ -71,7 +83,7 @@ namespace FastRoute\DataGenerator {
7183
}
7284

7385
namespace FastRoute\Dispatcher {
74-
abstract class RegexBasedAbstract implements Dispatcher {
86+
abstract class RegexBasedAbstract implements \FastRoute\Dispatcher {
7587
protected abstract function dispatchVariableRoute(array<array> $routeData, string $uri): array;
7688

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

101113
namespace FastRoute\RouteParser {
102-
class Std implements RouteParser {
114+
class Std implements \FastRoute\RouteParser {
103115
const string VARIABLE_REGEX = <<<'REGEX'
104116
\{
105117
\s* ([a-zA-Z][a-zA-Z0-9_]*) \s*

Diff for: test/HackTypechecker/HackTypecheckerTest.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace FastRoute;
4+
5+
class HackTypecheckerTest extends \PhpUnit_Framework_TestCase {
6+
const SERVER_ALREADY_RUNNING_CODE = 77;
7+
public function testTypechecks($recurse = true) {
8+
if (!defined('HHVM_VERSION')) {
9+
$this->markTestSkipped("HHVM only");
10+
}
11+
if (!version_compare(HHVM_VERSION, '3.9.0', '>=')) {
12+
$this->markTestSkipped('classname<T> requires HHVM 3.9+');
13+
}
14+
15+
// The typechecker recurses the whole tree, so it makes sure
16+
// that everything in fixtures/ is valid when this runs.
17+
18+
$output = array();
19+
$exit_code = null;
20+
exec(
21+
'hh_server --check '.escapeshellarg(__DIR__.'/../../').' 2>&1',
22+
$output,
23+
$exit_code
24+
);
25+
if ($exit_code === self::SERVER_ALREADY_RUNNING_CODE) {
26+
$this->assertTrue(
27+
$recurse,
28+
"Typechecker still running after running hh_client stop"
29+
);
30+
// Server already running - 3.10 => 3.11 regression:
31+
// https://github.com/facebook/hhvm/issues/6646
32+
exec('hh_client stop 2>/dev/null');
33+
$this->testTypechecks(/* recurse = */ false);
34+
return;
35+
36+
}
37+
$this->assertSame(0, $exit_code, implode("\n", $output));
38+
}
39+
}

Diff for: test/HackTypechecker/fixtures/all_options.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?hh
2+
3+
namespace FastRoute\TestFixtures;
4+
5+
function all_options_simple(): \FastRoute\Dispatcher {
6+
return \FastRoute\simpleDispatcher(
7+
$collector ==> {},
8+
shape(
9+
'routeParser' => \FastRoute\RouteParser\Std::class,
10+
'dataGenerator' => \FastRoute\DataGenerator\GroupCountBased::class,
11+
'dispatcher' => \FastRoute\Dispatcher\GroupCountBased::class,
12+
'routeCollector' => \FastRoute\RouteCollector::class,
13+
),
14+
);
15+
}
16+
17+
function all_options_cached(): \FastRoute\Dispatcher {
18+
return \FastRoute\cachedDispatcher(
19+
$collector ==> {},
20+
shape(
21+
'routeParser' => \FastRoute\RouteParser\Std::class,
22+
'dataGenerator' => \FastRoute\DataGenerator\GroupCountBased::class,
23+
'dispatcher' => \FastRoute\Dispatcher\GroupCountBased::class,
24+
'routeCollector' => \FastRoute\RouteCollector::class,
25+
'cacheFile' => '/dev/null',
26+
'cacheDisabled' => false,
27+
),
28+
);
29+
}

Diff for: test/HackTypechecker/fixtures/empty_options.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?hh
2+
3+
namespace FastRoute\TestFixtures;
4+
5+
function empty_options_simple(): \FastRoute\Dispatcher {
6+
return \FastRoute\simpleDispatcher($collector ==> {}, shape());
7+
}
8+
9+
function empty_options_cached(): \FastRoute\Dispatcher {
10+
return \FastRoute\cachedDispatcher($collector ==> {}, shape());
11+
}

Diff for: test/HackTypechecker/fixtures/no_options.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?hh
2+
3+
namespace FastRoute\TestFixtures;
4+
5+
function no_options_simple(): \FastRoute\Dispatcher {
6+
return \FastRoute\simpleDispatcher($collector ==> {});
7+
}
8+
9+
function no_options_cached(): \FastRoute\Dispatcher {
10+
return \FastRoute\cachedDispatcher($collector ==> {});
11+
}

0 commit comments

Comments
 (0)