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