1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Dash |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/DASPRiD/Dash For the canonical source repository |
6
|
|
|
* @copyright 2013-2015 Ben Scholzen 'DASPRiD' |
7
|
|
|
* @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Dash\Route; |
11
|
|
|
|
12
|
|
|
use Dash\Parser\ParserManager; |
13
|
|
|
use Dash\RouteCollection\LazyRouteCollection; |
14
|
|
|
use Interop\Container\ContainerInterface; |
15
|
|
|
|
16
|
|
|
class GenericFactory |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
* |
21
|
|
|
* @return Generic |
22
|
|
|
*/ |
23
|
|
|
public function __invoke(ContainerInterface $container, $resolvedName, array $options = null) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
if ($options === null) { |
26
|
|
|
return new Generic(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// Parameter normalization |
30
|
|
|
if (!isset($options['path']) && isset($options[0])) { |
31
|
|
|
$options['path'] = $options[0]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if (isset($options['defaults']) && isset($options[1])) { |
35
|
|
|
$options['defaults'] += $options[1]; |
36
|
|
|
} elseif (isset($options[1])) { |
37
|
|
|
$options['defaults'] = $options[1]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if (isset($options['methods']) && isset($options[2])) { |
41
|
|
|
$options['methods'] = array_merge($options[2], $options['methods']); |
42
|
|
|
} elseif (isset($options[2])) { |
43
|
|
|
$options['methods'] = $options[2]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// Try to retrive path and hostname parser |
47
|
|
|
$parserManager = $container->get(ParserManager::class); |
48
|
|
|
|
49
|
|
|
if (isset($options['path_parser'])) { |
50
|
|
|
$pathParser = $parserManager->build($options['path_parser'], $options); |
51
|
|
|
} elseif (isset($options['path'])) { |
52
|
|
|
$pathParser = $parserManager->build('PathSegment', $options); |
53
|
|
|
} else { |
54
|
|
|
$pathParser = null; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (isset($options['hostname_parser'])) { |
58
|
|
|
$hostnameParser = $parserManager->build($options['hostname_parser'], $options); |
59
|
|
|
} elseif (isset($options['hostname'])) { |
60
|
|
|
$hostnameParser = $parserManager->build('HostnameSegment', $options); |
61
|
|
|
} else { |
62
|
|
|
$hostnameParser = null; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// Setup children if they exist |
66
|
|
|
if (isset($options['children'])) { |
67
|
|
|
$children = new LazyRouteCollection($container->get(RouteManager::class), $options['children']); |
68
|
|
|
} else { |
69
|
|
|
$children = null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return new Generic( |
73
|
|
|
$pathParser, |
74
|
|
|
$hostnameParser, |
75
|
|
|
isset($options['methods']) ? $options['methods'] : null, |
76
|
|
|
isset($options['secure']) ? $options['secure'] : null, |
77
|
|
|
isset($options['port']) ? $options['port'] : null, |
78
|
|
|
isset($options['defaults']) ? $options['defaults'] : [], |
79
|
|
|
$children |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.