From 6f9793d04bc8d4de0ba3f97a460ebae884e1c0a0 Mon Sep 17 00:00:00 2001 From: kaste Date: Sun, 20 Apr 2008 13:50:46 +0000 Subject: [PATCH] returning false or invoking a render in a before-filter halts the execution chain of the current request. Fixes #150 git-svn-id: http://svn.akelos.org/trunk@570 a2fa5c27-f921-0410-a72c-bf682d381be0 --- lib/AkActionController.php | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/AkActionController.php b/lib/AkActionController.php index 454720a..6d0741a 100644 --- a/lib/AkActionController.php +++ b/lib/AkActionController.php @@ -183,7 +183,7 @@ class AkActionController extends AkObject $this->performActionWithFilters($this->_action_name); - if (!$this->_hasPerformed()){ + if (!$this->_hasPerformed()){ $this->_enableLayoutOnRender ? $this->renderWithLayout() : $this->renderWithoutLayout(); } @@ -280,7 +280,7 @@ class AkActionController extends AkObject } } return array(); - } + } function getDefaultHelpers() { @@ -300,7 +300,7 @@ class AkActionController extends AkObject function getApplicationHelpers() { $helper_names = array(); - if ($this->app_helpers == 'all'){ + if ($this->app_helpers == 'all'){ $available_helpers = Ak::dir(AK_HELPERS_DIR,array('dirs'=>false)); $helper_names = array(); foreach ($available_helpers as $available_helper){ @@ -566,7 +566,7 @@ class AkActionController extends AkObject * $this->render(array('nothing' => true, 'status' => 401)); */ function render($options = null, $status = 200) - { + { if(empty($options['partial']) && $this->_hasPerformed()){ $this->_doubleRenderError(Ak::t("Can only render or redirect once per action")); return false; @@ -643,7 +643,6 @@ class AkActionController extends AkObject } AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Rendering $this->full_template_path" . (!empty($status) ? " ($status)":'')) : null; - return $this->renderText($this->Template->renderFile($template_path, $use_full_path, $locals), $status); } @@ -835,7 +834,7 @@ class AkActionController extends AkObject function getControllerName() { if(!isset($this->controller_name)){ - $current_class_name = str_replace('_', '::', get_class($this)); + $current_class_name = str_replace('_', '::', get_class($this)); if (!AK_PHP5){ $current_class_name = $this->__getControllerName_PHP4_fix($current_class_name); } @@ -1006,7 +1005,7 @@ class AkActionController extends AkObject * would have slashed-off the path components after the changed action. */ function urlFor($options = array(), $parameters_for_method_reference = null) - { + { return $this->rewrite($this->rewriteOptions($options)); } @@ -1072,7 +1071,7 @@ class AkActionController extends AkObject function _assertExistanceOfTemplateFile($template_name) { $extension = $this->Template->delegateTemplateExists($template_name); - $this->full_template_path = $this->Template->getFullTemplatePath($template_name, $extension ? $extension : 'tpl'); + $this->full_template_path = $this->Template->getFullTemplatePath($template_name, $extension ? $extension : 'tpl'); if(!$this->_hasTemplate($this->full_template_path)){ if(!empty($this->_ignore_missing_templates) && $this->_ignore_missing_templates === true){ return; @@ -1387,7 +1386,7 @@ class AkActionController extends AkObject * weblog/standard, but setLayout('standard') will return layouts/standard. */ function getActiveLayout($passed_layout = null) - { + { if(empty($passed_layout)){ $layout = !isset($this->layout) ? AkInflector::underscore($this->getControllerName()) : $this->layout; }else{ @@ -1408,8 +1407,8 @@ class AkActionController extends AkObject function renderWithALayout($options = null, $status = null, $layout = null) - { - $template_with_options = !empty($options) && is_array($options); + { + $template_with_options = !empty($options) && is_array($options); if($this->_canApplyLayout($template_with_options, $options) && ($layout = $this->_pickLayout($template_with_options, $options, $layout))){ @@ -1436,14 +1435,14 @@ class AkActionController extends AkObject } function _isCandidateForLayout($options) - { + { return !empty($options['layout']) || (empty($options['text']) && empty($options['file']) && empty($options['inline']) && empty($options['partial']) && empty($options['nothing'])) && !$this->_isTemplateExemptFromLayout($this->_getDefaultTemplateName(empty($options['action']) ? $options['template'] : $options['action'])); } function _pickLayout($template_with_options, $options, $layout = null) - { + { if(!empty($template_with_options)){ $layout = empty($options['layout']) ? ($this->_doesActionHasLayout() ? $this->getActiveLayout(): false) : $this->getActiveLayout($options['layout']); }elseif(empty($layout) || $layout === true){ @@ -1453,7 +1452,7 @@ class AkActionController extends AkObject $layout = strstr($layout,'/') || strstr($layout,DS) ? $layout : 'layouts'.DS.$layout; $layout = substr($layout,0,7) === 'layouts' ? (empty($this->_module_path) ? AK_VIEWS_DIR.DS.$layout.'.tpl' : AK_VIEWS_DIR.DS.'layouts'.DS.trim($this->_module_path, DS).'.tpl') : - $layout.'.tpl'; + $layout.'.tpl'; if (file_exists($layout)) { return $layout; } @@ -1712,7 +1711,7 @@ class AkActionController extends AkObject function beforeFilter() { $filters = func_get_args(); - foreach (array_keys($filters) as $k){ + foreach (array_keys($filters) as $k){ $this->appendBeforeFilter($filters[$k]); } } @@ -1951,12 +1950,12 @@ class AkActionController extends AkObject function performActionWithFilters($method = '') { - if ($this->beforeAction($method) !== false || empty($this->_performed)){ + if ($this->beforeAction($method) !== false && !$this->_hasPerformed()){ $this->performActionWithoutFilters($method); $this->afterAction($method); return true; - } - return $this->performActionWithoutFilters($method); + } + return false; } function performAction($method = '') @@ -2013,7 +2012,7 @@ class AkActionController extends AkObject function _actionIsExempted($filter, $method = '') - { + { $method_id = is_string($method) ? $method : $this->_filterId($method); $filter_id = $this->_filterId($filter); -- 2.11.4.GIT