Skip to content

Commit c044810

Browse files
authored
Convert mod_stats to service provider (#42781)
1 parent dac4c55 commit c044810

File tree

5 files changed

+88
-22
lines changed

5 files changed

+88
-22
lines changed

modules/mod_stats/mod_stats.php

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

modules/mod_stats/mod_stats.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\Stats</namespace>
1313
<files>
14-
<filename module="mod_stats">mod_stats.php</filename>
14+
<folder module="mod_stats">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
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 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\\Stats'));
37+
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Stats\\Site\\Helper'));
38+
39+
$container->registerServiceProvider(new Module());
40+
}
41+
};
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.Site
5+
* @subpackage mod_stats
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\Stats\Site\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_stats
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['list'] = $this->getHelperFactory()->getHelper('StatsHelper')->getList($data['params']);
42+
43+
return $data;
44+
}
45+
}

modules/mod_stats/tmpl/default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @license GNU General Public License version 2 or later; see LICENSE.txt
99
*/
1010

11-
defined('_JEXEC') or die;
11+
\defined('_JEXEC') or die;
1212
?>
1313
<ul class="mod-stats list-group">
1414
<?php foreach ($list as $item) : ?>

0 commit comments

Comments
 (0)