|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Joomla! Statistics Server |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved. |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Joomla\StatsServer; |
|
10
|
|
|
|
|
11
|
|
|
use Joomla\Controller\ControllerInterface; |
|
12
|
|
|
use Joomla\DI\{ |
|
13
|
|
|
ContainerAwareInterface, ContainerAwareTrait |
|
14
|
|
|
}; |
|
15
|
|
|
use Joomla\Router\RestRouter; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Stats application router |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.0 |
|
21
|
|
|
*/ |
|
22
|
|
|
class Router extends RestRouter implements ContainerAwareInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use ContainerAwareTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get a controller object for a given name. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $name The controller name (excluding prefix) for which to fetch and instance. |
|
30
|
|
|
* |
|
31
|
|
|
* @return ControllerInterface |
|
32
|
|
|
* |
|
33
|
|
|
* @since 1.0 |
|
34
|
|
|
* @throws \RuntimeException |
|
35
|
|
|
*/ |
|
36
|
1 |
|
protected function fetchController($name) |
|
37
|
|
|
{ |
|
38
|
|
|
// Derive the controller class name. |
|
39
|
1 |
|
$class = $this->controllerPrefix . ucfirst($name); |
|
40
|
|
|
|
|
41
|
|
|
// If the controller class does not exist panic. |
|
42
|
1 |
|
if (!class_exists($class)) |
|
43
|
|
|
{ |
|
44
|
|
|
throw new \RuntimeException(sprintf('Unable to locate controller `%s`.', $class), 404); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// If the controller does not follows the implementation. |
|
48
|
1 |
|
if (!is_subclass_of($class, 'Joomla\\Controller\\ControllerInterface')) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
throw new \RuntimeException( |
|
51
|
|
|
sprintf('Invalid Controller. Controllers must implement Joomla\Controller\ControllerInterface. `%s`.', $class), 500 |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
// Instantiate the controller. |
|
56
|
1 |
|
return $this->getContainer()->get($class); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|