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

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