diff options
| author | David King <imkingdavid@gmail.com> | 2012-11-13 09:43:53 -0500 |
|---|---|---|
| committer | David King <imkingdavid@gmail.com> | 2012-11-16 16:47:22 -0500 |
| commit | ac29c7e9d982648ed64e0ef73bbebd67567c2d89 (patch) | |
| tree | f12565edb8dd3424c841a825a70362d7d3a03b09 | |
| parent | 4b6d538b062a56f55ba221ac8437b4bfc712a475 (diff) | |
| download | forums-ac29c7e9d982648ed64e0ef73bbebd67567c2d89.tar forums-ac29c7e9d982648ed64e0ef73bbebd67567c2d89.tar.gz forums-ac29c7e9d982648ed64e0ef73bbebd67567c2d89.tar.bz2 forums-ac29c7e9d982648ed64e0ef73bbebd67567c2d89.tar.xz forums-ac29c7e9d982648ed64e0ef73bbebd67567c2d89.zip | |
[feature/controller] Rework assign_display(), use exceptions instead of return
PHPBB3-10864
| -rw-r--r-- | phpBB/includes/template/template.php | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index a48e8459d5..a6ae44969b 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -219,30 +219,45 @@ class phpbb_template * * @param string $handle Handle to operate on * @param string $template_var Template variable to assign compiled handle to - * @param bool $return_content If true return compiled handle, otherwise assign to $template_var - * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true + * @param bool $return_contents If true return compiled handle, otherwise assign to $template_var + * @return bool|string If $return_content is true return string of the compiled handle, otherwise return true + * @throws RuntimeException */ - public function assign_display($handle, $template_var = '', $return_content = true) + public function assign_display($handle, $template_var = '', $return_contents = true) { $contents = $this->return_display($handle); - if ($return_content === true || empty($template_var) || $contents === false) + if (!$template_var) { - return $contents; + throw new RuntimeException($this->user->lang('TEMPLATE_CANNOT_BE_ASSIGNED') } $this->assign_var($template_var, $contents); - return true; + // If !$return_content evaluates to true, true will be returned + // Otherwise, the value of $contents will be returned + return !$return_contents ?: $contents; } + /** + * Return the compiled template code as a string + * + * @param string $handle Handle to operate on + * @return string Compiled template code; can be output directly to page + * @throws RuntimeException + */ public function return_display($handle) { ob_start(); $result = $this->display($handle); $contents = ob_get_clean(); - return $result === false ? $result : $contents; + if ($result === false) + { + throw new RuntimeException($user->lang('TEMPLATE_HANDLE_NOT_FOUND')); + } + + return $contents; } /** |
