-
Notifications
You must be signed in to change notification settings - Fork 30
/
ChainRouter.php
80 lines (69 loc) · 1.62 KB
/
ChainRouter.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* This file is part of the PPI Framework.
*
* @copyright Copyright (c) 2011-2016 Paul Dragoonis <paul@ppi.io>
* @license http://opensource.org/licenses/mit-license.php MIT
*
* @link http://www.ppi.io
*/
namespace PPI\Framework\Router;
use Symfony\Cmf\Component\Routing\ChainRouter as BaseChainRouter;
use Symfony\Component\HttpFoundation\Request;
/**
* Class ChainRouter.
*
* @author Paul Dragoonis <paul@ppi.io>
*/
class ChainRouter extends BaseChainRouter
{
/**
* @var Request
*/
protected $matchedRouteRequest;
/**
* @param array $parameters
*
* @return string
*/
public function parametersToString(array $parameters)
{
$pieces = array();
foreach ($parameters as $key => $val) {
$pieces[] = sprintf('"%s": "%s"', $key, (is_string($val) ? $val : json_encode($val)));
}
return implode(', ', $pieces);
}
/**
* @return bool
*/
public function hasRouters()
{
$routers = $this->sortRouters();
return !empty($routers);
}
/**
* @todo - might not need this afterall
*
* @return Request
*/
public function getMatchedRouteRequest()
{
return $this->matchedRouteRequest;
}
/**
* @param Request $request
*
* @throws \Exception
*/
public function matchRequest(Request $request)
{
try {
$parameters = parent::matchRequest($request);
$this->matchedRouteRequest = $request;
return $parameters;
} catch (\Exception $e) {
throw $e;
}
}
}