| 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 | 15 | 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 | 19 | ->toArray() |
|
| 72 | 19 | ; |
|
| 73 | 19 | }) |
|
| 74 | 19 | ->toArray() |
|
| 75 | 19 | ; |
|
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Parse every collection and store them in the manager. |
||
| 80 | * |
||
| 81 | * @param string[][] $collections An array of definitions for collections |
||
| 82 | */ |
||
| 83 | 36 | public function parseCollections($collections) |
|
| 84 | { |
||
| 85 | 36 | if ($collections === null) |
|
| 86 | 36 | { |
|
| 87 | $this->output->debug('No collections found, nothing to parse.'); |
||
| 88 | |||
| 89 | return; |
||
| 90 | } |
||
| 91 | |||
| 92 | 36 | $this->collectionDefinitions = $collections; |
|
| 93 | |||
| 94 | /** |
||
| 95 | * The information which each collection has taken from the configuration file. |
||
| 96 | * |
||
| 97 | * $collection['name'] string The name of the collection |
||
| 98 | * ['folder'] string The folder where this collection has its ContentItems |
||
| 99 | * |
||
| 100 | * @var array |
||
| 101 | */ |
||
| 102 | 36 | foreach ($collections as $collection) |
|
| 103 | { |
||
| 104 | 36 | $this->output->notice("Loading '{$collection['name']}' collection..."); |
|
|
1 ignored issue
–
show
|
|||
| 105 | |||
| 106 | 36 | $collectionFolder = $this->fs->absolutePath($collection['folder']); |
|
| 107 | |||
| 108 | 36 | if (!$this->fs->exists($collectionFolder)) |
|
| 109 | 36 | { |
|
| 110 | $this->output->warning("The folder '{$collection['folder']}' could not be found for the '{$collection['name']}' collection"); |
||
|
1 ignored issue
–
show
|
|||
| 111 | continue; |
||
| 112 | } |
||
| 113 | |||
| 114 | 36 | $this->saveFolderDefinition($collection['folder'], $collection); |
|
| 115 | 36 | $this->scanTrackableItems($collectionFolder, array( |
|
| 116 | 36 | 'namespace' => $collection['name'], |
|
| 117 | 36 | )); |
|
| 118 | 36 | } |
|
| 119 | 36 | } |
|
| 120 | |||
| 121 | /** |
||
| 122 | * {@inheritdoc} |
||
| 123 | */ |
||
| 124 | public function createNewItem($filePath) |
||
| 125 | { |
||
| 126 | $collection = $this->getTentativeCollectionName($filePath); |
||
| 127 | |||
| 128 | return $this->handleTrackableItem($filePath, array( |
||
| 129 | 'namespace' => $collection, |
||
| 130 | )); |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * {@inheritdoc} |
||
| 135 | */ |
||
| 136 | public function refreshItem($filePath) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritdoc} |
||
| 142 | */ |
||
| 143 | 36 | protected function handleTrackableItem($filePath, $options = array()) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Get the name of the Collection this Content Item belongs to. |
||
| 163 | * |
||
| 164 | * @param string $filePath |
||
| 165 | * |
||
| 166 | * @return string |
||
| 167 | */ |
||
| 168 | private function getTentativeCollectionName($filePath) |
||
| 180 | } |
||
| 181 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.