]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Admin/Themes/Embed.php
Introduce `Response` for Modules to create a testable way for module responses
[friendica.git] / src / Module / Admin / Themes / Embed.php
index dabc9209e6be695ea27bcb04636babcc9265b481..1eb3018d56235e4ae98021a9025975724c561b80 100644 (file)
 
 namespace Friendica\Module\Admin\Themes;
 
+use Friendica\App;
+use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
-use Friendica\DI;
 use Friendica\Module\BaseAdmin;
+use Friendica\Module\Response;
+use Friendica\Util\Profiler;
 use Friendica\Util\Strings;
+use Psr\Log\LoggerInterface;
 
 class Embed extends BaseAdmin
 {
-       public static function init(array $parameters = [])
+       /** @var App */
+       protected $app;
+       /** @var App\Mode */
+       protected $mode;
+
+       public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Mode $mode, array $server, array $parameters = [])
        {
-               $theme = Strings::sanitizeFilePathItem($parameters['theme']);
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->app  = $app;
+               $this->mode = $mode;
+
+               $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
                if (is_file("view/theme/$theme/config.php")) {
-                       DI::app()->setCurrentTheme($theme);
+                       $this->app->setCurrentTheme($theme);
                }
        }
 
-       public static function post(array $parameters = [])
+       protected function post(array $request = [], array $post = [])
        {
                self::checkAdminAccess();
 
-               $theme = Strings::sanitizeFilePathItem($parameters['theme']);
+               $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
                if (is_file("view/theme/$theme/config.php")) {
                        require_once "view/theme/$theme/config.php";
                        if (function_exists('theme_admin_post')) {
                                self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
-                               theme_admin_post(DI::app());
+                               theme_admin_post($this->app);
                        }
                }
 
-               if (DI::mode()->isAjax()) {
+               if ($this->mode->isAjax()) {
                        return;
                }
 
-               DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
+               $this->baseUrl->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
        }
 
-       public static function content(array $parameters = [])
+       protected function content(array $request = []): string
        {
-               parent::content($parameters);
+               parent::content();
 
-               $theme = Strings::sanitizeFilePathItem($parameters['theme']);
+               $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
                if (!is_dir("view/theme/$theme")) {
-                       notice(DI::l10n()->t('Unknown theme.'));
+                       notice($this->t('Unknown theme.'));
                        return '';
                }
 
@@ -71,7 +85,7 @@ class Embed extends BaseAdmin
                        require_once "view/theme/$theme/config.php";
 
                        if (function_exists('theme_admin')) {
-                               $admin_form = theme_admin(DI::app());
+                               $admin_form = theme_admin($this->app);
                        }
                }