Skip to content

Commit

Permalink
Make Yaf_View_Simple not final anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Sep 9, 2012
1 parent 70d9fd2 commit 762cb16
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 12 deletions.
57 changes: 57 additions & 0 deletions tests/053.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--TEST--
Check for Custom view engine
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0

--FILE--
<?php
require "build.inc";
define("APPLICATION_PATH", dirname(__FILE__));
startup(APPLICATION_PATH . '/application');
$config = array(
"application" => 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", <<<PHP
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract {
public function _initView(Yaf_Dispatcher \$dispatcher) {
\$dispatcher->setView(new SimpleView("{$tpl_dir}"));
}
}
PHP
);

file_put_contents(APPLICATION_PATH . "/application/controllers/Index.php", <<<PHP
<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
\$this->_view->name = "custom view";
}
}
PHP
);

file_put_contents(APPLICATION_PATH . "/application/views/index/index.phtml", "<?=\$name?>");

$app = new Yaf_Application($config);
$response = $app->bootstrap()->run();
echo $response;
?>
--EXPECTF--
custom view
5 changes: 2 additions & 3 deletions views/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}
/* }}} */
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions yaf_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 762cb16

Please sign in to comment.