diff options
author | n-aleha <nick_aleha@myway.com> | 2014-05-12 01:00:59 +0300 |
---|---|---|
committer | n-aleha <nick_aleha@myway.com> | 2014-05-29 01:07:44 +0300 |
commit | 031273de728e2c69e583cc4beef49087228cbc2c (patch) | |
tree | 636bd74248fc0f3ac45231c8adfa8f02dad6f3cd | |
parent | 305be2ae64dc3236d9e39a97d35394ba171482b1 (diff) | |
download | forums-031273de728e2c69e583cc4beef49087228cbc2c.tar forums-031273de728e2c69e583cc4beef49087228cbc2c.tar.gz forums-031273de728e2c69e583cc4beef49087228cbc2c.tar.bz2 forums-031273de728e2c69e583cc4beef49087228cbc2c.tar.xz forums-031273de728e2c69e583cc4beef49087228cbc2c.zip |
[ticket/11467] Add language variables for extension exception messages
Remove hard-coded messages and add language variables for extension
exception messages.
PHPBB3-11467
-rw-r--r-- | phpBB/config/services.yml | 1 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_extensions.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 2 | ||||
-rw-r--r-- | phpBB/language/en/acp/extensions.php | 3 | ||||
-rw-r--r-- | phpBB/language/en/common.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/extension/manager.php | 17 | ||||
-rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 30 |
7 files changed, 37 insertions, 20 deletions
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 4de47f750f..618ffacb24 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -173,6 +173,7 @@ services: - %tables.ext% - %core.root_path% - %core.php_ext% + - @user - @cache.driver filesystem: diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 88b6a9c270..3d3cfb7f16 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -70,7 +70,7 @@ class acp_extensions // If they've specified an extension, let's load the metadata manager and validate it. if ($ext_name) { - $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $phpbb_root_path); + $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path); try { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 3000a18668..2d3ac62f86 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3030,7 +3030,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port } else if (stripos($line, '404 not found') !== false) { - $errstr = $user->lang('FILE_NOT_FOUND', $filename); + $errstr = $user->lang('FILE_NOT_FOUND', $filename); return false; } } diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index e9f1c3ac5c..6ec722bb78 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -117,4 +117,7 @@ $lang = array_merge($lang, array( 'VERSIONCHECK_FORCE_UPDATE_ALL' => 'Re-Check all versions', 'FORCE_UNSTABLE' => 'Always check for unstable versions', 'EXTENSIONS_VERSION_CHECK_SETTINGS' => 'Version check settings', + + 'META_FIELD_NOT_SET' => 'Required meta field %s has not been set.', + 'META_FIELD_INVALID' => 'Meta field %s is invalid.', )); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 5e524a6164..2020783100 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -231,6 +231,8 @@ $lang = array_merge($lang, array( 'FILESIZE' => 'File size', 'FILEDATE' => 'File date', 'FILE_COMMENT' => 'File comment', + 'FILE_CONTENT_ERR' => 'Could not read the contents of file: %s', + 'FILE_JSON_DECODE_ERR' => 'Failed to decode json file: %s', 'FILE_NOT_FOUND' => 'The requested file could not be found: %s', 'FIND_USERNAME' => 'Find a member', 'FOLDER' => 'Folder', diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 0bfec23573..50877c9ca1 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -26,6 +26,7 @@ class manager protected $db; protected $config; protected $cache; + protected $user; protected $php_ext; protected $extensions; protected $extension_table; @@ -37,24 +38,26 @@ class manager * * @param ContainerInterface $container A container * @param \phpbb\db\driver\driver_interface $db A database connection - * @param \phpbb\config\config $config \phpbb\config\config + * @param \phpbb\config\config $config Config object * @param \phpbb\filesystem $filesystem * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. - * @param string $php_ext php file extension + * @param string $php_ext php file extension, defaults to php + * @param \phpbb\user $user User object * @param \phpbb\cache\driver\driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\user $user, \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext') { $this->container = $container; - $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->config = $config; - $this->cache = $cache; $this->filesystem = $filesystem; - $this->php_ext = $php_ext; $this->extension_table = $extension_table; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->user = $user; + $this->cache = $cache; $this->cache_name = $cache_name; $this->extensions = ($this->cache) ? $this->cache->get($this->cache_name) : false; @@ -150,7 +153,7 @@ class manager */ public function create_extension_metadata_manager($name, \phpbb\template\template $template) { - return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->phpbb_root_path); + return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->user, $this->phpbb_root_path); } /** diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index 047f0ca54c..1c4019c22d 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -37,6 +37,12 @@ class metadata_manager protected $template; /** + * phpBB User instance + * @var \phpbb\user + */ + protected $user; + + /** * phpBB root path * @var string */ @@ -65,15 +71,17 @@ class metadata_manager * * @param string $ext_name Name (including vendor) of the extension * @param \phpbb\config\config $config phpBB Config instance - * @param \phpbb\extension\manager $extension_manager An instance of the phpBBb extension manager - * @param \phpbb\template\template $template phpBB Template instance + * @param \phpbb\extension\manager $extension_manager An instance of the phpBBb extension manager + * @param \phpbb\template\template $template phpBB Template instance + * @param \phpbb\user $user User instance * @param string $phpbb_root_path Path to the phpbb includes directory. */ - public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, $phpbb_root_path) + public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, \phpbb\user $user, $phpbb_root_path) { $this->config = $config; $this->extension_manager = $extension_manager; $this->template = $template; + $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->ext_name = $ext_name; @@ -141,7 +149,7 @@ class metadata_manager if (!file_exists($this->metadata_file)) { - throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file); + throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file)); } } @@ -154,18 +162,18 @@ class metadata_manager { if (!file_exists($this->metadata_file)) { - throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file); + throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file)); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - throw new \phpbb\extension\exception('file_get_contents failed on ' . $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('json_decode failed on ' . $this->metadata_file); + throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file)); } $this->metadata = $metadata; @@ -224,12 +232,12 @@ class metadata_manager { if (!isset($this->metadata[$name])) { - throw new \phpbb\extension\exception("Required meta field '$name' has not been set."); + throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', $name)); } if (!preg_match($fields[$name], $this->metadata[$name])) { - throw new \phpbb\extension\exception("Meta field '$name' is invalid."); + throw new \phpbb\extension\exception($this->user->lang('META_FIELD_INVALID', $name)); } } break; @@ -247,14 +255,14 @@ class metadata_manager { if (empty($this->metadata['authors'])) { - throw new \phpbb\extension\exception("Required meta field 'authors' has not been set."); + throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'authors')); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - throw new \phpbb\extension\exception("Required meta field 'author name' has not been set."); + throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'author name')); } } |