PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
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 1 year ago ControllerResolver.php 4 months ago HttpCodeException.php 2 years ago Router.php 1 year ago
ControllerResolver.php
95 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Http;
10
11 use Matomo\Dependencies\DI\FactoryInterface;
12 use Piwik\Exception\ThingNotFoundException;
13 use Piwik\Plugin\ReportsProvider;
14 use Piwik\Plugin\WidgetsProvider;
15 /**
16 * Resolves the controller that will handle the request.
17 *
18 * A controller is a PHP callable.
19 */
20 class ControllerResolver
21 {
22 /**
23 * @var FactoryInterface
24 */
25 private $abstractFactory;
26 /**
27 * @var WidgetsProvider
28 */
29 private $widgets;
30 public function __construct(FactoryInterface $abstractFactory, WidgetsProvider $widgets)
31 {
32 $this->abstractFactory = $abstractFactory;
33 $this->widgets = $widgets;
34 }
35 /**
36 * @param string $module
37 * @param string|null $action
38 * @param array $parameters
39 * @throws ThingNotFoundException Controller not found.
40 * @return callable The controller is a PHP callable.
41 */
42 public function getController($module, $action, array &$parameters)
43 {
44 $controller = $this->createPluginController($module, $action);
45 if ($controller) {
46 return $controller;
47 }
48 $controller = $this->createWidgetController($module, $action, $parameters);
49 if ($controller) {
50 return $controller;
51 }
52 $controller = $this->createReportController($module, $action, $parameters);
53 if ($controller) {
54 return $controller;
55 }
56 throw new ThingNotFoundException(sprintf("Action '%s' not found in the module '%s'", $action, $module));
57 }
58 private function createPluginController($module, $action)
59 {
60 $controllerClass = "Piwik\\Plugins\\{$module}\\Controller";
61 if (!class_exists($controllerClass)) {
62 return null;
63 }
64 /** @var $controller Controller */
65 $controller = $this->abstractFactory->make($controllerClass);
66 $action = $action ?: $controller->getDefaultAction();
67 if (!is_callable(array($controller, $action)) || !in_array($action, get_class_methods($controller))) {
68 return null;
69 }
70 return array($controller, $action);
71 }
72 private function createWidgetController($module, $action, array &$parameters)
73 {
74 $widget = $this->widgets->factory($module, $action);
75 if (!$widget) {
76 return;
77 }
78 $parameters['widget'] = $widget;
79 return array($this->createCoreHomeController(), 'renderWidget');
80 }
81 private function createReportController($module, $action, array &$parameters)
82 {
83 $report = ReportsProvider::factory($module, $action);
84 if (!$report) {
85 return null;
86 }
87 $parameters['report'] = $report;
88 return array($this->createCoreHomeController(), 'renderReportWidget');
89 }
90 private function createCoreHomeController()
91 {
92 return $this->abstractFactory->make('Piwik\\Plugins\\CoreHome\\Controller');
93 }
94 }
95