From 762cb16c03784919571adde0acb87d5c65178a48 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 9 Sep 2012 14:54:48 +0800 Subject: [PATCH] Make Yaf_View_Simple not final anymore --- tests/053.phpt | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ views/simple.c | 5 ++--- yaf_dispatcher.c | 18 +++++++-------- 3 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 tests/053.phpt diff --git a/tests/053.phpt b/tests/053.phpt new file mode 100644 index 00000000..9ab17904 --- /dev/null +++ b/tests/053.phpt @@ -0,0 +1,57 @@ +--TEST-- +Check for Custom view engine +--SKIPIF-- + +--INI-- +yaf.use_spl_autoload=0 +yaf.lowcase_path=0 + +--FILE-- + array( + "directory" => APPLICATION_PATH . "/application/", + ), +); + +class SimpleView extends Yaf_View_Simple { + public function __constrct() { + } + + public function assign($name, $value = NULL) { + $this->_tpls_vars[$name] = $value; + } +} + +$tpl_dir = APPLICATION_PATH . "/application/views"; +file_put_contents(APPLICATION_PATH . "/application/Bootstrap.php", <<setView(new SimpleView("{$tpl_dir}")); + } + } +PHP +); + +file_put_contents(APPLICATION_PATH . "/application/controllers/Index.php", <<_view->name = "custom view"; + } + } +PHP +); + +file_put_contents(APPLICATION_PATH . "/application/views/index/index.phtml", ""); + +$app = new Yaf_Application($config); +$response = $app->bootstrap()->run(); +echo $response; +?> +--EXPECTF-- +custom view diff --git a/views/simple.c b/views/simple.c index 88ea0e30..03ded40c 100644 --- a/views/simple.c +++ b/views/simple.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: simple.c 327549 2012-09-09 03:02:48Z laruence $ */ +/* $Id: simple.c 327562 2012-09-09 06:54:44Z laruence $ */ #include "main/php_output.h" @@ -686,7 +686,7 @@ PHP_METHOD(yaf_view_simple, setScriptPath) { /** {{{ proto public Yaf_View_Simple::getScriptPath(void) */ PHP_METHOD(yaf_view_simple, getScriptPath) { - zval *tpl_dir = zend_read_property(yaf_view_simple_ce, getThis(), ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLDIR), 1 TSRMLS_CC); + zval *tpl_dir = zend_read_property(yaf_view_simple_ce, getThis(), ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLDIR), 0 TSRMLS_CC); RETURN_ZVAL(tpl_dir, 1, 0); } /* }}} */ @@ -904,7 +904,6 @@ YAF_STARTUP_FUNCTION(view_simple) { zend_declare_property_null(yaf_view_simple_ce, ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLDIR), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(yaf_view_simple_ce, ZEND_STRL(YAF_VIEW_PROPERTY_NAME_OPTS), ZEND_ACC_PROTECTED TSRMLS_CC); - yaf_view_simple_ce->ce_flags |= ZEND_ACC_FINAL_CLASS; zend_class_implements(yaf_view_simple_ce TSRMLS_CC, 1, yaf_view_interface_ce); return SUCCESS; diff --git a/yaf_dispatcher.c b/yaf_dispatcher.c index 7d87ec9d..4b5f9b8a 100644 --- a/yaf_dispatcher.c +++ b/yaf_dispatcher.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: yaf_dispatcher.c 327561 2012-09-09 06:30:22Z laruence $ */ +/* $Id: yaf_dispatcher.c 327562 2012-09-09 06:54:44Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -591,14 +591,13 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, view_dir = zend_read_property(view_ce, view, ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLDIR), 1 TSRMLS_CC); } else { zend_call_method_with_0_params(&view, view_ce, NULL, "getscriptpath", &view_dir); - } - - if (EG(exception)) { - if (view_dir) { - zval_ptr_dtor(&view_dir); + if (EG(exception)) { + if (view_dir) { + zval_ptr_dtor(&view_dir); + } + zval_ptr_dtor(&icontroller); + return 0; } - zval_ptr_dtor(&icontroller); - return 0; } if (!view_dir || IS_STRING != Z_TYPE_P(view_dir) || !Z_STRLEN_P(view_dir)) { @@ -631,7 +630,8 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, zval_ptr_dtor(&icontroller); return 0; } - + } else if (view_ce != yaf_view_simple_ce) { + zval_ptr_dtor(&view_dir); } zend_update_property(ce, icontroller, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_NAME), controller TSRMLS_CC);