Skip to content

Commit dacda5c

Browse files
authored
[5.1] Convert mod_version to service provider (#42814)
* Convert mod_version to service provider * getVersion method non-static * Static function getVersion deprecated * Deprecated function getVersion static
1 parent f4876ca commit dacda5c

File tree

5 files changed

+102
-18
lines changed

5 files changed

+102
-18
lines changed

administrator/modules/mod_version/mod_version.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

administrator/modules/mod_version/mod_version.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<description>MOD_VERSION_XML_DESCRIPTION</description>
1212
<namespace path="src">Joomla\Module\Version</namespace>
1313
<files>
14-
<filename module="mod_version">mod_version.php</filename>
14+
<folder module="mod_version">services</folder>
1515
<folder>src</folder>
1616
<folder>tmpl</folder>
1717
</files>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage mod_version
6+
*
7+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
\defined('_JEXEC') or die;
12+
13+
use Joomla\CMS\Extension\Service\Provider\HelperFactory;
14+
use Joomla\CMS\Extension\Service\Provider\Module;
15+
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
16+
use Joomla\DI\Container;
17+
use Joomla\DI\ServiceProviderInterface;
18+
19+
return new class () implements ServiceProviderInterface {
20+
/**
21+
* Registers the service provider with a DI container.
22+
*
23+
* @param Container $container The DI container.
24+
*
25+
* @return void
26+
*
27+
* @since __DEPLOY_VERSION__
28+
*/
29+
public function register(Container $container)
30+
{
31+
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Version'));
32+
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Version\\Administrator\\Helper'));
33+
34+
$container->registerServiceProvider(new Module());
35+
}
36+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage mod_version
6+
*
7+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Module\Version\Administrator\Dispatcher;
12+
13+
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
14+
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
15+
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
16+
17+
// phpcs:disable PSR1.Files.SideEffects
18+
\defined('_JEXEC') or die;
19+
// phpcs:enable PSR1.Files.SideEffects
20+
21+
/**
22+
* Dispatcher class for mod_version
23+
*
24+
* @since __DEPLOY_VERSION__
25+
*/
26+
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
27+
{
28+
use HelperFactoryAwareTrait;
29+
30+
/**
31+
* Returns the layout data.
32+
*
33+
* @return array
34+
*
35+
* @since __DEPLOY_VERSION__
36+
*/
37+
protected function getLayoutData()
38+
{
39+
$data = parent::getLayoutData();
40+
41+
$data['version'] = $this->getHelperFactory()->getHelper('VersionHelper')->getVersionString();
42+
43+
return $data;
44+
}
45+
}

administrator/modules/mod_version/src/Helper/VersionHelper.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,35 @@
2121
*
2222
* @since 1.6
2323
*/
24-
abstract class VersionHelper
24+
class VersionHelper
2525
{
2626
/**
2727
* Get the Joomla version number.
2828
*
2929
* @return string String containing the current Joomla version.
30+
*
31+
* @since __DEPLOY_VERSION__
3032
*/
31-
public static function getVersion()
33+
public function getVersionString()
3234
{
3335
$version = new Version();
3436

3537
return '&#x200E;' . $version->getShortVersion();
3638
}
39+
40+
/**
41+
* Get the Joomla version number.
42+
*
43+
* @return string String containing the current Joomla version.
44+
*
45+
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
46+
* Use the non-static method getVersionString
47+
* Example: Factory::getApplication()->bootModule('mod_version', 'administrator')
48+
* ->getHelper('VersionHelper')
49+
* ->getVersionString()
50+
*/
51+
public static function getVersion()
52+
{
53+
return (new self())->getVersionString();
54+
}
3755
}

0 commit comments

Comments
 (0)