Skip to content

Commit

Permalink
Fix #406
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Oct 25, 2013
1 parent 46f6182 commit 5519ab5
Showing 1 changed file with 87 additions and 18 deletions.
105 changes: 87 additions & 18 deletions ext/mvc/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,29 @@ PHP_METHOD(Phalcon_Mvc_View, __construct){
*/
PHP_METHOD(Phalcon_Mvc_View, setViewsDir){

zval *views_dir;
zval **views_dir;

phalcon_fetch_params(0, 1, 0, &views_dir);

if (Z_TYPE_P(views_dir) != IS_STRING) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "The views directory must be a string");
return;
phalcon_fetch_params_ex(1, 0, &views_dir);
PHALCON_ENSURE_IS_STRING(views_dir);
if (Z_STRLEN_PP(views_dir)) {
int len = Z_STRLEN_PP(views_dir);
char *c = Z_STRVAL_PP(views_dir);

if (c[len-1] != '/' && c[len-1] != '\\') {
SEPARATE_ZVAL(views_dir);
c = Z_STRVAL_PP(views_dir);

c = erealloc(c, len+2);
if (c != NULL) {
c[len] = PHP_DIR_SEPARATOR;
c[len+1] = 0;

ZVAL_STRINGL(*views_dir, c, len+1, 0);
}
}
}
phalcon_update_property_this(this_ptr, SL("_viewsDir"), views_dir TSRMLS_CC);

phalcon_update_property_this(this_ptr, SL("_viewsDir"), *views_dir TSRMLS_CC);

RETURN_THISW();
}
Expand Down Expand Up @@ -170,11 +184,29 @@ PHP_METHOD(Phalcon_Mvc_View, getViewsDir){
*/
PHP_METHOD(Phalcon_Mvc_View, setLayoutsDir){

zval *layouts_dir;
zval **layouts_dir;

phalcon_fetch_params(0, 1, 0, &layouts_dir);

phalcon_update_property_this(this_ptr, SL("_layoutsDir"), layouts_dir TSRMLS_CC);
phalcon_fetch_params_ex(1, 0, &layouts_dir);
PHALCON_ENSURE_IS_STRING(layouts_dir);
if (Z_STRLEN_PP(layouts_dir)) {
int len = Z_STRLEN_PP(layouts_dir);
char *c = Z_STRVAL_PP(layouts_dir);

if (c[len-1] != '/' && c[len-1] != '\\') {
SEPARATE_ZVAL(layouts_dir);
c = Z_STRVAL_PP(layouts_dir);

c = erealloc(c, len+2);
if (c != NULL) {
c[len] = PHP_DIR_SEPARATOR;
c[len+1] = 0;

ZVAL_STRINGL(*layouts_dir, c, len+1, 0);
}
}
}

phalcon_update_property_this(this_ptr, SL("_layoutsDir"), *layouts_dir TSRMLS_CC);
RETURN_THISW();
}

Expand All @@ -201,11 +233,29 @@ PHP_METHOD(Phalcon_Mvc_View, getLayoutsDir){
*/
PHP_METHOD(Phalcon_Mvc_View, setPartialsDir){

zval *partials_dir;
zval **partials_dir;

phalcon_fetch_params(0, 1, 0, &partials_dir);

phalcon_update_property_this(this_ptr, SL("_partialsDir"), partials_dir TSRMLS_CC);
phalcon_fetch_params_ex(1, 0, &partials_dir);
PHALCON_ENSURE_IS_STRING(partials_dir);
if (Z_STRLEN_PP(partials_dir)) {
int len = Z_STRLEN_PP(partials_dir);
char *c = Z_STRVAL_PP(partials_dir);

if (c[len-1] != '/' && c[len-1] != '\\') {
SEPARATE_ZVAL(partials_dir);
c = Z_STRVAL_PP(partials_dir);

c = erealloc(c, len+2);
if (c != NULL) {
c[len] = PHP_DIR_SEPARATOR;
c[len+1] = 0;

ZVAL_STRINGL(*partials_dir, c, len+1, 0);
}
}
}

phalcon_update_property_this(this_ptr, SL("_partialsDir"), *partials_dir TSRMLS_CC);
RETURN_THISW();
}

Expand All @@ -232,11 +282,30 @@ PHP_METHOD(Phalcon_Mvc_View, getPartialsDir){
*/
PHP_METHOD(Phalcon_Mvc_View, setBasePath){

zval *base_path;
zval **base_path;

phalcon_fetch_params(0, 1, 0, &base_path);
phalcon_fetch_params_ex(1, 0, &base_path);

PHALCON_ENSURE_IS_STRING(base_path);
if (Z_STRLEN_PP(base_path)) {
int len = Z_STRLEN_PP(base_path);
char *c = Z_STRVAL_PP(base_path);

if (c[len-1] != '/' && c[len-1] != '\\') {
SEPARATE_ZVAL(base_path);
c = Z_STRVAL_PP(base_path);

c = erealloc(c, len+2);
if (c != NULL) {
c[len] = PHP_DIR_SEPARATOR;
c[len+1] = 0;

ZVAL_STRINGL(*base_path, c, len+1, 0);
}
}
}

phalcon_update_property_this(this_ptr, SL("_basePath"), base_path TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_basePath"), *base_path TSRMLS_CC);
RETURN_THISW();
}

Expand Down

0 comments on commit 5519ab5

Please sign in to comment.