Skip to content

Commit

Permalink
Convert system plugins to service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Mar 27, 2023
1 parent 16a7dc9 commit 554c8c6
Show file tree
Hide file tree
Showing 70 changed files with 1,506 additions and 592 deletions.
4 changes: 3 additions & 1 deletion plugins/system/accessibility/accessibility.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>4.0.0</version>
<description>PLG_SYSTEM_ACCESSIBILITY_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\System\Accessibility</namespace>
<files>
<filename plugin="accessibility">accessibility.php</filename>
<folder plugin="accessibility">services</folder>
<folder>src</folder>
</files>
<languages folder="admin">
<language tag="en-GB">language/en-GB/plg_system_accessibility.ini</language>
Expand Down
47 changes: 47 additions & 0 deletions plugins/system/accessibility/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage System.accessibility
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Fields\Calendar\Extension\Calendar;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Calendar(
$dispatcher,
(array) PluginHelper::getPlugin('system', 'accessibility')
);
$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
*
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
namespace Joomla\Plugin\System\Accessibility\Extension;

use Joomla\CMS\Plugin\CMSPlugin;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -23,15 +21,8 @@
*
* @since 4.0.0
*/
class PlgSystemAccessibility extends CMSPlugin
final class Accessibility extends CMSPlugin
{
/**
* @var \Joomla\CMS\Application\CMSApplication
*
* @since 4.0.0
*/
protected $app;

/**
* Add the javascript for the accessibility menu
*
Expand All @@ -43,30 +34,30 @@ public function onBeforeCompileHead()
{
$section = $this->params->get('section', 'administrator');

if ($section !== 'both' && $this->app->isClient($section) !== true) {
if ($section !== 'both' && $this->getApplication()->isClient($section) !== true) {
return;
}

// Get the document object.
$document = $this->app->getDocument();
$document = $this->getApplication()->getDocument();

if ($document->getType() !== 'html') {
return;
}

// Are we in a modal?
if ($this->app->getInput()->get('tmpl', '', 'cmd') === 'component') {
if ($this->getApplication()->getInput()->get('tmpl', '', 'cmd') === 'component') {
return;
}

// Load language file.
$this->loadLanguage();

// Determine if it is an LTR or RTL language
$direction = Factory::getLanguage()->isRtl() ? 'right' : 'left';
$direction = $this->getApplication()->getLanguage()->isRtl() ? 'right' : 'left';

// Detect the current active language
$lang = Factory::getLanguage()->getTag();
$lang = $this->getApplication()->getLanguage()->getTag();

/**
* Add strings for translations in Javascript.
Expand All @@ -76,20 +67,20 @@ public function onBeforeCompileHead()
'accessibility-options',
[
'labels' => [
'menuTitle' => Text::_('PLG_SYSTEM_ACCESSIBILITY_MENU_TITLE'),
'increaseText' => Text::_('PLG_SYSTEM_ACCESSIBILITY_INCREASE_TEXT'),
'decreaseText' => Text::_('PLG_SYSTEM_ACCESSIBILITY_DECREASE_TEXT'),
'increaseTextSpacing' => Text::_('PLG_SYSTEM_ACCESSIBILITY_INCREASE_SPACING'),
'decreaseTextSpacing' => Text::_('PLG_SYSTEM_ACCESSIBILITY_DECREASE_SPACING'),
'invertColors' => Text::_('PLG_SYSTEM_ACCESSIBILITY_INVERT_COLORS'),
'grayHues' => Text::_('PLG_SYSTEM_ACCESSIBILITY_GREY'),
'underlineLinks' => Text::_('PLG_SYSTEM_ACCESSIBILITY_UNDERLINE'),
'bigCursor' => Text::_('PLG_SYSTEM_ACCESSIBILITY_CURSOR'),
'readingGuide' => Text::_('PLG_SYSTEM_ACCESSIBILITY_READING'),
'textToSpeech' => Text::_('PLG_SYSTEM_ACCESSIBILITY_TTS'),
'speechToText' => Text::_('PLG_SYSTEM_ACCESSIBILITY_STT'),
'resetTitle' => Text::_('PLG_SYSTEM_ACCESSIBILITY_RESET'),
'closeTitle' => Text::_('PLG_SYSTEM_ACCESSIBILITY_CLOSE'),
'menuTitle' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_MENU_TITLE'),
'increaseText' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INCREASE_TEXT'),
'decreaseText' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_DECREASE_TEXT'),
'increaseTextSpacing' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INCREASE_SPACING'),
'decreaseTextSpacing' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_DECREASE_SPACING'),
'invertColors' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INVERT_COLORS'),
'grayHues' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_GREY'),
'underlineLinks' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_UNDERLINE'),
'bigCursor' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_CURSOR'),
'readingGuide' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_READING'),
'textToSpeech' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_TTS'),
'speechToText' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_STT'),
'resetTitle' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_RESET'),
'closeTitle' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_CLOSE'),
],
'icon' => [
'position' => [
Expand Down
4 changes: 3 additions & 1 deletion plugins/system/actionlogs/actionlogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.9.0</version>
<description>PLG_SYSTEM_ACTIONLOGS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\System\ActionLogs</namespace>
<files>
<filename plugin="actionlogs">actionlogs.php</filename>
<folder>forms</folder>
<folder plugin="actionlogs">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_system_actionlogs.ini</language>
Expand Down
49 changes: 49 additions & 0 deletions plugins/system/actionlogs/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage System.actionlogs
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\System\ActionLogs\Extension\ActionLogs;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new ActionLogs(
$dispatcher,
(array) PluginHelper::getPlugin('system', 'actionlogs')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

namespace Joomla\Plugin\System\ActionLogs\Extension;

use Exception;
use JLoader;
use Joomla\CMS\Cache\Cache;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
Expand All @@ -19,8 +21,10 @@
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\User\User;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\Exception\ExecutionFailureException;
use Joomla\Database\ParameterType;
use RuntimeException;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -31,21 +35,9 @@
*
* @since 3.9.0
*/
class PlgSystemActionLogs extends CMSPlugin
final class ActionLogs extends CMSPlugin
{
/**
* @var \Joomla\CMS\Application\CMSApplication
*
* @since 3.9.0
*/
protected $app;

/**
* @var \Joomla\Database\DatabaseDriver
*
* @since 3.9.0
*/
protected $db;
use DatabaseAwareTrait;

/**
* Constructor.
Expand Down Expand Up @@ -113,7 +105,7 @@ public function onContentPrepareForm(Form $form, $data)
}

// If we are on the save command, no data is passed to $data variable, we need to get it directly from request
$jformData = $this->app->getInput()->get('jform', [], 'array');
$jformData = $this->getApplication()->getInput()->get('jform', [], 'array');

if ($jformData && !$data) {
$data = $jformData;
Expand All @@ -129,7 +121,7 @@ public function onContentPrepareForm(Form $form, $data)

Form::addFormPath(__DIR__ . '/forms');

if ((!PluginHelper::isEnabled('actionlog', 'joomla')) && (Factory::getApplication()->isClient('administrator'))) {
if ((!PluginHelper::isEnabled('actionlog', 'joomla')) && ($this->getApplication()->isClient('administrator'))) {
$form->loadFile('information', false);

return true;
Expand Down Expand Up @@ -168,7 +160,7 @@ public function onContentPrepareData($context, $data)
return true;
}

$db = $this->db;
$db = $this->getDatabase();
$id = (int) $data->id;

$query = $db->getQuery(true)
Expand Down Expand Up @@ -232,7 +224,7 @@ public function onAfterRespond()
// Update last run status
$this->params->set('lastrun', $now);

$db = $this->db;
$db = $this->getDatabase();
$params = $this->params->toString('JSON');
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
Expand Down Expand Up @@ -313,7 +305,7 @@ private function clearCacheGroups(array $clearGroups, array $cacheClients = [0,
$options = [
'defaultgroup' => $group,
'cachebase' => $clientId ? JPATH_ADMINISTRATOR . '/cache' :
Factory::getApplication()->get('cache_path', JPATH_SITE . '/cache'),
$this->getApplication()->get('cache_path', JPATH_SITE . '/cache'),
];

$cache = Cache::getInstance('callback', $options);
Expand Down Expand Up @@ -349,7 +341,7 @@ public function onUserAfterSave($user, $isNew, $success, $msg): void

$authorised = $userObject->authorise('core.admin');
$userid = (int) $user['id'];
$db = $this->db;
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select('COUNT(*)')
Expand Down Expand Up @@ -436,7 +428,7 @@ public function onUserAfterDelete($user, $success, $msg): void
return;
}

$db = $this->db;
$db = $this->getDatabase();
$userid = (int) $user['id'];

$query = $db->getQuery(true)
Expand Down
2 changes: 1 addition & 1 deletion plugins/system/debug/debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>PLG_DEBUG_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\System\Debug</namespace>
<files>
<filename plugin="debug">debug.php</filename>
<folder plugin="debug">services</folder>
<folder>src</folder>
</files>
<languages>
Expand Down
46 changes: 46 additions & 0 deletions plugins/system/debug/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage System.debug
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\System\Debug\Extension\Debug;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
return new Debug(
Factory::getApplication(),
$container->get(DatabaseInterface::class),
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'debug')
);
}
);
}
};

0 comments on commit 554c8c6

Please sign in to comment.