1 | <?php |
||
29 | class CollectionAdapter extends AbstractAdapter |
||
30 | { |
||
31 | private $metaCompiler; |
||
32 | private $variable = null; |
||
33 | private $field = null; |
||
34 | private $entries = []; |
||
35 | |||
36 | public function __construct(ParserFactory $parserFactory, MetaCompiler $metaCompiler) { |
||
41 | |||
42 | public function transformPage(Page $page, $filter = null) : array { |
||
43 | $this->loadConfig($page); |
||
44 | $result = []; |
||
45 | |||
46 | while ($entry = current($this->entries)) { |
||
47 | if (isset($entry[$this->field]) && (!$filter || $entry[$this->field] === $filter)) { |
||
48 | $entryPage = $this->createEntryPage($page, $entry); |
||
49 | $result[$entryPage->getId()] = $entryPage; |
||
50 | } |
||
51 | |||
52 | next($this->entries); |
||
53 | } |
||
54 | return $result; |
||
55 | } |
||
56 | |||
57 | private function createEntryPage(Page $page, array $entry) : Page { |
||
58 | $url = str_replace('{' . $this->field . '}', $entry[$this->field], $page->getId()); |
||
59 | $entryPage = Page::copy($page); |
||
60 | $entryPageMeta = $entryPage->getMeta(); |
||
61 | $this->metaCompiler->setDefaultMeta($entryPageMeta); |
||
62 | |||
63 | foreach ($entry as $entryVariableName => $entryVariableValue) { |
||
64 | $this->metaCompiler->compilePageVariable($entryPage, $entryVariableName, $entryVariableValue); |
||
65 | } |
||
66 | |||
67 | $entryPage |
||
68 | ->removeAdapter(AdapterFactory::COLLECTION_ADAPTER) |
||
69 | ->setVariableValue($this->variable, $entry) |
||
70 | ->setVariableIsParsed($this->variable) |
||
71 | ->setId($url); |
||
72 | |||
73 | $this->parseBrowseData($entryPage); |
||
74 | |||
75 | return $entryPage; |
||
76 | } |
||
77 | |||
78 | private function parseBrowseData(Page $entryPage) { |
||
100 | |||
101 | protected function loadConfig(Page $page) { |
||
123 | } |
||
124 |