-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFastRouteRouterFactory.php
46 lines (39 loc) · 1.14 KB
/
FastRouteRouterFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Mezzio\Router;
use ArrayAccess;
use Psr\Container\ContainerInterface;
use function assert;
use function is_array;
/**
* Create and return an instance of FastRouteRouter.
*
* Configuration should look like the following:
*
* <code>
* 'router' => [
* 'fastroute' => [
* 'cache_enabled' => true, // true|false
* 'cache_file' => '(/absolute/)path/to/cache/file', // optional
* ],
* ]
* </code>
*
* @psalm-import-type FastRouteConfig from FastRouteRouter
*/
class FastRouteRouterFactory
{
public function __invoke(ContainerInterface $container): FastRouteRouter
{
$config = $container->has('config')
? $container->get('config')
: [];
assert(is_array($config) || $config instanceof ArrayAccess);
$routerConfig = $config['router'] ?? [];
assert(is_array($routerConfig) || $routerConfig instanceof ArrayAccess);
$options = $routerConfig['fastroute'] ?? [];
assert(is_array($options));
/** @psalm-var FastRouteConfig $options */
return new FastRouteRouter(null, null, $options);
}
}