Skip to content

Commit

Permalink
Merge pull request #1581 from sjinks/issue-1575
Browse files Browse the repository at this point in the history
Fix #1575
  • Loading branch information
Phalcon committed Nov 22, 2013
2 parents e796e0c + 920e9f2 commit 442665f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
27 changes: 21 additions & 6 deletions ext/flash/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ PHP_METHOD(Phalcon_Flash_Session, message){
PHP_METHOD(Phalcon_Flash_Session, getMessages){

zval *type = NULL, *remove = NULL, *messages, *return_messages;
zval *do_remove;

PHALCON_MM_GROW();

Expand All @@ -213,13 +214,27 @@ PHP_METHOD(Phalcon_Flash_Session, getMessages){
if (!remove) {
remove = PHALCON_GLOBAL(z_true);
}

PHALCON_INIT_VAR(messages);
phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", remove);
if (Z_TYPE_P(messages) == IS_ARRAY) {
if (likely(Z_TYPE_P(type) == IS_STRING)) {

if (Z_TYPE_P(type) != IS_NULL) {
do_remove = PHALCON_GLOBAL(z_false);
}
else {
do_remove = remove;
}

PHALCON_OBS_VAR(messages);
phalcon_call_method_p1_ex(messages, &messages, this_ptr, "_getsessionmessages", do_remove);
if (Z_TYPE_P(messages) == IS_ARRAY) {
if (likely(Z_TYPE_P(type) != IS_NULL)) {
if (phalcon_array_isset_fetch(&return_messages, messages, type)) {
RETURN_CTOR(return_messages);
RETVAL_ZVAL(return_messages, 1, 0);
if (zend_is_true(remove)) {
phalcon_array_unset(&messages, type, 0);
phalcon_call_method_p1_noret(this_ptr, "_setsessionmessages", messages);
}

PHALCON_MM_RESTORE();
return;
}

RETURN_MM_EMPTY_ARRAY();
Expand Down
43 changes: 43 additions & 0 deletions ext/tests/issue-1575.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
flashSession->getMessages(type, BOOLEAN remove) removed all messages - https://github.com/phalcon/cphalcon/issues/1575
--GET--
dummy=1
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
$di = new \Phalcon\DI\FactoryDefault();
$s = new \Phalcon\Session\Adapter\Files(array('uniqueId' => 'issue-1575'));
var_dump($s->start());
$fs = $di->getShared('flashSession');
$fs->success('Success');
$fs->warning('Warning');
var_dump($fs->getMessages(null, false));
$fs->getMessages('success', true);
var_dump($fs->getMessages(null, false));
$fs->getMessages(null, true);
var_dump($fs->getMessages(null, false));
?>
--EXPECT--
bool(true)
array(2) {
["success"]=>
array(1) {
[0]=>
string(7) "Success"
}
["warning"]=>
array(1) {
[0]=>
string(7) "Warning"
}
}
array(1) {
["warning"]=>
array(1) {
[0]=>
string(7) "Warning"
}
}
array(0) {
}

0 comments on commit 442665f

Please sign in to comment.