@@ -32,138 +32,138 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class PluginManager { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var ServerContainer |
|
| 37 | - */ |
|
| 38 | - private $container; |
|
| 35 | + /** |
|
| 36 | + * @var ServerContainer |
|
| 37 | + */ |
|
| 38 | + private $container; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var IAppManager |
|
| 42 | - */ |
|
| 43 | - private $appManager; |
|
| 40 | + /** |
|
| 41 | + * @var IAppManager |
|
| 42 | + */ |
|
| 43 | + private $appManager; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * App plugins |
|
| 47 | - * |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - private $plugins = null; |
|
| 45 | + /** |
|
| 46 | + * App plugins |
|
| 47 | + * |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + private $plugins = null; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * App collections |
|
| 54 | - * |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 57 | - private $collections = null; |
|
| 52 | + /** |
|
| 53 | + * App collections |
|
| 54 | + * |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | + private $collections = null; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Contstruct a PluginManager |
|
| 61 | - * |
|
| 62 | - * @param ServerContainer $container server container for resolving plugin classes |
|
| 63 | - * @param IAppManager $appManager app manager to loading apps and their info |
|
| 64 | - */ |
|
| 65 | - public function __construct(ServerContainer $container, IAppManager $appManager) { |
|
| 66 | - $this->container = $container; |
|
| 67 | - $this->appManager = $appManager; |
|
| 68 | - } |
|
| 59 | + /** |
|
| 60 | + * Contstruct a PluginManager |
|
| 61 | + * |
|
| 62 | + * @param ServerContainer $container server container for resolving plugin classes |
|
| 63 | + * @param IAppManager $appManager app manager to loading apps and their info |
|
| 64 | + */ |
|
| 65 | + public function __construct(ServerContainer $container, IAppManager $appManager) { |
|
| 66 | + $this->container = $container; |
|
| 67 | + $this->appManager = $appManager; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Returns an array of app-registered plugins |
|
| 72 | - * |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - public function getAppPlugins() { |
|
| 76 | - if (null === $this->plugins) { |
|
| 77 | - $this->populate(); |
|
| 78 | - } |
|
| 79 | - return $this->plugins; |
|
| 80 | - } |
|
| 70 | + /** |
|
| 71 | + * Returns an array of app-registered plugins |
|
| 72 | + * |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + public function getAppPlugins() { |
|
| 76 | + if (null === $this->plugins) { |
|
| 77 | + $this->populate(); |
|
| 78 | + } |
|
| 79 | + return $this->plugins; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Returns an array of app-registered collections |
|
| 84 | - * |
|
| 85 | - * @return array |
|
| 86 | - */ |
|
| 87 | - public function getAppCollections() { |
|
| 88 | - if (null === $this->collections) { |
|
| 89 | - $this->populate(); |
|
| 90 | - } |
|
| 91 | - return $this->collections; |
|
| 92 | - } |
|
| 82 | + /** |
|
| 83 | + * Returns an array of app-registered collections |
|
| 84 | + * |
|
| 85 | + * @return array |
|
| 86 | + */ |
|
| 87 | + public function getAppCollections() { |
|
| 88 | + if (null === $this->collections) { |
|
| 89 | + $this->populate(); |
|
| 90 | + } |
|
| 91 | + return $this->collections; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Retrieve plugin and collection list and populate attributes |
|
| 96 | - */ |
|
| 97 | - private function populate() { |
|
| 98 | - $this->plugins = []; |
|
| 99 | - $this->collections = []; |
|
| 100 | - foreach ($this->appManager->getInstalledApps() as $app) { |
|
| 101 | - // load plugins and collections from info.xml |
|
| 102 | - $info = $this->appManager->getAppInfo($app); |
|
| 103 | - if (!isset($info['types']) || !in_array('dav', $info['types'], true)) { |
|
| 104 | - continue; |
|
| 105 | - } |
|
| 106 | - $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); |
|
| 107 | - $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); |
|
| 108 | - } |
|
| 109 | - } |
|
| 94 | + /** |
|
| 95 | + * Retrieve plugin and collection list and populate attributes |
|
| 96 | + */ |
|
| 97 | + private function populate() { |
|
| 98 | + $this->plugins = []; |
|
| 99 | + $this->collections = []; |
|
| 100 | + foreach ($this->appManager->getInstalledApps() as $app) { |
|
| 101 | + // load plugins and collections from info.xml |
|
| 102 | + $info = $this->appManager->getAppInfo($app); |
|
| 103 | + if (!isset($info['types']) || !in_array('dav', $info['types'], true)) { |
|
| 104 | + continue; |
|
| 105 | + } |
|
| 106 | + $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); |
|
| 107 | + $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - private function extractPluginList(array $array) { |
|
| 112 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 113 | - if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { |
|
| 114 | - if (isset($array['sabre']['plugins']['plugin'])) { |
|
| 115 | - $items = $array['sabre']['plugins']['plugin']; |
|
| 116 | - if (!is_array($items)) { |
|
| 117 | - $items = [$items]; |
|
| 118 | - } |
|
| 119 | - return $items; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - return []; |
|
| 124 | - } |
|
| 111 | + private function extractPluginList(array $array) { |
|
| 112 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 113 | + if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { |
|
| 114 | + if (isset($array['sabre']['plugins']['plugin'])) { |
|
| 115 | + $items = $array['sabre']['plugins']['plugin']; |
|
| 116 | + if (!is_array($items)) { |
|
| 117 | + $items = [$items]; |
|
| 118 | + } |
|
| 119 | + return $items; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + return []; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - private function extractCollectionList(array $array) { |
|
| 127 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 128 | - if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { |
|
| 129 | - if (isset($array['sabre']['collections']['collection'])) { |
|
| 130 | - $items = $array['sabre']['collections']['collection']; |
|
| 131 | - if (!is_array($items)) { |
|
| 132 | - $items = [$items]; |
|
| 133 | - } |
|
| 134 | - return $items; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - return []; |
|
| 139 | - } |
|
| 126 | + private function extractCollectionList(array $array) { |
|
| 127 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 128 | + if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { |
|
| 129 | + if (isset($array['sabre']['collections']['collection'])) { |
|
| 130 | + $items = $array['sabre']['collections']['collection']; |
|
| 131 | + if (!is_array($items)) { |
|
| 132 | + $items = [$items]; |
|
| 133 | + } |
|
| 134 | + return $items; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + return []; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - private function loadSabrePluginsFromInfoXml(array $plugins) { |
|
| 142 | - foreach ($plugins as $plugin) { |
|
| 143 | - try { |
|
| 144 | - $this->plugins[] = $this->container->query($plugin); |
|
| 145 | - } catch (QueryException $e) { |
|
| 146 | - if (class_exists($plugin)) { |
|
| 147 | - $this->plugins[] = new $plugin(); |
|
| 148 | - } else { |
|
| 149 | - throw new \Exception("Sabre plugin class '$plugin' is unknown and could not be loaded"); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 141 | + private function loadSabrePluginsFromInfoXml(array $plugins) { |
|
| 142 | + foreach ($plugins as $plugin) { |
|
| 143 | + try { |
|
| 144 | + $this->plugins[] = $this->container->query($plugin); |
|
| 145 | + } catch (QueryException $e) { |
|
| 146 | + if (class_exists($plugin)) { |
|
| 147 | + $this->plugins[] = new $plugin(); |
|
| 148 | + } else { |
|
| 149 | + throw new \Exception("Sabre plugin class '$plugin' is unknown and could not be loaded"); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - private function loadSabreCollectionsFromInfoXml(array $collections) { |
|
| 156 | - foreach ($collections as $collection) { |
|
| 157 | - try { |
|
| 158 | - $this->collections[] = $this->container->query($collection); |
|
| 159 | - } catch (QueryException $e) { |
|
| 160 | - if (class_exists($collection)) { |
|
| 161 | - $this->collections[] = new $collection(); |
|
| 162 | - } else { |
|
| 163 | - throw new \Exception("Sabre collection class '$collection' is unknown and could not be loaded"); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 155 | + private function loadSabreCollectionsFromInfoXml(array $collections) { |
|
| 156 | + foreach ($collections as $collection) { |
|
| 157 | + try { |
|
| 158 | + $this->collections[] = $this->container->query($collection); |
|
| 159 | + } catch (QueryException $e) { |
|
| 160 | + if (class_exists($collection)) { |
|
| 161 | + $this->collections[] = new $collection(); |
|
| 162 | + } else { |
|
| 163 | + throw new \Exception("Sabre collection class '$collection' is unknown and could not be loaded"); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | 169 | } |