1 | <?php |
||
19 | class CollectionManager extends TrackingManager |
||
20 | { |
||
21 | /** @var string[][] A copy of the collection definitions to be available for later usage. */ |
||
22 | private $collectionDefinitions; |
||
23 | private $configuration; |
||
24 | |||
25 | /** |
||
26 | * CollectionManager constructor. |
||
27 | */ |
||
28 | 37 | public function __construct(Configuration $configuration) |
|
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 5 | public function compileManager() |
|
39 | { |
||
40 | 5 | if (!$this->configuration->hasCollections()) |
|
41 | { |
||
42 | $this->output->notice('No Collections defined... Ignoring'); |
||
43 | return; |
||
44 | } |
||
45 | |||
46 | 5 | $this->parseCollections($this->configuration->getCollectionsFolders()); |
|
47 | 5 | } |
|
48 | |||
49 | /** |
||
50 | * Get all of the ContentItems grouped by Collection name. |
||
51 | * |
||
52 | * @return ContentItem[][] |
||
|
|||
53 | */ |
||
54 | 16 | public function &getCollections() |
|
58 | |||
59 | /** |
||
60 | * Get a ContentItem from a Collection pased on it's path. |
||
61 | * |
||
62 | * @param string $filePath |
||
63 | * |
||
64 | * @throws TrackedItemNotFoundException |
||
65 | * |
||
66 | * @return ContentItem |
||
67 | */ |
||
68 | 1 | public function &getContentItem($filePath) |
|
69 | { |
||
70 | 1 | if (!isset($this->trackedItemsFlattened[$filePath])) |
|
71 | { |
||
72 | throw new TrackedItemNotFoundException("The ContentItem at '$filePath' was not found."); |
||
73 | } |
||
74 | |||
75 | 1 | return $this->trackedItemsFlattened[$filePath]; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * A jailed representation of CollectionManager::getCollections(). |
||
80 | * |
||
81 | * @return JailedDocument[][] |
||
82 | */ |
||
83 | 19 | public function getJailedCollections() |
|
87 | |||
88 | /** |
||
89 | * Parse every collection and store them in the manager. |
||
90 | * |
||
91 | * @param string[][] $collections An array of definitions for collections |
||
92 | */ |
||
93 | 37 | public function parseCollections($collections) |
|
94 | { |
||
95 | 37 | if ($collections === null) |
|
96 | { |
||
97 | $this->output->debug('No collections found, nothing to parse.'); |
||
98 | |||
99 | return; |
||
100 | } |
||
101 | |||
102 | 37 | $this->collectionDefinitions = $collections; |
|
103 | |||
104 | /** |
||
105 | * The information which each collection has taken from the configuration file. |
||
106 | * |
||
107 | * $collection['name'] string The name of the collection |
||
108 | * ['folder'] string The folder where this collection has its ContentItems |
||
109 | * |
||
110 | * @var array |
||
111 | */ |
||
112 | 37 | foreach ($collections as $collection) |
|
113 | { |
||
114 | 37 | $this->output->notice("Loading '{name}' collection...", [ |
|
115 | 37 | 'name' => $collection['name'], |
|
116 | ]); |
||
117 | |||
118 | 37 | $collectionFolder = fs::absolutePath($collection['folder']); |
|
119 | |||
120 | 37 | if (!fs::exists($collectionFolder)) |
|
121 | { |
||
122 | $this->output->warning("The folder '{folder}' could not be found for the '{name}' collection", [ |
||
123 | 'folder' => $collection['folder'], |
||
124 | 'name' => $collection['name'], |
||
125 | ]); |
||
126 | continue; |
||
127 | } |
||
128 | |||
129 | 37 | $this->saveFolderDefinition($collection['folder'], $collection); |
|
130 | 37 | $this->scanTrackableItems($collectionFolder, array( |
|
131 | 37 | 'namespace' => $collection['name'], |
|
132 | )); |
||
133 | } |
||
134 | 37 | } |
|
135 | |||
136 | /** |
||
137 | * {@inheritdoc} |
||
138 | */ |
||
139 | public function createNewItem($filePath) |
||
140 | { |
||
141 | $collection = $this->getTentativeCollectionName($filePath); |
||
142 | |||
143 | return $this->handleTrackableItem($filePath, array( |
||
144 | 'namespace' => $collection, |
||
145 | )); |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | public function refreshItem($filePath) |
||
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | 37 | protected function handleTrackableItem($filePath, array $options = array()) |
|
177 | |||
178 | /** |
||
179 | * Get the name of the Collection this Content Item belongs to. |
||
180 | * |
||
181 | * @param string $filePath |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | private function getTentativeCollectionName($filePath) |
||
197 | } |
||
198 |
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.