Skip to content

Commit

Permalink
more injection
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Mar 27, 2023
1 parent ed3df6a commit 9380904
Show file tree
Hide file tree
Showing 27 changed files with 185 additions and 106 deletions.
4 changes: 2 additions & 2 deletions plugins/system/actionlogs/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function register(Container $container): void
PluginInterface::class,
function (Container $container) {
$plugin = new ActionLogs(
$container->get(UserFactoryInterface::class),
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'actionlogs')
(array) PluginHelper::getPlugin('system', 'actionlogs'),
$container->get(UserFactoryInterface::class)
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
Expand Down
7 changes: 4 additions & 3 deletions plugins/system/actionlogs/src/Extension/ActionLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ final class ActionLogs extends CMSPlugin
/**
* Constructor.
*
* @param object $subject The object to observe.
* @param array $config An optional associative array of configuration settings.
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
* @param UserFactoryInterface $userFactory The user factory
*
* @since 3.9.0
*/
public function __construct(UserFactoryInterface $userFactory, DispatcherInterface $dispatcher, array $config)
public function __construct(DispatcherInterface $dispatcher, array $config, UserFactoryInterface $userFactory)
{
parent::__construct($dispatcher, $config);

Expand Down
6 changes: 3 additions & 3 deletions plugins/system/debug/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function register(Container $container): void
PluginInterface::class,
function (Container $container) {
return new Debug(
Factory::getApplication(),
$container->get(DatabaseInterface::class),
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'debug')
(array) PluginHelper::getPlugin('system', 'debug'),
Factory::getApplication(),
$container->get(DatabaseInterface::class)
);
}
);
Expand Down
6 changes: 3 additions & 3 deletions plugins/system/debug/src/Extension/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ public static function getSubscribedEvents(): array
}

/**
* @param CMSApplicationInterface $app The app
* @param DatabaseInterface $db The db
* @param DispatcherInterface $dispatcher The object to observe -- event dispatcher.
* @param array $config An optional associative array of configuration settings.
* @param CMSApplicationInterface $app The app
* @param DatabaseInterface $db The db
*
* @since 1.5
*/
public function __construct(CMSApplicationInterface $app, DatabaseInterface $db, DispatcherInterface $dispatcher, $config)
public function __construct(DispatcherInterface $dispatcher, $config, CMSApplicationInterface $app, DatabaseInterface $db)
{
parent::__construct($dispatcher, $config);

Expand Down
9 changes: 5 additions & 4 deletions plugins/system/fields/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
Expand All @@ -33,10 +34,10 @@ public function register(Container $container): void
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Fields(
$dispatcher,
(array) PluginHelper::getPlugin('system', 'fields')
$plugin = new Fields(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'fields'),
$container->get(UserFactoryInterface::class)
);
$plugin->setApplication(Factory::getApplication());

Expand Down
30 changes: 28 additions & 2 deletions plugins/system/fields/src/Extension/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

namespace Joomla\Plugin\System\Fields\Extension;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Event\DispatcherInterface;
use Joomla\Registry\Registry;
use stdClass;

Expand All @@ -37,6 +38,31 @@ final class Fields extends CMSPlugin
*/
protected $autoloadLanguage = true;

/**
* The user factory
*
* @var UserFactoryInterface
*
* @since __DEPLOY_VERSION__
*/
private $userFactory;

/**
* Constructor.
*
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
* @param UserFactoryInterface $userFactory The user factory
*
* @since __DEPLOY_VERSION__
*/
public function __construct(DispatcherInterface $dispatcher, array $config, UserFactoryInterface $userFactory)
{
parent::__construct($dispatcher, $config);

$this->userFactory = $userFactory;
}

/**
* Normalizes the request data.
*
Expand Down Expand Up @@ -176,7 +202,7 @@ public function onUserAfterSave($userData, $isNew, $success, $msg): void
return;
}

$user = Factory::getUser($userData['id']);
$user = $this->userFactory->loadUserById($userData['id']);

$task = $this->getApplication()->getInput()->getCmd('task');

Expand Down
10 changes: 4 additions & 6 deletions plugins/system/highlight/src/Extension/Highlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Joomla\Plugin\System\Highlight\Extension;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Finder\Administrator\Indexer\Result;
Expand Down Expand Up @@ -77,10 +76,11 @@ public function onAfterDispatch()
$cleanTerms[] = htmlspecialchars($filter->clean($term, 'string'));
}

/** @var \Joomla\CMS\Document\HtmlDocument $doc */
$doc = $this->getApplication()->getDocument();

// Activate the highlighter.
if (!empty($cleanTerms)) {
$doc = Factory::getDocument();

$doc->getWebAssetManager()->useScript('highlight');
$doc->addScriptOptions(
'highlight',
Expand All @@ -92,8 +92,6 @@ public function onAfterDispatch()
}

// Adjust the component buffer.
/** @var \Joomla\CMS\Document\HtmlDocument $doc */
$doc = $this->getApplication()->getDocument();
$buf = $doc->getBuffer('component');
$buf = '<div class="js-highlight">' . $buf . '</div>';
$doc->setBuffer($buf, 'component');
Expand All @@ -103,7 +101,7 @@ public function onAfterDispatch()
* Method to catch the onFinderResult event.
*
* @param Result $item The search result
* @param array $query The search query of this result
* @param object $query The search query of this result
*
* @return void
*
Expand Down
4 changes: 2 additions & 2 deletions plugins/system/httpheaders/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function register(Container $container): void
PluginInterface::class,
function (Container $container) {
$plugin = new Httpheaders(
Factory::getApplication(),
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'httpheaders')
(array) PluginHelper::getPlugin('system', 'httpheaders'),
Factory::getApplication()
);
$plugin->setDatabase($container->get(DatabaseInterface::class));

Expand Down
5 changes: 2 additions & 3 deletions plugins/system/httpheaders/src/Extension/Httpheaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ final class Httpheaders extends CMSPlugin implements SubscriberInterface
];

/**
* @param CMSApplicationInterface $app The app
* @param DatabaseInterface $db The db
* @param DispatcherInterface $dispatcher The object to observe -- event dispatcher.
* @param array $config An optional associative array of configuration settings.
* @param CMSApplicationInterface $app The app
*
* @since 4.0.0
*/
public function __construct(CMSApplicationInterface $app, DispatcherInterface $dispatcher, $config)
public function __construct(DispatcherInterface $dispatcher, $config, CMSApplicationInterface $app)
{
parent::__construct($dispatcher, $config);

Expand Down
20 changes: 5 additions & 15 deletions plugins/system/jooa11y/src/Extension/Jooa11y.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Joomla\Plugin\System\Jooa11y\Extension;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;
Expand Down Expand Up @@ -45,14 +44,7 @@ final class Jooa11y extends CMSPlugin implements SubscriberInterface
*/
public static function getSubscribedEvents(): array
{
$mapping = [];

// Only trigger in frontend
if (Factory::getApplication()->isClient('site')) {
$mapping['onBeforeCompileHead'] = 'initJooa11y';
}

return $mapping;
return ['onBeforeCompileHead' => 'initJooa11y'];
}

/**
Expand Down Expand Up @@ -97,6 +89,10 @@ private function isAuthorisedDisplayChecker(): bool
*/
public function initJooa11y()
{
if (!$this->getApplication()->isClient('site')) {
return;
}

// Check if we are in a preview modal or the plugin has enforced loading
$showJooa11y = $this->getApplication()->getInput()->get('jooa11y', $this->params->get('showAlways', 0));

Expand All @@ -108,12 +104,6 @@ public function initJooa11y()
// Get the document object.
$document = $this->getApplication()->getDocument();

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

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

// Add plugin settings from the xml
$document->addScriptOptions(
'jooa11yOptions',
Expand Down
11 changes: 6 additions & 5 deletions plugins/system/languagefilter/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\LanguageFactoryInterface;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\SiteRouter;
use Joomla\DI\Container;
Expand All @@ -34,12 +35,12 @@ public function register(Container $container): void
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new LanguageFilter(
$dispatcher,
(array) PluginHelper::getPlugin('system', 'languagefilter')
$plugin = new LanguageFilter(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'languagefilter'),
Factory::getApplication(),
$container->get(LanguageFactoryInterface::class)
);
$plugin->setApplication(Factory::getApplication());
$plugin->setSiteRouter($container->get(SiteRouter::class));

return $plugin;
Expand Down
31 changes: 24 additions & 7 deletions plugins/system/languagefilter/src/Extension/Languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

use JLoader;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Language;
use Joomla\CMS\Language\LanguageFactoryInterface;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
Expand All @@ -27,6 +29,7 @@
use Joomla\CMS\Router\SiteRouterAwareTrait;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Menus\Administrator\Helper\MenusHelper;
use Joomla\Event\DispatcherInterface;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
Expand Down Expand Up @@ -92,17 +95,31 @@ final class LanguageFilter extends CMSPlugin
*/
private $user_lang_code;

/**
* The language factory
*
* @var LanguageFactoryInterface
*
* @since __DEPLOY_VERSION__
*/
private $languageFactory;

/**
* Constructor.
*
* @param object &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
* @param UserFactoryInterface $userFactory The user factory
*
* @since 1.6
* @since 1.6.0
*/
public function __construct(&$subject, $config)
public function __construct(DispatcherInterface $dispatcher, array $config,CMSApplicationInterface $app, LanguageFactoryInterface $languageFactory)
{
parent::__construct($subject, $config);
parent::__construct($dispatcher, $config);

$this->languageFactory = $languageFactory;

$this->setApplication($app);

// Setup language data.
$this->mode_sef = $this->getApplication()->get('sef', 0);
Expand Down Expand Up @@ -450,7 +467,7 @@ public function parseRule(&$router, &$uri)
$language = $this->getApplication()->getLanguage();

if ($language->getTag() !== $lang_code) {
$language_new = Language::getInstance($lang_code, (bool) $this->getApplication()->get('debug_lang'));
$language_new = $this->languageFactory->createLanguage($lang_code, (bool) $this->getApplication()->get('debug_lang'));

foreach ($language->getPaths() as $extension => $files) {
if (strpos($extension, 'plg_system') !== false) {
Expand Down Expand Up @@ -652,7 +669,7 @@ public function onUserLogin($user, $options = [])
$this->setLanguageCookie($lang_code);

// Change the language code.
Factory::getContainer()->get(\Joomla\CMS\Language\LanguageFactoryInterface::class)->createLanguage($lang_code);
$this->languageFactory->createLanguage($lang_code);
}
} else {
if ($this->getApplication()->getUserState('users.login.form.return')) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/system/logout/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function register(Container $container): void
PluginInterface::class,
function (Container $container) {
return new Logout(
Factory::getApplication(),
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'logout')
(array) PluginHelper::getPlugin('system', 'logout'),
Factory::getApplication()
);
}
);
Expand Down
4 changes: 2 additions & 2 deletions plugins/system/logout/src/Extension/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ final class Logout extends CMSPlugin
protected $autoloadLanguage = true;

/**
* @param CMSApplicationInterface $app The object to observe -- event dispatcher.
* @param DispatcherInterface $dispatcher The object to observe -- event dispatcher.
* @param array $config An optional associative array of configuration settings.
* @param CMSApplicationInterface $app The object to observe -- event dispatcher.
*
* @since 1.6
*/
public function __construct(CMSApplicationInterface $app, DispatcherInterface $dispatcher, $config)
public function __construct(DispatcherInterface $dispatcher, $config, CMSApplicationInterface $app)
{
parent::__construct($dispatcher, $config);

Expand Down

0 comments on commit 9380904

Please sign in to comment.