Skip to content
Snippets Groups Projects
Commit 9faceafb authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

introduce PluginDispatcher, fixes #4913

Closes #4913

Merge request studip/studip!3688
parent e9727367
No related branches found
No related tags found
No related merge requests found
......@@ -6,20 +6,20 @@
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @property StudIPPlugin $plugin
* @property callable $_
* @property callable $_n
*/
class PluginController extends StudipController
{
public function __construct($dispatcher)
public function __construct(PluginDispatcher $dispatcher)
{
parent::__construct($dispatcher);
if (!isset($dispatcher->current_plugin)) {
throw new Exception('Plugin missing for plugin controller!');
}
$this->plugin = $dispatcher->current_plugin;
if ($this->plugin && $this->plugin->hasTranslation()) {
if ($this->plugin->hasTranslation()) {
// Localization
$this->_ = function ($string) {
return call_user_func_array(
......@@ -64,7 +64,10 @@ class PluginController extends StudipController
*/
public function __call($method, $arguments)
{
if (isset($this->_template_variables[$method]) && is_callable($this->_template_variables[$method])) {
if (
isset($this->_template_variables[$method])
&& is_callable($this->_template_variables[$method])
) {
return call_user_func_array($this->_template_variables[$method], $arguments);
}
return parent::__call($method, $arguments);
......
<?php
/**
* This is a specialized dispatcher for plugins.
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @license GPL2 or any later version
* @since Stud.IP 6.0
*/
class PluginDispatcher extends StudipDispatcher
{
public StudIPPlugin $current_plugin;
public function __construct(
\Psr\Container\ContainerInterface $container,
StudIPPlugin $plugin
) {
parent::__construct($container);
$this->current_plugin = $plugin;
$this->trails_root = $plugin->getPluginPath();
$this->trails_uri = rtrim(PluginEngine::getLink($this->current_plugin, [], null, true), '/');
$this->default_controller = 'index';
}
}
......@@ -196,13 +196,8 @@ abstract class StudIPPlugin
$action = $args[0] !== '' ? array_shift($args).'_action' : 'show_action';
if (!method_exists($this, $action)) {
$dispatcher = app(\Trails\Dispatcher::class);
$dispatcher->trails_root = $this->getPluginPath();
$dispatcher->trails_uri = rtrim(PluginEngine::getLink($this, [], null, true), '/');
$dispatcher->default_controller = 'index';
$dispatcher->current_plugin = $this;
try {
$dispatcher->dispatch($unconsumed_path);
app(PluginDispatcher::class, ['plugin' => $this])->dispatch($unconsumed_path);
} catch (Trails\Exceptions\UnknownAction $exception) {
if (count($args) > 0) {
throw $exception;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment