Skip to content

Commit

Permalink
Phalcon\Session\Bag fixes
Browse files Browse the repository at this point in the history
  * initalized => initialized
  * add initialization check to remove()
  * be less aggressive in __construct()
  • Loading branch information
sjinks committed Dec 5, 2013
1 parent 4807e84 commit 11001ae
Showing 1 changed file with 30 additions and 28 deletions.
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

0 comments on commit 11001ae

Please sign in to comment.