Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basiccomponent.php
1<?php
2
3
5
6
8
9abstract class BasicComponent
10{
11 private $attachProperties = [];
12
13 private $attachSubComponent = [];
14
15 abstract public function getType() : string;
16
17 abstract public function getProperties(): array;
18
19 public function accessContent(): Content
20 {
21 $content = $this->setContent();
22
23 foreach ($this->attachProperties as $attachProperty)
24 {
25 $content->property($attachProperty);
26 }
27
28 $content->subComponent(...$this->attachSubComponent);
29
30 return $content;
31 }
32
33 public function toString(): string
34 {
35 $load = $this->accessContent();
36
37 $this->hasRequiredProperties($load);
38
39 $builder = new ComponentCreator($load);
40
41 return $builder->build();
42 }
43
44 public function appendProperty(PropertyType $property): BasicComponent
45 {
46 $this->attachProperties[] = $property;
47
48 return $this;
49 }
50
52 {
53 $this->attachSubComponent[] = $component;
54
55 return $this;
56 }
57
58 protected function hasRequiredProperties(Content $componentLoad)
59 {
60 $providedProperties = [];
61
62 foreach ($componentLoad->getProperties() as $property) {
63 $providedProperties = array_merge(
64 $providedProperties,
65 $property->getNames()
66 );
67 }
68
69 $requiredProperties = $this->getProperties();
70
71 $sameItems = array_intersect($requiredProperties, $providedProperties);
72
73 if (count($sameItems) !== count($requiredProperties)) {
74 $missingProperties = array_diff($requiredProperties, $sameItems);
75
76 throw InvalidComponent::requiredPropertyMissing($missingProperties, $this);
77 }
78 }
79}
hasRequiredProperties(Content $componentLoad)
appendSubComponent(BasicComponent $component)