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>
|
2022-04-09 10:01:42 +00:00
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2022-04-12 19:41:51 +00:00
|
|
|
namespace Octoleo\CMS\Service;
|
2022-04-09 10:01:42 +00:00
|
|
|
|
2022-04-12 19:41:51 +00:00
|
|
|
use Joomla\Authentication\AuthenticationStrategyInterface;
|
|
|
|
use Joomla\Authentication\Strategies\DatabaseStrategy;
|
|
|
|
use Joomla\Input\Input;
|
|
|
|
use Octoleo\CMS\User\UserFactory;
|
|
|
|
use Octoleo\CMS\User\UserFactoryInterface;
|
2022-04-09 10:01:42 +00:00
|
|
|
use Joomla\Database\DatabaseInterface;
|
|
|
|
use Joomla\DI\Container;
|
|
|
|
use Joomla\DI\ServiceProviderInterface;
|
|
|
|
|
|
|
|
/**
|
2022-04-12 19:41:51 +00:00
|
|
|
* Service provider for the user dependency
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
* source: https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/Service/Provider/User.php
|
|
|
|
*/
|
|
|
|
class UserProvider 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
|
|
|
|
*
|
|
|
|
* @since 4.0.0
|
|
|
|
*/
|
|
|
|
public function register(Container $container)
|
|
|
|
{
|
|
|
|
$container->alias('user.factory', UserFactoryInterface::class)
|
|
|
|
->alias(UserFactory::class, UserFactoryInterface::class)
|
2022-04-12 19:41:51 +00:00
|
|
|
->share(UserFactoryInterface::class, [$this, 'getUserFactoryService'], true);
|
|
|
|
|
|
|
|
$container->alias(DatabaseStrategy::class, AuthenticationStrategyInterface::class)
|
|
|
|
->share(AuthenticationStrategyInterface::class, [$this, 'getAuthenticationStrategyService'], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the UserFactoryInterface class service
|
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
|
|
|
* @return UserFactoryInterface
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function getUserFactoryService(Container $container): UserFactoryInterface
|
|
|
|
{
|
|
|
|
return new UserFactory(
|
|
|
|
$container->get(DatabaseInterface::class),
|
|
|
|
$container->get(AuthenticationStrategyInterface::class)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the AuthenticationStrategyInterface class service
|
|
|
|
*
|
|
|
|
* @param Container $container The DI container.
|
|
|
|
*
|
|
|
|
* @return AuthenticationStrategyInterface
|
|
|
|
*/
|
|
|
|
public function getAuthenticationStrategyService(Container $container): AuthenticationStrategyInterface
|
|
|
|
{
|
|
|
|
return new DatabaseStrategy(
|
|
|
|
$container->get(Input::class),
|
|
|
|
$container->get(DatabaseInterface::class)
|
|
|
|
);
|
2022-04-09 10:01:42 +00:00
|
|
|
}
|
|
|
|
}
|