-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentBuilder.php
More file actions
54 lines (47 loc) · 1.59 KB
/
ContentBuilder.php
File metadata and controls
54 lines (47 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Kwc\ContentApiBundle\Services;
use Kwc_Abstract;
use Kwf_Component_Data;
class ContentBuilder
{
private $exportComponents;
public function setExportComponents(array $componentClasses)
{
$this->exportComponents = $componentClasses;
}
public function getContent(Kwf_Component_Data $data)
{
if (Kwc_Abstract::hasSetting($data->componentClass, 'apiContent') && in_array($data->componentClass, $this->exportComponents)) {
$cls = Kwc_Abstract::getSetting($data->componentClass, 'apiContent');
$apiContent = new $cls();
$ret = $apiContent->getContent($data);
if ($ret instanceof Kwf_Component_Data) {
$ret = $this->getContent($ret);
} else {
$ret['type'] = Kwc_Abstract::getSetting($data->componentClass, 'apiContentType');
}
$ret = $this->convertData($ret);
} else {
$ret = array();
$ret['html'] = $data->render();
$ret['type'] = 'legacyHtml';
}
$ret['hasContent'] = $data->hasContent();
return $ret;
}
private function convertData($data)
{
foreach ($data as $k=>$i) {
if (is_array($i)) {
$data[$k] = $this->convertData($i);
} else if ($i instanceof Kwf_Component_Data) {
$data[$k] = $this->getContent($i);
} else if (is_object($i)) {
$data[$k] = $this->convertData((array)$i);
} else {
$data[$k] = $i;
}
}
return $data;
}
}