Skip to content

Commit a759763

Browse files
authored
[5.1] Convert mod_stats_admin to service provider (#42886)
* Convert mod_stats_admin to service provider
1 parent 75fca46 commit a759763

File tree

5 files changed

+115
-25
lines changed

5 files changed

+115
-25
lines changed

administrator/modules/mod_stats_admin/mod_stats_admin.php

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

administrator/modules/mod_stats_admin/mod_stats_admin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<description>MOD_STATS_XML_DESCRIPTION</description>
1212
<namespace path="src">Joomla\Module\StatsAdmin</namespace>
1313
<files>
14-
<filename module="mod_stats_admin">mod_stats_admin.php</filename>
14+
<folder module="mod_stats_admin">services</folder>
1515
<folder>src</folder>
1616
<folder>tmpl</folder>
1717
</files>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage mod_stats_admin
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+
/**
20+
* The statistics administrator module service provider.
21+
*
22+
* @since __DEPLOY_VERSION__
23+
*/
24+
return new class () implements ServiceProviderInterface {
25+
/**
26+
* Registers the service provider with a DI container.
27+
*
28+
* @param Container $container The DI container.
29+
*
30+
* @return void
31+
*
32+
* @since __DEPLOY_VERSION__
33+
*/
34+
public function register(Container $container)
35+
{
36+
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\StatsAdmin'));
37+
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\StatsAdmin\\Administrator\\Helper'));
38+
39+
$container->registerServiceProvider(new Module());
40+
}
41+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage mod_stats_admin
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\StatsAdmin\Administrator\Dispatcher;
12+
13+
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
14+
use Joomla\CMS\Factory;
15+
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
16+
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
17+
use Joomla\Database\DatabaseInterface;
18+
19+
// phpcs:disable PSR1.Files.SideEffects
20+
\defined('_JEXEC') or die;
21+
// phpcs:enable PSR1.Files.SideEffects
22+
23+
/**
24+
* Dispatcher class for mod_stats_admin
25+
*
26+
* @since __DEPLOY_VERSION__
27+
*/
28+
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
29+
{
30+
use HelperFactoryAwareTrait;
31+
32+
/**
33+
* Returns the layout data.
34+
*
35+
* @return array
36+
*
37+
* @since __DEPLOY_VERSION__
38+
*/
39+
protected function getLayoutData()
40+
{
41+
$data = parent::getLayoutData();
42+
43+
$data['serverinfo'] = $data['params']->get('serverinfo');
44+
$data['siteinfo'] = $data['params']->get('siteinfo');
45+
$data['list'] = $this->getHelperFactory()->getHelper('StatsAdminHelper')->getStatsData($data['params'], $this->getApplication(), Factory::getContainer()->get(DatabaseInterface::class));
46+
47+
return $data;
48+
}
49+
}

administrator/modules/mod_stats_admin/src/Helper/StatsAdminHelper.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class StatsAdminHelper
3737
*
3838
* @return array Array containing site information
3939
*
40-
* @since 3.0
40+
* @since __DEPLOY_VERSION__
4141
*/
42-
public static function getStats(Registry $params, CMSApplication $app, DatabaseInterface $db)
42+
public function getStatsData(Registry $params, CMSApplication $app, DatabaseInterface $db)
4343
{
4444
$user = $app->getIdentity();
4545

@@ -144,4 +144,26 @@ public static function getStats(Registry $params, CMSApplication $app, DatabaseI
144144

145145
return $rows;
146146
}
147+
148+
/**
149+
* Method to retrieve information about the site
150+
*
151+
* @param Registry $params The module parameters
152+
* @param CMSApplication $app The application
153+
* @param DatabaseInterface $db The database
154+
*
155+
* @return array Array containing site information
156+
*
157+
* @since 3.0
158+
*
159+
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
160+
* Use the non-static method getStatsData
161+
* Example: Factory::getApplication()->bootModule('mod_stats_admin', 'administrator')
162+
* ->getHelper('StatsAdminHelper')
163+
* ->getStatsData($params, Factory::getApplication(), Factory::getContainer()->get(DatabaseInterface::class))
164+
*/
165+
public static function getStats(Registry $params, CMSApplication $app, DatabaseInterface $db)
166+
{
167+
return (new self())->getStatsData($params, $app, $db);
168+
}
147169
}

0 commit comments

Comments
 (0)