diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index a833c8c482..287074395d 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -49,9 +49,12 @@ class acp_extensions { $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template, $config); - try{ + try + { $md_manager->get_metadata('all'); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { trigger_error($e); } } @@ -172,7 +175,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('enabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -183,7 +187,9 @@ class acp_extensions 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $name, 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); @@ -204,7 +210,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -215,7 +222,9 @@ class acp_extensions 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); @@ -238,7 +247,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -248,7 +258,9 @@ class acp_extensions $this->output_actions('disabled', array( 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); diff --git a/phpBB/includes/exception/metadata.php b/phpBB/includes/exception/metadata.php deleted file mode 100644 index 93cc337f55..0000000000 --- a/phpBB/includes/exception/metadata.php +++ /dev/null @@ -1,69 +0,0 @@ -code = $code; - $this->field_name = $field_name; - } - - public function __toString() - { - return sprintf($this->getErrorMessage(), $this->field_name); - } - - public function getErrorMessage() - { - switch ($this->code) - { - case self::NOT_SET: - return 'The "%s" meta field has not been set.'; - break; - - case self::INVALID: - return 'The "%s" meta field is not valid.'; - break; - - case self::FILE_GET_CONTENTS: - return 'file_get_contents failed on %s'; - break; - - case self::JSON_DECODE: - return 'json_decode failed on %s'; - break; - - case self::FILE_DOES_NOT_EXIST: - return 'Required file does not exist at %s'; - break; - - default: - return 'An unexpected error has occurred.'; - break; - } - } -} \ No newline at end of file diff --git a/phpBB/includes/extension/exception.php b/phpBB/includes/extension/exception.php new file mode 100644 index 0000000000..e08a8912ea --- /dev/null +++ b/phpBB/includes/extension/exception.php @@ -0,0 +1,27 @@ +getMessage(); + } +} \ No newline at end of file diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 126331ce1c..27b04d4c08 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -114,7 +114,7 @@ class phpbb_extension_metadata_manager if (!file_exists($this->metadata_file)) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); + throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); } } @@ -127,18 +127,18 @@ class phpbb_extension_metadata_manager { if (!file_exists($this->metadata_file)) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); + throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_GET_CONTENTS, $this->metadata_file); + throw new phpbb_extension_exception('file_get_contents failed on ' . $this->metadata_file); } if (($metadata = json_decode($file_contents, true)) === NULL) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::JSON_DECODE, $this->metadata_file); + throw new phpbb_extension_exception('json_decode failed on ' . $this->metadata_file); } $this->metadata = $metadata; @@ -182,12 +182,12 @@ class phpbb_extension_metadata_manager { if (!isset($this->metadata[$name])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, $name); + throw new phpbb_extension_exception("Required meta field '$name' has not been set."); } if (!preg_match($fields[$name], $this->metadata[$name])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::INVALID, $name); + throw new phpbb_extension_exception("Meta field '$name' is invalid."); } } @@ -222,14 +222,14 @@ class phpbb_extension_metadata_manager { if (empty($this->metadata['authors'])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'authors'); + throw new phpbb_extension_exception("Required meta field 'authors' has not been set."); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'author name'); + throw new phpbb_extension_exception("Required meta field 'author name' has not been set."); } }