vendor/shopware/core/Content/Flow/Dispatching/StorableFlow.php line 66

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Flow\Dispatching;
  3. use Shopware\Core\Content\Flow\FlowException;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Event\FlowEvent;
  6. use Shopware\Core\Framework\Event\FlowEventAware;
  7. use Shopware\Core\Framework\Feature;
  8. /**
  9.  * @internal
  10.  */
  11. class StorableFlow
  12. {
  13.     protected ?FlowState $state null;
  14.     /**
  15.      * @var array<string, mixed>
  16.      */
  17.     protected array $config = [];
  18.     protected string $name;
  19.     protected Context $context;
  20.     /**
  21.      * @var array<string, mixed>
  22.      */
  23.     protected array $store = [];
  24.     /**
  25.      * @var array<string, mixed>
  26.      */
  27.     protected array $data = [];
  28.     /**
  29.      * @deprecated tag:v6.5.0 Will be removed
  30.      */
  31.     private ?FlowEventAware $originalEvent null;
  32.     /**
  33.      * @deprecated tag:v6.5.0 Will be removed
  34.      */
  35.     private ?FlowEvent $flowEvent null;
  36.     /**
  37.      * @param array<string, mixed> $store
  38.      * @param array<string, mixed> $data
  39.      */
  40.     public function __construct(
  41.         string $name,
  42.         Context $context,
  43.         array $store = [],
  44.         array $data = []
  45.     ) {
  46.         $this->name $name;
  47.         $this->context $context;
  48.         $this->data $data;
  49.         $this->store $store;
  50.     }
  51.     /**
  52.      * @deprecated tag:v6.5.0 Will be removed
  53.      */
  54.     public function setOriginalEvent(FlowEventAware $event): void
  55.     {
  56.         Feature::triggerDeprecationOrThrow(
  57.             'v6.5.0.0',
  58.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0')
  59.         );
  60.         $this->originalEvent $event;
  61.     }
  62.     /**
  63.      * @deprecated tag:v6.5.0 Will be removed
  64.      */
  65.     public function getOriginalEvent(): ?FlowEventAware
  66.     {
  67.         Feature::triggerDeprecationOrThrow(
  68.             'v6.5.0.0',
  69.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0')
  70.         );
  71.         return $this->originalEvent;
  72.     }
  73.     /**
  74.      * @deprecated tag:v6.5.0 Will be removed
  75.      */
  76.     public function setFlowEvent(FlowEvent $event): void
  77.     {
  78.         Feature::triggerDeprecationOrThrow(
  79.             'v6.5.0.0',
  80.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0')
  81.         );
  82.         $this->flowEvent $event;
  83.     }
  84.     /**
  85.      * @deprecated tag:v6.5.0 Will be removed
  86.      */
  87.     public function getFlowEvent(): ?FlowEvent
  88.     {
  89.         Feature::triggerDeprecationOrThrow(
  90.             'v6.5.0.0',
  91.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0')
  92.         );
  93.         return $this->flowEvent;
  94.     }
  95.     public function getName(): string
  96.     {
  97.         return $this->name;
  98.     }
  99.     public function getContext(): Context
  100.     {
  101.         return $this->context;
  102.     }
  103.     /**
  104.      * @param mixed $value
  105.      */
  106.     public function setStore(string $key$value): void
  107.     {
  108.         $this->store[$key] = $value;
  109.     }
  110.     public function hasStore(string $key): bool
  111.     {
  112.         return \array_key_exists($key$this->store);
  113.     }
  114.     /**
  115.      * @param mixed $default
  116.      *
  117.      * @return mixed
  118.      */
  119.     public function getStore(string $key$default null)
  120.     {
  121.         return $this->store[$key] ?? $default;
  122.     }
  123.     /**
  124.      * @return array<string, mixed>
  125.      */
  126.     public function stored(): array
  127.     {
  128.         return $this->store;
  129.     }
  130.     /**
  131.      * @param mixed $value
  132.      */
  133.     public function setData(string $key$value): void
  134.     {
  135.         $this->data[$key] = $value;
  136.     }
  137.     public function hasData(string $key): bool
  138.     {
  139.         return \array_key_exists($key$this->data);
  140.     }
  141.     /**
  142.      * @param mixed $default
  143.      *
  144.      * @return mixed
  145.      */
  146.     public function getData(string $key$default null)
  147.     {
  148.         $value $this->data[$key] ?? $default;
  149.         if (\is_callable($value)) {
  150.             $this->data[$key] = $value($this);
  151.         }
  152.         return $this->data[$key] ?? $default;
  153.     }
  154.     /**
  155.      * @return array<string, mixed>
  156.      */
  157.     public function data(): array
  158.     {
  159.         foreach ($this->data as $key => $data) {
  160.             $this->getData($key);
  161.         }
  162.         return $this->data;
  163.     }
  164.     /**
  165.      * @param array<int, mixed> $args
  166.      */
  167.     public function lazy(string $key, callable $closure, array $args): void
  168.     {
  169.         $this->data[$key] = $closure($args);
  170.     }
  171.     /**
  172.      * @param array<string, mixed> $config
  173.      */
  174.     public function setConfig(array $config): void
  175.     {
  176.         $this->config $config;
  177.     }
  178.     /**
  179.      * @return array<string, mixed>
  180.      */
  181.     public function getConfig(): array
  182.     {
  183.         return $this->config;
  184.     }
  185.     public function setFlowState(FlowState $state): void
  186.     {
  187.         $this->state $state;
  188.     }
  189.     public function getFlowState(): FlowState
  190.     {
  191.         if (!$this->state) {
  192.             throw FlowException::methodNotCompatible('getFlowState()'self::class);
  193.         }
  194.         return $this->state;
  195.     }
  196.     public function stop(): void
  197.     {
  198.         if (!$this->state) {
  199.             throw FlowException::methodNotCompatible('stop()'self::class);
  200.         }
  201.         $this->state->stop true;
  202.     }
  203. }