aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/extension
diff options
context:
space:
mode:
authorjaviexin <javiexin@gmail.com>2017-02-09 22:03:53 +0100
committerjaviexin <javiexin@gmail.com>2017-02-09 22:03:53 +0100
commite0e59bc6c080033dd7250a9f84cbeb6cd47acf0a (patch)
tree0d3d97358189fd420387fcaded6423f3c0ab7fca /phpBB/phpbb/extension
parent3322117c3863c443ca1b79d25541bde4c662c0ed (diff)
downloadforums-e0e59bc6c080033dd7250a9f84cbeb6cd47acf0a.tar
forums-e0e59bc6c080033dd7250a9f84cbeb6cd47acf0a.tar.gz
forums-e0e59bc6c080033dd7250a9f84cbeb6cd47acf0a.tar.bz2
forums-e0e59bc6c080033dd7250a9f84cbeb6cd47acf0a.tar.xz
forums-e0e59bc6c080033dd7250a9f84cbeb6cd47acf0a.zip
[ticket/15080] Save unneeded file loads for extension metadata
PHPBB3-15080
Diffstat (limited to 'phpBB/phpbb/extension')
-rw-r--r--phpBB/phpbb/extension/metadata_manager.php60
1 files changed, 15 insertions, 45 deletions
diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php
index a64d88fe39..759f15ee5c 100644
--- a/phpBB/phpbb/extension/metadata_manager.php
+++ b/phpBB/phpbb/extension/metadata_manager.php
@@ -97,13 +97,11 @@ class metadata_manager
*/
public function get_metadata($element = 'all')
{
- $this->set_metadata_file();
-
- // Fetch the metadata
- $this->fetch_metadata();
-
- // Clean the metadata
- $this->clean_metadata_array();
+ // Fetch and clean the metadata if not done yet
+ if ($this->metadata_file === '')
+ {
+ $this->fetch_metadata_from_file();
+ }
switch ($element)
{
@@ -136,11 +134,11 @@ class metadata_manager
}
/**
- * Sets the filepath of the metadata file
+ * Sets the path of the metadata file, gets its contents and cleans loaded file
*
* @throws \phpbb\extension\exception
*/
- private function set_metadata_file()
+ private function fetch_metadata_from_file()
{
$ext_filepath = $this->extension_manager->get_extension_path($this->ext_name);
$metadata_filepath = $this->phpbb_root_path . $ext_filepath . 'composer.json';
@@ -151,37 +149,19 @@ class metadata_manager
{
throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file));
}
- }
- /**
- * Gets the contents of the composer.json file
- *
- * @return bool True if success, throws an exception on failure
- * @throws \phpbb\extension\exception
- */
- private function fetch_metadata()
- {
- if (!file_exists($this->metadata_file))
+ if (!($file_contents = file_get_contents($this->metadata_file)))
{
- throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file));
+ throw new \phpbb\extension\exception($this->user->lang('FILE_CONTENT_ERR', $this->metadata_file));
}
- else
- {
- if (!($file_contents = file_get_contents($this->metadata_file)))
- {
- throw new \phpbb\extension\exception($this->user->lang('FILE_CONTENT_ERR', $this->metadata_file));
- }
-
- if (($metadata = json_decode($file_contents, true)) === null)
- {
- throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file));
- }
- array_walk_recursive($metadata, array($this, 'sanitize_json'));
- $this->metadata = $metadata;
-
- return true;
+ if (($metadata = json_decode($file_contents, true)) === null)
+ {
+ throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file));
}
+
+ array_walk_recursive($metadata, array($this, 'sanitize_json'));
+ $this->metadata = $metadata;
}
/**
@@ -196,16 +176,6 @@ class metadata_manager
}
/**
- * This array handles the cleaning of the array
- *
- * @return array Contains the cleaned metadata array
- */
- private function clean_metadata_array()
- {
- return $this->metadata;
- }
-
- /**
* Validate fields
*
* @param string $name ("all" for display and enable validation