2022-04-09 10:01:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2022-04-12 19:41:51 +00:00
|
|
|
* @package Octoleo CMS
|
2022-04-09 10:01:42 +00:00
|
|
|
*
|
2022-04-12 19:41:51 +00:00
|
|
|
* @created 9th April 2022
|
|
|
|
* @author Llewellyn van der Merwe <https://git.vdm.dev/Llewellyn>
|
|
|
|
* @git WEBD-325-45 <https://git.vdm.dev/Llewellyn/WEBD-325-45>
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
2022-04-09 10:01:42 +00:00
|
|
|
*/
|
|
|
|
|
2022-04-12 19:41:51 +00:00
|
|
|
namespace Octoleo\CMS\Service;
|
2022-04-09 10:01:42 +00:00
|
|
|
|
|
|
|
use Joomla\Application\AbstractWebApplication;
|
|
|
|
use Joomla\Application\Controller\ContainerControllerResolver;
|
|
|
|
use Joomla\Application\Controller\ControllerResolverInterface;
|
|
|
|
use Joomla\Application\Web\WebClient;
|
|
|
|
use Joomla\Database\DatabaseInterface;
|
|
|
|
use Joomla\DI\Container;
|
|
|
|
use Joomla\DI\ServiceProviderInterface;
|
|
|
|
use Joomla\Event\DispatcherInterface;
|
2022-04-12 19:41:51 +00:00
|
|
|
|
|
|
|
use Joomla\Session\SessionInterface;
|
|
|
|
use Octoleo\CMS\Controller\DashboardController;
|
|
|
|
use Octoleo\CMS\Controller\LoginController;
|
|
|
|
use Octoleo\CMS\Controller\WrongCmsController;
|
|
|
|
use Octoleo\CMS\Model\DashboardModel;
|
|
|
|
use Octoleo\CMS\User\UserFactoryInterface;
|
|
|
|
use Octoleo\CMS\View\Admin\DashboardHtmlView;
|
|
|
|
use Octoleo\CMS\Application\AdminApplication;
|
|
|
|
|
2022-04-09 10:01:42 +00:00
|
|
|
use Joomla\Input\Input;
|
|
|
|
use Joomla\Renderer\RendererInterface;
|
|
|
|
use Joomla\Router\Router;
|
|
|
|
use Joomla\Router\RouterInterface;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Application service provider
|
2022-04-12 19:41:51 +00:00
|
|
|
* source: https://github.com/joomla/framework.joomla.org/blob/master/src/Service/ApplicationProvider.php
|
2022-04-09 10:01:42 +00:00
|
|
|
*/
|
2022-04-12 19:41:51 +00:00
|
|
|
class AdminApplicationProvider implements ServiceProviderInterface
|
2022-04-09 10:01:42 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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
|
2022-04-12 19:41:51 +00:00
|
|
|
$container->alias(AdminApplication::class, AbstractWebApplication::class)
|
|
|
|
->share(AbstractWebApplication::class, [$this, 'getAdminApplicationClassService']);
|
2022-04-09 10:01:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Application Helpers and Dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This service cannot be protected as it is decorated when the debug bar is available
|
|
|
|
$container->alias(ContainerControllerResolver::class, ControllerResolverInterface::class)
|
|
|
|
->share(ControllerResolverInterface::class, [$this, 'getControllerResolverService']);
|
|
|
|
|
|
|
|
$container->share(WebClient::class, [$this, 'getWebClientService'], true);
|
|
|
|
|
|
|
|
// This service cannot be protected as it is decorated when the debug bar is available
|
|
|
|
$container->alias(RouterInterface::class, 'application.router')
|
|
|
|
->alias(Router::class, 'application.router')
|
|
|
|
->share('application.router', [$this, 'getApplicationRouterService']);
|
|
|
|
|
|
|
|
$container->share(Input::class, [$this, 'getInputClassService'], true);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MVC Layer
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Controllers
|
2022-04-12 19:41:51 +00:00
|
|
|
$container->alias(DashboardController::class, 'controller.dashboard')
|
|
|
|
->share('controller.dashboard', [$this, 'getControllerDashboardService'], true);
|
2022-04-09 10:01:42 +00:00
|
|
|
|
2022-04-12 19:41:51 +00:00
|
|
|
$container->alias(LoginController::class, 'controller.login')
|
|
|
|
->share('controller.login', [$this, 'getControllerLoginService'], true);
|
2022-04-09 10:01:42 +00:00
|
|
|
|
|
|
|
$container->alias(WrongCmsController::class, 'controller.wrong.cms')
|
|
|
|
->share('controller.wrong.cms', [$this, 'getControllerWrongCmsService'], true);
|
|
|
|
|
|
|
|
// Models
|
2022-04-12 19:41:51 +00:00
|
|
|
$container->alias(DashboardModel::class, 'model.dashboard')
|
|
|
|
->share('model.dashboard', [$this, 'getModelDashboardService'], true);
|
2022-04-09 10:01:42 +00:00
|
|
|
|
|
|
|
// Views
|
2022-04-12 19:41:51 +00:00
|
|
|
$container->alias(DashboardHtmlView::class, 'view.dashboard.html')
|
|
|
|
->share('view.dashboard.html', [$this, 'getViewDashboardHtmlService'], true);
|
2022-04-09 10:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the `application.router` service
|
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
|
|
|
* @return RouterInterface
|
|
|
|
*/
|
|
|
|
public function getApplicationRouterService(Container $container): RouterInterface
|
|
|
|
{
|
|
|
|
$router = new Router;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CMS Admin Panels
|
|
|
|
*/
|
2022-04-12 19:41:51 +00:00
|
|
|
$router->all(
|
|
|
|
'/index.php?dashboard=*',
|
|
|
|
DashboardController::class
|
2022-04-09 10:01:42 +00:00
|
|
|
);
|
|
|
|
$router->get(
|
2022-04-12 19:41:51 +00:00
|
|
|
'/*',
|
|
|
|
LoginController::class
|
2022-04-09 10:01:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return $router;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-12 19:41:51 +00:00
|
|
|
* Get the `controller.login` service
|
2022-04-09 10:01:42 +00:00
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
2022-04-12 19:41:51 +00:00
|
|
|
* @return LoginController
|
2022-04-09 10:01:42 +00:00
|
|
|
*/
|
2022-04-12 19:41:51 +00:00
|
|
|
public function getControllerLoginService(Container $container): LoginController
|
2022-04-09 10:01:42 +00:00
|
|
|
{
|
2022-04-12 19:41:51 +00:00
|
|
|
return new LoginController(
|
2022-04-09 10:01:42 +00:00
|
|
|
$container->get(RendererInterface::class),
|
|
|
|
$container->get(Input::class),
|
2022-04-12 19:41:51 +00:00
|
|
|
$container->get(AdminApplication::class)
|
2022-04-09 10:01:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-12 19:41:51 +00:00
|
|
|
* Get the `controller.dashboard` service
|
2022-04-09 10:01:42 +00:00
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
2022-04-12 19:41:51 +00:00
|
|
|
* @return DashboardController
|
2022-04-09 10:01:42 +00:00
|
|
|
*/
|
2022-04-12 19:41:51 +00:00
|
|
|
public function getControllerDashboardService(Container $container): DashboardController
|
2022-04-09 10:01:42 +00:00
|
|
|
{
|
2022-04-12 19:41:51 +00:00
|
|
|
return new DashboardController(
|
|
|
|
$container->get(DashboardHtmlView::class),
|
2022-04-09 10:01:42 +00:00
|
|
|
$container->get(Input::class),
|
2022-04-12 19:41:51 +00:00
|
|
|
$container->get(AdminApplication::class)
|
2022-04-09 10:01:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the `controller.wrong.cms` service
|
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
|
|
|
* @return WrongCmsController
|
|
|
|
*/
|
|
|
|
public function getControllerWrongCmsService(Container $container): WrongCmsController
|
|
|
|
{
|
|
|
|
return new WrongCmsController(
|
|
|
|
$container->get(Input::class),
|
2022-04-12 19:41:51 +00:00
|
|
|
$container->get(AdminApplication::class)
|
2022-04-09 10:01:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Input class service
|
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
|
|
|
* @return Input
|
|
|
|
*/
|
|
|
|
public function getInputClassService(Container $container): Input
|
|
|
|
{
|
|
|
|
return new Input($_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-12 19:41:51 +00:00
|
|
|
* Get the `model.dashboard` service
|
2022-04-09 10:01:42 +00:00
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
2022-04-12 19:41:51 +00:00
|
|
|
* @return DashboardModel
|
2022-04-09 10:01:42 +00:00
|
|
|
*/
|
2022-04-12 19:41:51 +00:00
|
|
|
public function getModelDashboardService(Container $container): DashboardModel
|
2022-04-09 10:01:42 +00:00
|
|
|
{
|
2022-04-12 19:41:51 +00:00
|
|
|
return new DashboardModel($container->get(DatabaseInterface::class));
|
2022-04-09 10:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-12 19:41:51 +00:00
|
|
|
* Get the WebApplication class service
|
2022-04-09 10:01:42 +00:00
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
2022-04-12 19:41:51 +00:00
|
|
|
* @return AdminApplication
|
2022-04-09 10:01:42 +00:00
|
|
|
*/
|
2022-04-12 19:41:51 +00:00
|
|
|
public function getAdminApplicationClassService(Container $container): AdminApplication
|
2022-04-09 10:01:42 +00:00
|
|
|
{
|
2022-04-12 19:41:51 +00:00
|
|
|
/** @var \Octoleo\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)
|
2022-04-09 10:01:42 +00:00
|
|
|
);
|
|
|
|
|
2022-04-12 19:41:51 +00:00
|
|
|
$application->httpVersion = '2';
|
2022-04-09 10:01:42 +00:00
|
|
|
|
2022-04-12 19:41:51 +00:00
|
|
|
// 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));
|
2022-04-09 10:01:42 +00:00
|
|
|
|
2022-04-12 19:41:51 +00:00
|
|
|
return $application;
|
2022-04-09 10:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-12 19:41:51 +00:00
|
|
|
* Get the controller resolver service
|
2022-04-09 10:01:42 +00:00
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
2022-04-12 19:41:51 +00:00
|
|
|
* @return ControllerResolverInterface
|
2022-04-09 10:01:42 +00:00
|
|
|
*/
|
2022-04-12 19:41:51 +00:00
|
|
|
public function getControllerResolverService(Container $container): ControllerResolverInterface
|
2022-04-09 10:01:42 +00:00
|
|
|
{
|
2022-04-12 19:41:51 +00:00
|
|
|
return new ContainerControllerResolver($container);
|
2022-04-09 10:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-12 19:41:51 +00:00
|
|
|
* Get the `view.page.html` service
|
2022-04-09 10:01:42 +00:00
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
2022-04-12 19:41:51 +00:00
|
|
|
* @return DashboardHtmlView
|
2022-04-09 10:01:42 +00:00
|
|
|
*/
|
2022-04-12 19:41:51 +00:00
|
|
|
public function getViewDashboardHtmlService(Container $container): DashboardHtmlView
|
2022-04-09 10:01:42 +00:00
|
|
|
{
|
2022-04-12 19:41:51 +00:00
|
|
|
return new DashboardHtmlView(
|
|
|
|
$container->get('model.dashboard'),
|
2022-04-09 10:01:42 +00:00
|
|
|
$container->get('renderer')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|