Skip to content

Commit 0828bc8

Browse files
laoneowilsonge
authored andcommitted
[4.0] Change com_cpanel to services (#21419)
* Change com_cpanel to services * dispatcher
1 parent 72bb7d8 commit 0828bc8

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

administrator/components/com_cpanel/dispatcher.php renamed to administrator/components/com_cpanel/Dispatcher/Dispatcher.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,29 @@
77
* @license GNU General Public License version 2 or later; see LICENSE.txt
88
*/
99

10+
namespace Joomla\Component\Cpanel\Administrator\Dispatcher;
11+
1012
defined('_JEXEC') or die;
1113

12-
use Joomla\CMS\Dispatcher\Dispatcher;
14+
use Joomla\CMS\Access\Exception\Notallowed;
1315

1416
/**
1517
* Dispatcher class for com_cpanel
1618
*
1719
* @since 4.0.0
1820
*/
19-
class CpanelDispatcher extends Dispatcher
21+
class Dispatcher extends \Joomla\CMS\Dispatcher\Dispatcher
2022
{
2123
/**
22-
* The extension namespace
24+
* Method to check component access permission
2325
*
24-
* @var string
25-
*
26-
* @since 4.0.0
27-
*/
28-
protected $namespace = 'Joomla\\Component\\Cpanel';
29-
30-
/**
31-
* com_cpanel does not require check permission, so we override checkAccess method and have it empty
26+
* @since 4.0.0
3227
*
3328
* @return void
29+
*
30+
* @throws \Exception|Notallowed
3431
*/
3532
protected function checkAccess()
3633
{
37-
3834
}
3935
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* @package Joomla.Administrator
4+
* @subpackage com_cpanel
5+
*
6+
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
defined('_JEXEC') or die;
11+
12+
use Joomla\CMS\Dispatcher\DispatcherFactoryInterface;
13+
use Joomla\CMS\Extension\ComponentInterface;
14+
use Joomla\CMS\Extension\MVCComponent;
15+
use Joomla\CMS\Extension\Service\Provider\DispatcherFactory;
16+
use Joomla\CMS\Extension\Service\Provider\MVCFactoryFactory;
17+
use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface;
18+
use Joomla\DI\Container;
19+
use Joomla\DI\ServiceProviderInterface;
20+
21+
/**
22+
* The cpanel service provider.
23+
*
24+
* @since 4.0.0
25+
*/
26+
return new class implements ServiceProviderInterface
27+
{
28+
/**
29+
* Registers the service provider with a DI container.
30+
*
31+
* @param Container $container The DI container.
32+
*
33+
* @return void
34+
*
35+
* @since 4.0.0
36+
*/
37+
public function register(Container $container)
38+
{
39+
$container->registerServiceProvider(new MVCFactoryFactory('\\Joomla\\Component\\Cpanel'));
40+
$container->registerServiceProvider(new DispatcherFactory('\\Joomla\\Component\\Cpanel'));
41+
42+
$container->set(
43+
ComponentInterface::class,
44+
function (Container $container)
45+
{
46+
$component = new MVCComponent($container->get(DispatcherFactoryInterface::class));
47+
48+
$component->setMvcFactoryFactory($container->get(MVCFactoryFactoryInterface::class));
49+
50+
return $component;
51+
}
52+
);
53+
}
54+
};

0 commit comments

Comments
 (0)