diff options
Diffstat (limited to 'phpBB/includes/extension/manager.php')
-rw-r--r-- | phpBB/includes/extension/manager.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 86d8fab64b..2eebebf9b2 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -464,4 +464,68 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } + + /** + * Gets and processes the contents of the composer.json file. + * + * TODO: Add authors, fix it + * + * @param string $name Extension name to check + * @return array All the existing metadata keys + */ + public function get_meta_data($name) + { + // Find out where the composer.json is + $ext_filepath = get_extension_path($name); + $md_filepath = $phpbb_root_path . $ext_filepath . '/composer.json'; + + // Read the composer.json and decode it + $metadatafile = file_get_contents($filepath); + $metadata = json_decode($metadatafile, true); + + // What keys are required + $required_md_keys = array( + $metadata['name'], + $metadata['type'], + $metadata['description'], + $metadata['version'], + $metadata['license'], + $medadata['require']['phpbb'], + $metadata['extra']['dispay-name'], + ); + + // Check for required keys and trigger and error if it doesn't exist + foreach ($required_md_keys as $md_key) + { + if (empty($md_key)) + { + trigger_error('Not all required items exist in the composer.json'); + } + else + { + $existing_required_keys += $md_key; + } + } + + // Which keys are optional + $optional_md_keys = array( + $metadata['require']['php'], + $metadata['time'], + $metadata['homepage'], + ); + + $existing_optional_keys = array(); + + foreach ($optional_md_keys as $md_key) + { + if (!empty($md_key)) + { + $existing_optional_keys += $md_key; + } + } + + $keys = array_merge($existing_optional_keys, $existing_required_keys); + + return $keys; + } } |