1 | <?php |
||
23 | class CollectionManager extends TrackingManager |
||
24 | { |
||
25 | /** @var string[][] A copy of the collection definitions to be available for later usage. */ |
||
26 | private $collectionDefinitions; |
||
27 | private $markupEngineManager; |
||
28 | private $configuration; |
||
29 | private $eventDispatcher; |
||
30 | private $logger; |
||
31 | |||
32 | /** |
||
33 | * CollectionManager constructor. |
||
34 | */ |
||
35 | 36 | public function __construct(MarkupEngineManager $markupEngineManager, Configuration $configuration, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger) |
|
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 6 | public function compileManager() |
|
47 | { |
||
48 | 6 | if (!$this->configuration->hasCollections()) |
|
49 | 6 | { |
|
50 | $this->logger->notice('No Collections defined... Ignoring'); |
||
51 | |||
52 | return; |
||
53 | } |
||
54 | |||
55 | 6 | $this->parseCollections($this->configuration->getCollectionsFolders()); |
|
56 | 6 | } |
|
57 | |||
58 | /** |
||
59 | * Get all of the ContentItems grouped by Collection name. |
||
60 | * |
||
61 | * ```php |
||
62 | * [ |
||
63 | * 'collection name' => [ |
||
64 | * new ContentItem(), |
||
65 | * new ContentItem(), |
||
66 | * ] |
||
67 | * ] |
||
68 | * ``` |
||
69 | * |
||
70 | * @return ContentItem[][] |
||
71 | */ |
||
72 | 15 | public function &getCollections() |
|
76 | |||
77 | /** |
||
78 | * Get a ContentItem from a Collection passed on it's path. |
||
79 | * |
||
80 | * @param string $filePath |
||
81 | * |
||
82 | * @throws TrackedItemNotFoundException |
||
83 | * |
||
84 | * @return ContentItem |
||
85 | */ |
||
86 | 1 | public function &getContentItem($filePath) |
|
87 | { |
||
88 | 1 | if (!isset($this->trackedItemsFlattened[$filePath])) |
|
89 | 1 | { |
|
90 | throw new TrackedItemNotFoundException("The ContentItem at '$filePath' was not found."); |
||
91 | } |
||
92 | |||
93 | 1 | return $this->trackedItemsFlattened[$filePath]; |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * A jailed representation of CollectionManager::getCollections(). |
||
98 | * |
||
99 | * @return JailedDocument[][] |
||
|
|||
100 | */ |
||
101 | 19 | public function getJailedCollections() |
|
105 | |||
106 | /** |
||
107 | * Parse every collection and store them in the manager. |
||
108 | * |
||
109 | * @param string[][] $collections An array of definitions for collections |
||
110 | */ |
||
111 | 36 | public function parseCollections($collections) |
|
112 | { |
||
113 | 36 | if ($collections == null || empty($collections)) |
|
114 | 36 | { |
|
115 | 1 | $this->logger->debug('No collections found, nothing to parse.'); |
|
116 | |||
117 | 1 | return; |
|
118 | } |
||
119 | |||
120 | 36 | $this->collectionDefinitions = $collections; |
|
121 | |||
122 | /** |
||
123 | * The information which each collection has taken from the configuration file. |
||
124 | * |
||
125 | * $collection['name'] string The name of the collection |
||
126 | * ['folder'] string The folder where this collection has its ContentItems |
||
127 | * |
||
128 | * @var array |
||
129 | */ |
||
130 | 36 | foreach ($collections as $collection) |
|
131 | { |
||
132 | 36 | $this->logger->notice('Loading "{name}" collection...', [ |
|
133 | 36 | 'name' => $collection['name'], |
|
134 | 36 | ]); |
|
135 | |||
136 | 36 | $collectionFolder = fs::absolutePath($collection['folder']); |
|
137 | |||
138 | 36 | if (!fs::exists($collectionFolder)) |
|
139 | 36 | { |
|
140 | $this->logger->warning('The folder "{folder}" could not be found for the "{name}" collection', [ |
||
141 | 'folder' => $collection['folder'], |
||
142 | 'name' => $collection['name'], |
||
143 | ]); |
||
144 | |||
145 | continue; |
||
146 | } |
||
147 | |||
148 | 36 | $this->saveFolderDefinition($collection['folder'], $collection); |
|
149 | 36 | $this->scanTrackableItems($collectionFolder, [ |
|
150 | 36 | 'namespace' => $collection['name'], |
|
151 | 36 | ]); |
|
152 | 36 | } |
|
153 | 36 | } |
|
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | 1 | public function createNewItem($filePath) |
|
159 | { |
||
160 | 1 | $collection = $this->getCollectionNameFromPath($filePath); |
|
161 | |||
162 | 1 | return $this->handleTrackableItem($filePath, [ |
|
163 | 1 | 'namespace' => $collection, |
|
164 | 1 | ]); |
|
165 | } |
||
166 | |||
167 | /** |
||
168 | * {@inheritdoc} |
||
169 | */ |
||
170 | public function refreshItem($filePath) |
||
173 | |||
174 | /** |
||
175 | * {@inheritdoc} |
||
176 | */ |
||
177 | 36 | protected function handleTrackableItem(File $filePath, array $options = []) |
|
197 | |||
198 | /** |
||
199 | * Get the name of the Collection this ContentItem belongs to based on its location. |
||
200 | * |
||
201 | * @param File $file |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | 1 | private function getCollectionNameFromPath(File $file) |
|
217 | } |
||
218 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.