src/Module/GetServicePriceOptionsHandler.php
<?php
namespace RebelCode\EddBookings\Services\Module;
use Dhii\Data\Container\ContainerGetCapableTrait;
use Dhii\Data\Container\CreateContainerExceptionCapableTrait;
use Dhii\Data\Container\CreateNotFoundExceptionCapableTrait;
use Dhii\Data\Container\NormalizeKeyCapableTrait;
use Dhii\Exception\CreateInvalidArgumentExceptionCapableTrait;
use Dhii\Exception\CreateOutOfRangeExceptionCapableTrait;
use Dhii\Exception\CreateRuntimeExceptionCapableTrait;
use Dhii\I18n\StringTranslatingTrait;
use Dhii\Invocation\InvocableInterface;
use Dhii\Iterator\CountIterableCapableTrait;
use Dhii\Iterator\ResolveIteratorCapableTrait;
use Dhii\Util\Normalization\NormalizeIntCapableTrait;
use Dhii\Util\Normalization\NormalizeStringCapableTrait;
use Psr\EventManager\EventInterface;
use RebelCode\Entity\GetCapableManagerInterface;
use RuntimeException;
/**
* The handler that filters the price options for an EDD Download, if it is a bookable service.
*
* @since [*next-version*]
*/
class GetServicePriceOptionsHandler implements InvocableInterface
{
/* @since [*next-version*] */
use GetEddServicePricesCapableTrait;
/* @since [*next-version*] */
use ContainerGetCapableTrait;
/* @since [*next-version*] */
use CountIterableCapableTrait;
/* @since [*next-version*] */
use ResolveIteratorCapableTrait;
/* @since [*next-version*] */
use NormalizeIntCapableTrait;
/* @since [*next-version*] */
use NormalizeKeyCapableTrait;
/* @since [*next-version*] */
use NormalizeStringCapableTrait;
/* @since [*next-version*] */
use CreateContainerExceptionCapableTrait;
/* @since [*next-version*] */
use CreateNotFoundExceptionCapableTrait;
/* @since [*next-version*] */
use CreateOutOfRangeExceptionCapableTrait;
/* @since [*next-version*] */
use CreateInvalidArgumentExceptionCapableTrait;
/* @since [*next-version*] */
use CreateRuntimeExceptionCapableTrait;
/* @since [*next-version*] */
use StringTranslatingTrait;
/**
* The services manager.
*
* @since [*next-version*]
*
* @var GetCapableManagerInterface
*/
protected $servicesManager;
/**
* Constructor.
*
* @since [*next-version*]
*
* @param GetCapableManagerInterface $servicesManager The services manager.
*/
public function __construct(GetCapableManagerInterface $servicesManager)
{
$this->servicesManager = $servicesManager;
}
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
protected function _getServicesManager()
{
return $this->servicesManager;
}
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
public function __invoke()
{
/* @var $event EventInterface */
$event = func_get_arg(0);
if (!($event instanceof EventInterface)) {
throw $this->_createInvalidArgumentException(
$this->__('Argument is not an event instance'), null, null, $event
);
}
$serviceId = $event->getParam(1);
try {
$priceOptions = $this->_getEddServicePrices($serviceId);
} catch (RuntimeException $exception) {
return;
}
$event->setParams([0 => $priceOptions] + $event->getParams());
}
}