Skip to content

Commit

Permalink
Merge pull request #1639 from sjinks/issue-1637
Browse files Browse the repository at this point in the history
[1.3.0] Fix #1637
  • Loading branch information
Phalcon committed Dec 5, 2013
2 parents f1b0d5a + 11001ae commit c513fe3
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ext/di/injectable.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ PHP_METHOD(Phalcon_DI_Injectable, __get){
ZVAL_STRING(service, "sessionBag", 1);

phalcon_return_call_method_p2(dependency_injector, "get", service, arguments);
phalcon_update_property_this(this_ptr, SL("persistent"), (return_value_ptr ? *return_value_ptr : return_value) TSRMLS_CC);
zend_update_property(phalcon_di_injectable_ce, getThis(), SL("persistent"), (return_value_ptr ? *return_value_ptr : return_value) TSRMLS_CC);
RETURN_MM();
}

Expand Down
58 changes: 30 additions & 28 deletions ext/session/bag.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ PHALCON_INIT_CLASS(Phalcon_Session_Bag){
zend_declare_property_null(phalcon_session_bag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_session_bag_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_session_bag_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_session_bag_ce, SL("_initalized"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_session_bag_ce, SL("_initialized"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_session_bag_ce, SL("_session"), ZEND_ACC_PROTECTED TSRMLS_CC);

zend_class_implements(phalcon_session_bag_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_session_baginterface_ce);
Expand All @@ -77,16 +77,11 @@ PHALCON_INIT_CLASS(Phalcon_Session_Bag){
*/
PHP_METHOD(Phalcon_Session_Bag, __construct){

zval *name;
zval **name;

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

if (Z_TYPE_P(name) != IS_STRING) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_session_exception_ce, "The name parameter must be a string");
return;
}
phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC);

phalcon_fetch_params_ex(1, 0, &name);
PHALCON_ENSURE_IS_STRING(name);
phalcon_update_property_this(this_ptr, SL("_name"), *name TSRMLS_CC);
}

/**
Expand Down Expand Up @@ -161,7 +156,7 @@ PHP_METHOD(Phalcon_Session_Bag, initialize){
}

phalcon_update_property_this(this_ptr, SL("_data"), data TSRMLS_CC);
phalcon_update_property_bool(this_ptr, SL("_initalized"), 1 TSRMLS_CC);
phalcon_update_property_bool(this_ptr, SL("_initialized"), 1 TSRMLS_CC);

PHALCON_MM_RESTORE();
}
Expand All @@ -175,13 +170,13 @@ PHP_METHOD(Phalcon_Session_Bag, initialize){
*/
PHP_METHOD(Phalcon_Session_Bag, destroy){

zval *initalized, *name, *session;
zval *initialized, *name, *session;

PHALCON_MM_GROW();

PHALCON_OBS_VAR(initalized);
phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initalized)) {
PHALCON_OBS_VAR(initialized);
phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initialized)) {
phalcon_call_method_noret(this_ptr, "initialize");
}

Expand All @@ -207,16 +202,16 @@ PHP_METHOD(Phalcon_Session_Bag, destroy){
*/
PHP_METHOD(Phalcon_Session_Bag, set){

zval *property, *value, *initalized, *name, *data;
zval *property, *value, *initialized, *name, *data;
zval *session;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &property, &value);

PHALCON_OBS_VAR(initalized);
phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initalized)) {
PHALCON_OBS_VAR(initialized);
phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initialized)) {
phalcon_call_method_noret(this_ptr, "initialize");
}

Expand Down Expand Up @@ -261,7 +256,7 @@ PHALCON_DOC_METHOD(Phalcon_Session_Bag, __set);
*/
PHP_METHOD(Phalcon_Session_Bag, get){

zval *property, *default_value = NULL, *initalized;
zval *property, *default_value = NULL, *initialized;
zval *data, *value;

PHALCON_MM_GROW();
Expand All @@ -275,9 +270,9 @@ PHP_METHOD(Phalcon_Session_Bag, get){
/**
* Check first if the bag is initialized
*/
PHALCON_OBS_VAR(initalized);
phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initalized)) {
PHALCON_OBS_VAR(initialized);
phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initialized)) {
phalcon_call_method_noret(this_ptr, "initialize");
}

Expand Down Expand Up @@ -323,15 +318,15 @@ PHALCON_DOC_METHOD(Phalcon_Session_Bag, __get);
*/
PHP_METHOD(Phalcon_Session_Bag, has){

zval *property, *initalized, *data;
zval *property, *initialized, *data;

PHALCON_MM_GROW();

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

PHALCON_OBS_VAR(initalized);
phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initalized)) {
PHALCON_OBS_VAR(initialized);
phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initialized)) {
phalcon_call_method_noret(this_ptr, "initialize");
}

Expand Down Expand Up @@ -370,11 +365,18 @@ PHALCON_DOC_METHOD(Phalcon_Session_Bag, __isset);
PHP_METHOD(Phalcon_Session_Bag, remove){

zval *property, *data = NULL, *name, *session;
zval *initialized;

PHALCON_MM_GROW();

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


PHALCON_OBS_VAR(initialized);
phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(initialized)) {
phalcon_call_method_noret(this_ptr, "initialize");
}

PHALCON_OBS_VAR(data);
phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC);
if (phalcon_array_isset(data, property)) {
Expand Down
120 changes: 120 additions & 0 deletions ext/tests/issue-1637.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
--TEST--
Cannot Remove A Property From Phalcon Persistent Storage - https://github.com/phalcon/cphalcon/issues/1637
--SKIPIF--
<?php include('skipif.inc'); ?>
--GET--
dummy=1
--FILE--
<?php

class Test extends \Phalcon\Di\Injectable
{
public function test()
{
$this->persistent->destroy();
$this->dump('anu');
echo "Set\n";
$this->persistent->anu = 'Aloha';
$this->dump('anu');
echo "Remove\n";
$this->persistent->remove('anu');
$this->dump('anu');
echo "set\n";
$this->persistent->anu = 'Aloha';
$this->dump('anu');
echo "assign null\n";
$this->persistent->anu = null;
$this->dump('anu');
echo "set\n";
$this->persistent->anu = 'Aloha';
$this->dump('anu');
echo "destroy\n";
$this->persistent->destroy();
$this->dump('anu');
}

public function dump($v)
{
echo $v, '=', var_dump($this->persistent->$v);
echo 'has(', $v, ')=', var_dump($this->persistent->has($v));
echo 'isset(', $v, ')=', var_dump(isset($this->persistent->$v));
echo PHP_EOL;
}
}

$di = new \Phalcon\DI\FactoryDefault();
$di['session'] = function() { $s = new \Phalcon\Session\Adapter\Files(array('uniqueId' => 'issue-1575')); $s->start(); return $s; };

$test = new Test();
$test->test();

?>
--EXPECT--
anu=NULL
has(anu)=bool(false)
isset(anu)=bool(false)

Set
anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

Remove
anu=NULL
has(anu)=bool(false)
isset(anu)=bool(false)

set
anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

assign null
anu=NULL
has(anu)=bool(true)
isset(anu)=bool(true)

set
anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

destroy
anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

Set
anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

Remove
anu=NULL
has(anu)=bool(false)
isset(anu)=bool(false)

set
anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

assign null
anu=NULL
has(anu)=bool(true)
isset(anu)=bool(true)

set
anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

destroy
anu=string(5) "Aloha"
has(anu)=bool(true)
isset(anu)=bool(true)

0 comments on commit c513fe3

Please sign in to comment.