104 lines
3.0 KiB
PHP
104 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* @package Kumwe CMS
|
|
*
|
|
* @created 9th April 2022
|
|
* @author Llewellyn van der Merwe <https://git.vdm.dev/Llewellyn>
|
|
* @git Kumwe CMS <https://git.vdm.dev/Kumwe/cms>
|
|
* @license GNU General Public License version 2; see LICENSE.txt
|
|
*/
|
|
|
|
namespace Kumwe\CMS\Service;
|
|
|
|
use Joomla\Application\AbstractWebApplication;
|
|
use Joomla\Application\Controller\ControllerResolverInterface;
|
|
use Joomla\Application\Web\WebClient;
|
|
use Joomla\DI\Container;
|
|
use Joomla\DI\ServiceProviderInterface;
|
|
use Joomla\Event\DispatcherInterface;
|
|
|
|
use Joomla\Session\SessionInterface;
|
|
use Kumwe\CMS\User\UserFactoryInterface;
|
|
use Kumwe\CMS\Application\AdminApplication;
|
|
|
|
use Joomla\Input\Input;
|
|
use Joomla\Router\RouterInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
/**
|
|
* Admin Application service provider
|
|
* source: https://github.com/joomla/framework.joomla.org/blob/master/src/Service/ApplicationProvider.php
|
|
*/
|
|
class AdminApplicationProvider implements ServiceProviderInterface
|
|
{
|
|
/**
|
|
* Registers the service provider with a DI container.
|
|
*
|
|
* @param Container $container The DI container.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register(Container $container): void
|
|
{
|
|
/*
|
|
* Application Classes
|
|
*/
|
|
|
|
// This service cannot be protected as it is decorated when the debug bar is available
|
|
$container->alias(AdminApplication::class, AbstractWebApplication::class)
|
|
->share(AbstractWebApplication::class, [$this, 'getAdminApplicationClassService']);
|
|
|
|
/*
|
|
* Application Helpers and Dependencies
|
|
*/
|
|
$container->share(WebClient::class, [$this, 'getWebClientService'], true);
|
|
}
|
|
|
|
/**
|
|
* Get the WebApplication class service
|
|
*
|
|
* @param Container $container The DI container.
|
|
*
|
|
* @return AdminApplication
|
|
*/
|
|
public function getAdminApplicationClassService(Container $container): AdminApplication
|
|
{
|
|
/** @var \Kumwe\CMS\Application\AdminApplication $application */
|
|
$application = new AdminApplication(
|
|
$container->get(ControllerResolverInterface::class),
|
|
$container->get(RouterInterface::class),
|
|
$container->get(Input::class),
|
|
$container->get('config'),
|
|
$container->get(WebClient::class)
|
|
);
|
|
|
|
$application->httpVersion = '2';
|
|
|
|
// Inject extra services
|
|
$application->setDispatcher($container->get(DispatcherInterface::class));
|
|
$application->setLogger($container->get(LoggerInterface::class));
|
|
$application->setSession($container->get(SessionInterface::class));
|
|
$application->setUserFactory($container->get(UserFactoryInterface::class));
|
|
|
|
return $application;
|
|
}
|
|
|
|
/**
|
|
* Get the web client service
|
|
*
|
|
* @param Container $container The DI container.
|
|
*
|
|
* @return WebClient
|
|
*/
|
|
public function getWebClientService(Container $container): WebClient
|
|
{
|
|
/** @var Input $input */
|
|
$input = $container->get(Input::class);
|
|
$userAgent = $input->server->getString('HTTP_USER_AGENT', '');
|
|
$acceptEncoding = $input->server->getString('HTTP_ACCEPT_ENCODING', '');
|
|
$acceptLanguage = $input->server->getString('HTTP_ACCEPT_LANGUAGE', '');
|
|
|
|
return new WebClient($userAgent, $acceptEncoding, $acceptLanguage);
|
|
}
|
|
}
|