Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Convert mod_version to service provider #42814

Merged
merged 16 commits into from Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 0 additions & 15 deletions administrator/modules/mod_version/mod_version.php

This file was deleted.

2 changes: 1 addition & 1 deletion administrator/modules/mod_version/mod_version.xml
Expand Up @@ -11,7 +11,7 @@
<description>MOD_VERSION_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\Version</namespace>
<files>
<filename module="mod_version">mod_version.php</filename>
<folder module="mod_version">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
36 changes: 36 additions & 0 deletions administrator/modules/mod_version/services/provider.php
@@ -0,0 +1,36 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage mod_version
*
* @copyright (C) 2024 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\Service\Provider\HelperFactory;
use Joomla\CMS\Extension\Service\Provider\Module;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

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)
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Version'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Version\\Administrator\\Helper'));

$container->registerServiceProvider(new Module());
}
};
45 changes: 45 additions & 0 deletions administrator/modules/mod_version/src/Dispatcher/Dispatcher.php
@@ -0,0 +1,45 @@
<?php

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

namespace Joomla\Module\Version\Administrator\Dispatcher;

use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Dispatcher class for mod_version
*
* @since __DEPLOY_VERSION__
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;

/**
* Returns the layout data.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();

$data['version'] = $this->getHelperFactory()->getHelper('VersionHelper')->getVersionString();

return $data;
}
}
22 changes: 20 additions & 2 deletions administrator/modules/mod_version/src/Helper/VersionHelper.php
Expand Up @@ -21,17 +21,35 @@
*
* @since 1.6
*/
abstract class VersionHelper
class VersionHelper
{
/**
* Get the Joomla version number.
*
* @return string String containing the current Joomla version.
*
* @since __DEPLOY_VERSION__
*/
public static function getVersion()
public function getVersionString()
{
$version = new Version();

return '&#x200E;' . $version->getShortVersion();
}

/**
* Get the Joomla version number.
*
* @return string String containing the current Joomla version.
*
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
* Use the non-static method getVersionString
* Example: Factory::getApplication()->bootModule('mod_version', 'administrator')
* ->getHelper('VersionHelper')
* ->getVersionString()
*/
public static function getVersion()
{
return (new self())->getVersionString();
}
}