Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ExportStep.php
1<?php
2
4
5use \Bitrix\Main;
6
7
8abstract class ExportStep {
9 //region input info
10 public string $entityCode;
11 public $entityId;
13 public int $stepNumber;
14 //end region
15 //region OutputInfo
20 //endregion
21 public function __construct(Main\Event $event)
22 {
23 $this->entityCode = $event->getParameter('CODE');
24 $this->entityId = $event->getParameter('ITEM_CODE');
25 $this->stepNumber = (int) $event->getParameter('STEP');
26 $data = json_decode($event->getParameter('NEXT') ?: '', true);
27 $this->previousStep = new Main\Type\Dictionary(($data ?: []));
28
29 $this->data = new Main\Type\Dictionary();
30 $this->files = new Main\Type\Dictionary();
31 $this->nextStep = new Main\Type\Dictionary();
32 $this->errorCollection = new Main\ErrorCollection();
33
34 $this->init();
35 }
36
37 abstract public function init(): void;
38
39 public function makeAnAnswer(): ?array
40 {
41 return [
42 'FILE_NAME' =>
43 implode('_',
44 [
45 (new \ReflectionClass(static::class))->getShortName(),
46 $this->entityCode,
47 $this->entityId,
48 $this->stepNumber
49 ]
50 ),
51 'CONTENT' => $this->data->toArray(),
52 'FILES' => $this->files->toArray(),
53 'NEXT' => $this->nextStep->count() <= 0
54 ? false : json_encode($this->nextStep->toArray()),
55
56 ] + (($error = $this->errorCollection->current()) ? [
57 'ERROR_MESSAGE' => $error->getMessage(),
58 'ERROR_ACTION' => $error->getCode(),
59 ] : []);
60 }
61
62 public static function fulfill(Main\Event $event): array
63 {
64 $step = new static($event);
65 return $step->makeAnAnswer();
66 }
67}
static fulfill(Main\Event $event)
Main ErrorCollection $errorCollection