From 64ab3a7f72601fcf49d26738a75d69956258f645 Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Fri, 11 Oct 2013 14:34:45 +0800 Subject: [PATCH 1/2] Add Tag::setTitleSeparator --- ext/tag.c | 32 ++++++++++++++++++++++++----- ext/tag.h | 6 ++++++ unit-tests/TagTest.php | 46 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 unit-tests/TagTest.php diff --git a/ext/tag.c b/ext/tag.c index 25618769c53..6749147058a 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -61,6 +61,7 @@ PHALCON_INIT_CLASS(Phalcon_Tag){ zend_declare_property_null(phalcon_tag_ce, SL("_displayValues"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); zend_declare_property_null(phalcon_tag_ce, SL("_documentTitle"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_null(phalcon_tag_ce, SL("_documentTitleSeparator"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); zend_declare_property_long(phalcon_tag_ce, SL("_documentType"), 11, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); zend_declare_property_null(phalcon_tag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); zend_declare_property_null(phalcon_tag_ce, SL("_urlService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); @@ -1364,6 +1365,25 @@ PHP_METHOD(Phalcon_Tag, setTitle){ } +/** + * Set the title separator of view content + * + * + * Phalcon\Tag::setTitleSeparator('-'); + * + * + * @param string $titleSeparator + */ +PHP_METHOD(Phalcon_Tag, setTitleSeparator){ + + zval *title_separator; + + phalcon_fetch_params(0, 1, 0, &title_separator); + + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator"), title_separator TSRMLS_CC); + +} + /** * Appends a text to current document title * @@ -1371,13 +1391,14 @@ PHP_METHOD(Phalcon_Tag, setTitle){ */ PHP_METHOD(Phalcon_Tag, appendTitle){ - zval *title, *t0, *r0; + zval *title, *document_title, *document_title_separator, *r0; phalcon_fetch_params(0, 1, 0, &title); - t0 = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC); + document_title = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC); + document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC); ALLOC_INIT_ZVAL(r0); - concat_function(r0, t0, title TSRMLS_CC); + PHALCON_CONCAT_VVV(r0, document_title, document_title_separator, title); phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitle"), r0 TSRMLS_CC); zval_ptr_dtor(&r0); } @@ -1389,14 +1410,15 @@ PHP_METHOD(Phalcon_Tag, appendTitle){ */ PHP_METHOD(Phalcon_Tag, prependTitle){ - zval *title, *document_title, *r0; + zval *title, *document_title, *document_title_separator, *r0; phalcon_fetch_params(0, 1, 0, &title); document_title = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC); + document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC); ALLOC_INIT_ZVAL(r0); - concat_function(r0, title, document_title TSRMLS_CC); + PHALCON_CONCAT_VVV(r0, title, document_title_separator, document_title); phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitle"), r0 TSRMLS_CC); zval_ptr_dtor(&r0); } diff --git a/ext/tag.h b/ext/tag.h index 27a25f0b8ef..7a219869d41 100644 --- a/ext/tag.h +++ b/ext/tag.h @@ -68,6 +68,7 @@ PHP_METHOD(Phalcon_Tag, textArea); PHP_METHOD(Phalcon_Tag, form); PHP_METHOD(Phalcon_Tag, endForm); PHP_METHOD(Phalcon_Tag, setTitle); +PHP_METHOD(Phalcon_Tag, setTitleSeparator); PHP_METHOD(Phalcon_Tag, appendTitle); PHP_METHOD(Phalcon_Tag, prependTitle); PHP_METHOD(Phalcon_Tag, getTitle); @@ -137,6 +138,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_settitle, 0, 0, 1) ZEND_ARG_INFO(0, title) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_settitleseparator, 0, 0, 1) + ZEND_ARG_INFO(0, separator) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_appendtitle, 0, 0, 1) ZEND_ARG_INFO(0, title) ZEND_END_ARG_INFO() @@ -230,6 +235,7 @@ PHALCON_INIT_FUNCS(phalcon_tag_method_entry){ PHP_ME(Phalcon_Tag, form, arginfo_phalcon_tag_form, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, endForm, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, setTitle, arginfo_phalcon_tag_settitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(Phalcon_Tag, setTitleSeparator, arginfo_phalcon_tag_settitleseparator, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, appendTitle, arginfo_phalcon_tag_appendtitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, prependTitle, arginfo_phalcon_tag_prependtitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, getTitle, arginfo_phalcon_tag_gettitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) diff --git a/unit-tests/TagTest.php b/unit-tests/TagTest.php new file mode 100644 index 00000000000..2ac7a387b48 --- /dev/null +++ b/unit-tests/TagTest.php @@ -0,0 +1,46 @@ + | + | Eduar Carvajal | + +------------------------------------------------------------------------+ +*/ + +use Phalcon\Tag as Tag; + +class TagTest extends PHPUnit_Framework_TestCase +{ + + public function testSetTitleSeparator() + { + + Tag::setTitle('Title'); + Tag::appendTitle('Class'); + + $this->assertEquals(Tag::getTitle(), 'TitleClass'.PHP_EOL); + + Tag::setTitle('Title'); + Tag::setTitleSeparator('|'); + Tag::appendTitle('Class'); + + $this->assertEquals(Tag::getTitle(), 'Title|Class'.PHP_EOL); + + Tag::setTitle('Title'); + Tag::setTitleSeparator('|'); + Tag::prependTitle('Class'); + + $this->assertEquals(Tag::getTitle(), 'Class|Title'.PHP_EOL); + } +} From 00a00f981f986af27daad4c0ec90fe6e9e644cb2 Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Fri, 11 Oct 2013 15:16:53 +0800 Subject: [PATCH 2/2] Add getTItleSeparator --- ext/tag.c | 20 ++++++++++++++++++++ ext/tag.h | 2 ++ unit-tests/TagTest.php | 1 + 3 files changed, 23 insertions(+) diff --git a/ext/tag.c b/ext/tag.c index 6749147058a..94cd1b14cc2 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -1451,6 +1451,26 @@ PHP_METHOD(Phalcon_Tag, getTitle){ } } +/** + * Gets the current document title separator + * + * + * echo Phalcon\Tag::getTitleSeparator(); + * + * + * + * {{ get_title_separator() }} + * + * + * @return string + */ +PHP_METHOD(Phalcon_Tag, getTitleSeparator){ + + zval *document_title_separator; + document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC); + RETURN_ZVAL(document_title_separator, 1, 0); +} + /** * Builds a LINK[rel="stylesheet"] tag * diff --git a/ext/tag.h b/ext/tag.h index 7a219869d41..045d87684cd 100644 --- a/ext/tag.h +++ b/ext/tag.h @@ -71,6 +71,7 @@ PHP_METHOD(Phalcon_Tag, setTitle); PHP_METHOD(Phalcon_Tag, setTitleSeparator); PHP_METHOD(Phalcon_Tag, appendTitle); PHP_METHOD(Phalcon_Tag, prependTitle); +PHP_METHOD(Phalcon_Tag, getTitleSeparator); PHP_METHOD(Phalcon_Tag, getTitle); PHP_METHOD(Phalcon_Tag, stylesheetLink); PHP_METHOD(Phalcon_Tag, javascriptInclude); @@ -239,6 +240,7 @@ PHALCON_INIT_FUNCS(phalcon_tag_method_entry){ PHP_ME(Phalcon_Tag, appendTitle, arginfo_phalcon_tag_appendtitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, prependTitle, arginfo_phalcon_tag_prependtitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, getTitle, arginfo_phalcon_tag_gettitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(Phalcon_Tag, getTitleSeparator, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, stylesheetLink, arginfo_phalcon_tag_stylesheetlink, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, javascriptInclude, arginfo_phalcon_tag_javascriptinclude, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Phalcon_Tag, image, arginfo_phalcon_tag_image, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) diff --git a/unit-tests/TagTest.php b/unit-tests/TagTest.php index 2ac7a387b48..bb8ff9f5bf1 100644 --- a/unit-tests/TagTest.php +++ b/unit-tests/TagTest.php @@ -36,6 +36,7 @@ public function testSetTitleSeparator() Tag::appendTitle('Class'); $this->assertEquals(Tag::getTitle(), 'Title|Class'.PHP_EOL); + $this->assertEquals(Tag::getTitleSeparator(), '|'); Tag::setTitle('Title'); Tag::setTitleSeparator('|');