Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
component.php
1<?php
3
5{
6 private $componentName = null;
7 private $componentTemplate = null;
8 private $componentParams = [];
9 private $componentResult = [];
10
12 private $dataKeys = [];
13 private $parentComponent = null;
14 private $functionParams = [];
15
24 public function __construct($componentName, $componentTemplate = '', array $componentParams = [], $dataKeys = [])
25 {
26 $this->componentName = $componentName;
27 $this->componentTemplate = $componentTemplate;
28 $this->dataKeys = $dataKeys;
29 $this->setParameters($componentParams);
30 }
31
37 public function setParameters(array $params)
38 {
39 $this->componentParams = $params;
40
41 return $this;
42 }
43
49 public function setParentComponent($parentComponent)
50 {
51 $this->parentComponent = $parentComponent;
52
53 return $this;
54 }
55
61 public function setFunctionParameters(array $functionParams)
62 {
63 $this->functionParams = $functionParams;
64
65 return $this;
66 }
67
71 public function getHtml()
72 {
73 global $APPLICATION;
74
75 ob_start();
76 $this->componentResult = $APPLICATION->IncludeComponent(
77 $this->componentName,
78 $this->componentTemplate,
79 $this->componentParams,
80 $this->parentComponent,
81 $this->functionParams,
82 !empty($this->dataKeys) // returnResult
83 );
84
85 return ob_get_clean();
86 }
87
91 public function getSectionName(): string
92 {
93 return 'componentResult';
94 }
95
99 public function getSectionData()
100 {
101 $result = [];
102
103 if (
104 is_array($this->dataKeys)
105 && !empty($this->dataKeys)
106 )
107 {
108 $result = array_intersect_key($this->componentResult, array_combine($this->dataKeys, $this->dataKeys));
109 }
110 elseif (is_callable($this->dataKeys))
111 {
112 $result = call_user_func_array($this->dataKeys, [ $this->componentResult ]);
113 }
114
115 return $result;
116 }
117}
__construct($componentName, $componentTemplate='', array $componentParams=[], $dataKeys=[])
Definition component.php:24