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