PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.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 5 years ago HttpCodeException.php 6 years ago Router.php 5 years ago
ControllerResolver.php
117 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\Controller;
14 use Piwik\Plugin\ReportsProvider;
15 use Piwik\Plugin\WidgetsProvider;
16
17 /**
18 * Resolves the controller that will handle the request.
19 *
20 * A controller is a PHP callable.
21 */
22 class ControllerResolver
23 {
24 /**
25 * @var FactoryInterface
26 */
27 private $abstractFactory;
28
29 /**
30 * @var WidgetsProvider
31 */
32 private $widgets;
33
34 public function __construct(FactoryInterface $abstractFactory, WidgetsProvider $widgets)
35 {
36 $this->abstractFactory = $abstractFactory;
37 $this->widgets = $widgets;
38 }
39
40 /**
41 * @param string $module
42 * @param string|null $action
43 * @param array $parameters
44 * @throws Exception Controller not found.
45 * @return callable The controller is a PHP callable.
46 */
47 public function getController($module, $action, array &$parameters)
48 {
49 $controller = $this->createPluginController($module, $action);
50 if ($controller) {
51 return $controller;
52 }
53
54 $controller = $this->createWidgetController($module, $action, $parameters);
55 if ($controller) {
56 return $controller;
57 }
58
59 $controller = $this->createReportController($module, $action, $parameters);
60 if ($controller) {
61 return $controller;
62 }
63
64 throw new Exception(sprintf("Action '%s' not found in the module '%s'", $action, $module));
65 }
66
67 private function createPluginController($module, $action)
68 {
69 $controllerClass = "Piwik\\Plugins\\$module\\Controller";
70 if (!class_exists($controllerClass)) {
71 return null;
72 }
73
74 /** @var $controller Controller */
75 $controller = $this->abstractFactory->make($controllerClass);
76
77 $action = $action ?: $controller->getDefaultAction();
78
79 if (!is_callable(array($controller, $action)) || !in_array($action, get_class_methods($controller))) {
80 return null;
81 }
82
83 return array($controller, $action);
84 }
85
86 private function createWidgetController($module, $action, array &$parameters)
87 {
88 $widget = $this->widgets->factory($module, $action);
89
90 if (!$widget) {
91 return;
92 }
93
94 $parameters['widget'] = $widget;
95
96 return array($this->createCoreHomeController(), 'renderWidget');
97 }
98
99 private function createReportController($module, $action, array &$parameters)
100 {
101 $report = ReportsProvider::factory($module, $action);
102
103 if (!$report) {
104 return null;
105 }
106
107 $parameters['report'] = $report;
108
109 return array($this->createCoreHomeController(), 'renderReportWidget');
110 }
111
112 private function createCoreHomeController()
113 {
114 return $this->abstractFactory->make('Piwik\Plugins\CoreHome\Controller');
115 }
116 }
117