PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.13.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.13.2
5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Http / ControllerResolver.php
matomo / app / core / Http Last commit date
BadRequestException.php 6 years ago ControllerResolver.php 4 years ago HttpCodeException.php 6 years ago Router.php 5 years ago
ControllerResolver.php
116 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 */
8
9 namespace Piwik\Http;
10
11 use DI\FactoryInterface;
12 use Exception;
13 use Piwik\Plugin\ReportsProvider;
14 use Piwik\Plugin\WidgetsProvider;
15
16 /**
17 * Resolves the controller that will handle the request.
18 *
19 * A controller is a PHP callable.
20 */
21 class ControllerResolver
22 {
23 /**
24 * @var FactoryInterface
25 */
26 private $abstractFactory;
27
28 /**
29 * @var WidgetsProvider
30 */
31 private $widgets;
32
33 public function __construct(FactoryInterface $abstractFactory, WidgetsProvider $widgets)
34 {
35 $this->abstractFactory = $abstractFactory;
36 $this->widgets = $widgets;
37 }
38
39 /**
40 * @param string $module
41 * @param string|null $action
42 * @param array $parameters
43 * @throws Exception Controller not found.
44 * @return callable The controller is a PHP callable.
45 */
46 public function getController($module, $action, array &$parameters)
47 {
48 $controller = $this->createPluginController($module, $action);
49 if ($controller) {
50 return $controller;
51 }
52
53 $controller = $this->createWidgetController($module, $action, $parameters);
54 if ($controller) {
55 return $controller;
56 }
57
58 $controller = $this->createReportController($module, $action, $parameters);
59 if ($controller) {
60 return $controller;
61 }
62
63 throw new Exception(sprintf("Action '%s' not found in the module '%s'", $action, $module));
64 }
65
66 private function createPluginController($module, $action)
67 {
68 $controllerClass = "Piwik\\Plugins\\$module\\Controller";
69 if (!class_exists($controllerClass)) {
70 return null;
71 }
72
73 /** @var $controller Controller */
74 $controller = $this->abstractFactory->make($controllerClass);
75
76 $action = $action ?: $controller->getDefaultAction();
77
78 if (!is_callable(array($controller, $action)) || !in_array($action, get_class_methods($controller))) {
79 return null;
80 }
81
82 return array($controller, $action);
83 }
84
85 private function createWidgetController($module, $action, array &$parameters)
86 {
87 $widget = $this->widgets->factory($module, $action);
88
89 if (!$widget) {
90 return;
91 }
92
93 $parameters['widget'] = $widget;
94
95 return array($this->createCoreHomeController(), 'renderWidget');
96 }
97
98 private function createReportController($module, $action, array &$parameters)
99 {
100 $report = ReportsProvider::factory($module, $action);
101
102 if (!$report) {
103 return null;
104 }
105
106 $parameters['report'] = $report;
107
108 return array($this->createCoreHomeController(), 'renderReportWidget');
109 }
110
111 private function createCoreHomeController()
112 {
113 return $this->abstractFactory->make('Piwik\Plugins\CoreHome\Controller');
114 }
115 }
116