1 | <?php |
||
35 | class PageManager extends TrackingManager |
||
36 | { |
||
37 | /** @var StaticPageView[] A place to store a reference to static PageViews with titles. */ |
||
38 | private $staticPages; |
||
39 | private $configuration; |
||
40 | private $assetEngineManager; |
||
41 | private $collectionManager; |
||
42 | private $dataManager; |
||
43 | private $eventDispatcher; |
||
44 | private $logger; |
||
45 | |||
46 | /** |
||
47 | * PageManager constructor. |
||
48 | */ |
||
49 | 19 | public function __construct( |
|
50 | Configuration $configuration, |
||
51 | AssetEngineManager $assetEngineManager, |
||
52 | CollectionManager $collectionManager, |
||
53 | DataManager $dataManager, |
||
54 | EventDispatcherInterface $eventDispatcher, |
||
55 | LoggerInterface $logger |
||
56 | ) { |
||
57 | 19 | $this->trackedItems = [ |
|
58 | 19 | BasePageView::STATIC_TYPE => [], |
|
59 | 19 | BasePageView::DYNAMIC_TYPE => [], |
|
60 | 19 | BasePageView::REPEATER_TYPE => [], |
|
61 | ]; |
||
62 | 19 | $this->staticPages = []; |
|
63 | 19 | $this->configuration = $configuration; |
|
64 | 19 | $this->assetEngineManager = $assetEngineManager; |
|
65 | 19 | $this->collectionManager = $collectionManager; |
|
66 | 19 | $this->dataManager = $dataManager; |
|
67 | 19 | $this->eventDispatcher = $eventDispatcher; |
|
68 | 19 | $this->logger = $logger; |
|
69 | 19 | } |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 7 | public function compileManager() |
|
75 | { |
||
76 | 7 | $this->parseAssetPageViews(); |
|
77 | 7 | $this->parsePageViews($this->configuration->getPageViewFolders()); |
|
78 | 6 | } |
|
79 | |||
80 | 7 | public function parseAssetPageViews() |
|
81 | { |
||
82 | /** |
||
83 | * @var string $folder |
||
84 | * @var AssetEngine $engine |
||
85 | */ |
||
86 | 7 | foreach ($this->assetEngineManager->getFoldersToWatch() as $folder => $engine) |
|
87 | { |
||
88 | $assetFolder = fs::absolutePath($folder); |
||
|
|||
89 | |||
90 | if (!fs::exists($assetFolder)) |
||
91 | { |
||
92 | continue; |
||
93 | } |
||
94 | |||
95 | $extensions = []; |
||
96 | |||
97 | foreach ($engine->getExtensions() as $extension) |
||
98 | { |
||
99 | $extensions[] = "/.{$extension}.twig$/"; |
||
100 | } |
||
101 | |||
102 | $explorer = FileExplorer::create($assetFolder, [], $extensions, FileExplorer::IGNORE_DIRECTORIES); |
||
103 | |||
104 | foreach ($explorer as $file) |
||
105 | { |
||
106 | $assetPageView = new StaticPageView($file); |
||
107 | $compiled = $engine->parse($assetPageView->getContent()); |
||
108 | $assetPageView->setContent($compiled); |
||
109 | |||
110 | $this->handleTrackableStaticPageView($assetPageView); |
||
111 | $this->addObjectToTracker($assetPageView, $assetPageView->getType()); |
||
112 | } |
||
113 | 7 | } |
|
114 | 7 | } |
|
115 | |||
116 | /** |
||
117 | * Go through all of the PageView directories and create a respective PageView for each and classify them by type. |
||
118 | * |
||
119 | * @param string[] $pageViewFolders |
||
120 | * |
||
121 | * @since 0.1.0 |
||
122 | */ |
||
123 | 19 | public function parsePageViews(array $pageViewFolders) |
|
124 | { |
||
125 | 19 | foreach ($pageViewFolders as $pageViewFolderName) |
|
126 | { |
||
127 | 19 | $pageViewFolderPath = fs::absolutePath($pageViewFolderName); |
|
128 | |||
129 | 19 | if (!fs::exists($pageViewFolderPath)) |
|
130 | 19 | { |
|
131 | 1 | $this->logger->warning("The '$pageViewFolderName' folder could not be found"); |
|
132 | 1 | continue; |
|
133 | } |
||
134 | |||
135 | 18 | $event = new PageViewDefinitionAdded($pageViewFolderName); |
|
136 | 18 | $this->eventDispatcher->dispatch(PageViewDefinitionAdded::NAME, $event); |
|
137 | |||
138 | 18 | $this->scanTrackableItems($pageViewFolderPath, [ |
|
139 | 18 | 'fileExplorer' => FileExplorer::INCLUDE_ONLY_FILES, |
|
140 | 18 | ], ['/.html$/', '/.twig$/']); |
|
141 | 18 | } |
|
142 | 18 | } |
|
143 | |||
144 | /** |
||
145 | * Get all of the PageViews in an associative array with PageView types as the keys. |
||
146 | * |
||
147 | * @since 0.1.1 |
||
148 | * |
||
149 | * @return BasePageView[][] |
||
150 | */ |
||
151 | public function &getPageViews() |
||
155 | |||
156 | /** |
||
157 | * Get all of the PageViews in flat array. |
||
158 | * |
||
159 | * @since 0.1.1 |
||
160 | * |
||
161 | * @return BasePageView[] |
||
162 | */ |
||
163 | 17 | public function &getPageViewsFlattened() |
|
167 | |||
168 | /** |
||
169 | * Get the static PageViews tracked by this manager indexed by their title. |
||
170 | * |
||
171 | * @since 0.1.0 |
||
172 | * |
||
173 | * @return StaticPageView[] |
||
174 | */ |
||
175 | 1 | public function getStaticPageViews() |
|
179 | |||
180 | /** |
||
181 | * Get the jailed version of the static PageViews indexed by their title. |
||
182 | * |
||
183 | * @since 0.1.0 |
||
184 | * |
||
185 | * @return JailedDocument[] |
||
186 | */ |
||
187 | 13 | public function getJailedStaticPageViews() |
|
198 | |||
199 | /** |
||
200 | * Add a new ContentItem to the respective parent PageView of the ContentItem. |
||
201 | * |
||
202 | * @param ContentItem $contentItem |
||
203 | * |
||
204 | * @since 0.1.0 |
||
205 | */ |
||
206 | 1 | public function trackNewContentItem(&$contentItem) |
|
211 | |||
212 | /** |
||
213 | * {@inheritdoc} |
||
214 | */ |
||
215 | 18 | protected function &handleTrackableItem(File $filePath, array $options = []) |
|
247 | |||
248 | /** |
||
249 | * Handle special behavior and treatment for static PageViews while we're iterating through them. |
||
250 | * |
||
251 | * @param StaticPageView $pageView |
||
252 | * |
||
253 | * @since 0.1.0 |
||
254 | */ |
||
255 | 11 | private function handleTrackableStaticPageView(&$pageView) |
|
268 | |||
269 | /** |
||
270 | * Handle special behavior and treatment for dynamic PageViews while we're iterating through them. |
||
271 | * |
||
272 | * @param DynamicPageView $pageView |
||
273 | * |
||
274 | * @since 0.1.0 |
||
275 | * |
||
276 | * @throws \Exception |
||
277 | */ |
||
278 | 4 | private function handleTrackableDynamicPageView(&$pageView) |
|
319 | |||
320 | /** |
||
321 | * Handle special behavior and treatment for repeater PageViews while we're iterating through them. |
||
322 | * |
||
323 | * @param RepeaterPageView $pageView |
||
324 | * |
||
325 | * @since 0.2.0 |
||
326 | */ |
||
327 | 3 | private function handleTrackableRepeaterPageView(&$pageView) |
|
334 | } |
||
335 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: