106 lines
2.2 KiB
PHP
106 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace KupShop\ComponentsBundle\Actions\Frontend;
|
|
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
use KupShop\OrderDiscountBundle\Actions\Frontend\HandlerInterface;
|
|
use KupShop\OrderDiscountBundle\Entity\OrderDiscount;
|
|
use Twig\Environment;
|
|
|
|
abstract class AbstractHandler implements HandlerInterface
|
|
{
|
|
protected $actionId;
|
|
/** @var OrderDiscount */
|
|
protected $orderDiscount;
|
|
|
|
protected $actionData;
|
|
protected $data = [];
|
|
|
|
protected string $component;
|
|
public string $templateSize;
|
|
|
|
public function __construct(
|
|
protected ?Environment $twig,
|
|
) {
|
|
}
|
|
|
|
public function getActionId()
|
|
{
|
|
return $this->actionId;
|
|
}
|
|
|
|
public function setActionId($actionId): self
|
|
{
|
|
$this->actionId = $actionId;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setOrderDiscount(OrderDiscount $orderDiscount): self
|
|
{
|
|
$this->orderDiscount = $orderDiscount;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getOrderDiscount(): OrderDiscount
|
|
{
|
|
return $this->orderDiscount;
|
|
}
|
|
|
|
public function setActionData(array $actionData): self
|
|
{
|
|
$this->actionData = $actionData;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function handleData($data): array
|
|
{
|
|
$this->data = $data;
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function getData()
|
|
{
|
|
return $this->data;
|
|
}
|
|
|
|
public function getVars(): array
|
|
{
|
|
return [
|
|
'actionId' => $this->actionId,
|
|
'name' => 'action_handler['.$this->actionId.']',
|
|
'title' => $this->orderDiscount->getDisplayName(),
|
|
'frontend_data' => $this->getData(),
|
|
'data' => $this->actionData,
|
|
];
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return $this->twig->render('@Components/components/component.html.twig', [
|
|
'name' => $this->component,
|
|
'data' => ['handler' => $this],
|
|
]);
|
|
}
|
|
|
|
public function __wakeup()
|
|
{
|
|
$this->twig = ServiceContainer::getService(Environment::class);
|
|
}
|
|
|
|
public function __sleep()
|
|
{
|
|
$vars = array_keys(get_object_vars($this));
|
|
|
|
return array_diff($vars, ['twig']);
|
|
}
|
|
|
|
public function getActionData(): array
|
|
{
|
|
return $this->actionData;
|
|
}
|
|
}
|