1 | <?php |
||
17 | class CollectionManager extends TrackingManager |
||
18 | { |
||
19 | /** |
||
20 | * A copy of the collection definitions to be available for later usage. |
||
21 | * |
||
22 | * @var string[][] |
||
23 | */ |
||
24 | private $collectionDefinitions; |
||
25 | |||
26 | /** |
||
27 | * Get all of the ContentItems grouped by Collection name. |
||
28 | * |
||
29 | * @return ContentItem[][] |
||
30 | */ |
||
31 | 15 | public function &getCollections() |
|
35 | |||
36 | /** |
||
37 | * Get a ContentItem from a Collection pased on it's path. |
||
38 | * |
||
39 | * @param string $filePath |
||
40 | * |
||
41 | * @throws TrackedItemNotFoundException |
||
42 | * |
||
43 | * @return ContentItem |
||
44 | */ |
||
45 | 1 | public function &getContentItem($filePath) |
|
46 | { |
||
47 | 1 | if (!isset($this->trackedItemsFlattened[$filePath])) |
|
48 | { |
||
49 | throw new TrackedItemNotFoundException("The ContentItem at '$filePath' was not found."); |
||
1 ignored issue
–
show
|
|||
50 | } |
||
51 | |||
52 | 1 | return $this->trackedItemsFlattened[$filePath]; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * A jailed representation of CollectionManager::getCollections(). |
||
57 | * |
||
58 | * @return JailedDocument[][] |
||
59 | */ |
||
60 | 18 | public function getJailedCollections() |
|
61 | { |
||
62 | 18 | $jailItems = array(); |
|
63 | |||
64 | 18 | foreach ($this->trackedItems as $key => $items) |
|
65 | { |
||
66 | 18 | foreach ($items as $name => $contentItem) |
|
67 | { |
||
68 | 18 | $jailItems[$key][$name] = $contentItem->createJail(); |
|
69 | } |
||
70 | } |
||
71 | |||
72 | 18 | return $jailItems; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Parse every collection and store them in the manager. |
||
77 | * |
||
78 | * @param string[][] $collections An array of definitions for collections |
||
79 | */ |
||
80 | 35 | public function parseCollections($collections) |
|
81 | { |
||
82 | 35 | if ($collections === null) |
|
83 | { |
||
84 | $this->output->debug('No collections found, nothing to parse.'); |
||
85 | |||
86 | return; |
||
87 | } |
||
88 | |||
89 | 35 | $this->collectionDefinitions = $collections; |
|
90 | |||
91 | /** |
||
92 | * The information which each collection has taken from the configuration file. |
||
93 | * |
||
94 | * $collection['name'] string The name of the collection |
||
95 | * ['folder'] string The folder where this collection has its ContentItems |
||
96 | * |
||
97 | * @var array |
||
98 | */ |
||
99 | 35 | foreach ($collections as $collection) |
|
100 | { |
||
101 | 35 | $this->output->notice("Loading '{$collection['name']}' collection..."); |
|
1 ignored issue
–
show
|
|||
102 | |||
103 | 35 | $collectionFolder = $this->fs->absolutePath($collection['folder']); |
|
104 | |||
105 | 35 | if (!$this->fs->exists($collectionFolder)) |
|
106 | { |
||
107 | $this->output->warning("The folder '{$collection['folder']}' could not be found for the '{$collection['name']}' collection"); |
||
1 ignored issue
–
show
|
|||
108 | continue; |
||
109 | } |
||
110 | |||
111 | 35 | $this->saveFolderDefinition($collection['folder'], $collection); |
|
112 | 35 | $this->scanTrackableItems($collectionFolder, array( |
|
113 | 35 | 'namespace' => $collection['name'], |
|
114 | )); |
||
115 | } |
||
116 | 35 | } |
|
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function createNewItem($filePath) |
||
122 | { |
||
123 | $collection = $this->getTentativeCollectionName($filePath); |
||
124 | |||
125 | return $this->handleTrackableItem($filePath, array( |
||
126 | 'namespace' => $collection, |
||
127 | )); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | public function refreshItem($filePath) |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | 35 | protected function handleTrackableItem($filePath, $options = array()) |
|
157 | |||
158 | /** |
||
159 | * Get the name of the Collection this Content Item belongs to. |
||
160 | * |
||
161 | * @param string $filePath |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | private function getTentativeCollectionName($filePath) |
||
177 | } |
||
178 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.