Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ImportStep.php
1<?php
3
4use \Bitrix\Main;
5use \Bitrix\Rest;
6
7
8abstract class ImportStep {
9 //region input info
10 public string $entityCode;
14 //end region
15 //region OutputInfo
18 //endregion
19 public function __construct(Main\Event $event)
20 {
21 $this->entityCode = $event->getParameter('CODE');
22 $this->data = new Main\Type\Dictionary($event->getParameter('CONTENT')['DATA']);
23 $this->structure = new Rest\Configuration\Structure($event->getParameter('CONTEXT_USER'));
24
25 $this->previousStep = new Main\Type\Dictionary($event->getParameter('CONTENT')['RATIO']);
26 $this->nextStep = new Main\Type\Dictionary();
27 $this->errorCollection = new Main\ErrorCollection();
28
29 $this->init($event);
30 }
31
32 abstract public function init($event): void;
33
34 abstract public function makeAStep(): void;
35
36 public function makeAnAnswer(): ?array
37 {
38 return [
39 'RATIO' => $this->nextStep->toArray(),
40 ] + (($error = $this->errorCollection->current()) ? [
41 'ERROR_MESSAGE' => $error->getMessage(),
42 'ERROR_ACTION' => $error->getCode(),
43 ] : []);
44 }
45
46 public static function fulfill(Main\Event $event): array
47 {
48 $step = new static($event);
49 if ($step->errorCollection->isEmpty())
50 {
51 $step->makeAStep();
52 }
53 return $step->makeAnAnswer();
54 }
55}
static fulfill(Main\Event $event)
Main ErrorCollection $errorCollection
Rest Configuration Structure $structure