Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phalcon\Session\Adapter and Phalcon\Session\Bag improvements #1917

Merged
merged 19 commits into from Jan 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,16 @@
- Phalcon\Security::checkHash() now correctly handles non-bcrypt hashes (#1912)
- Phalcon\Session:
- Fix Phalcon\Session\Bag::remove() (#1637)
- Add remove() to Phalcon\Session\BagInterface (#1917)
- Phalcon\Session\Adapter::get() may optionally remove the data from session (#1358)
- Phalcon\Session\Adapter optimizations (#1624)
- Phalcon\Session\Adapter::__destruct() now calls session_write_close() (#1624)
- Phalcon\Session\AdapterInterface is compatible with SessionHandlerInterface (#1108)
- Phalcon\Session\Adapter now implements Phalcon\Session\AdapterInterface (#1852)
- Phalcon\Session\Bag::__get() now returns by reference (unlike get()) (#1895)
- Phalcon\Session\Bag implements ArrayAccess, Countable, IteratorAggregate interfaces (#1917)
- Phalcon\Session\Adapter implements ArrayAccess, Countable, IteratorAggregate interfaces (#1917)
- Optimized Phalcon\Session\Adapter using object handlers (#1917)
- Phalcon\Tag:
- Fixed bugs (#903)
- Fixed radio button generation (#947)
Expand Down
2 changes: 0 additions & 2 deletions ext/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,7 @@ static zend_object_value phalcon_config_object_ctor(zend_class_entry* ce TSRMLS_
zend_object_value retval;

zend_object_std_init(&obj->obj, ce TSRMLS_CC);
#if PHP_VERSION_ID >= 50400
object_properties_init(&obj->obj, ce);
#endif

ALLOC_HASHTABLE(obj->props);
zend_hash_init(obj->props, 0, NULL, ZVAL_PTR_DTOR, 0);
Expand Down
2 changes: 0 additions & 2 deletions ext/di.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,7 @@ static zend_object_value phalcon_di_ctor(zend_class_entry* ce TSRMLS_DC)
zend_object_value retval;

zend_object_std_init(&obj->obj, ce TSRMLS_CC);
#if PHP_VERSION_ID >= 50400
object_properties_init(&obj->obj, ce);
#endif

ALLOC_HASHTABLE(obj->services);
ALLOC_HASHTABLE(obj->shared);
Expand Down
126 changes: 126 additions & 0 deletions ext/internal/arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
| Vladimir Kolesnikov <vladimir@extrememember.com> |
+------------------------------------------------------------------------+
*/

#ifndef PHALCON_INTERNAL_ARGINFO_H
#define PHALCON_INTERNAL_ARGINFO_H

#include <Zend/zend.h>
#include <Zend/zend_API.h>


ZEND_BEGIN_ARG_INFO_EX(arginfo_empty, 0, 0, 0)
ZEND_END_ARG_INFO()


/** @brief & __get($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo___getref, 0, 1, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()

/** @brief __get($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo___get, 0, 0, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()

/** @brief __set($property, $value) */
ZEND_BEGIN_ARG_INFO_EX(arginfo___set, 0, 0, 2)
ZEND_ARG_INFO(0, property)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

/** @brief __isset($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo___isset, 0, 0, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()

/** @brief __unset($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo___unset, 0, 0, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()


/** @brief IteratorAggregate::getIterator() */
ZEND_BEGIN_ARG_INFO_EX(arginfo_iteratoraggregate_getiterator, 0, 0, 0)
ZEND_END_ARG_INFO()


/** @brief Countable::count() */
ZEND_BEGIN_ARG_INFO_EX(arginfo_countable_count, 0, 0, 0)
ZEND_END_ARG_INFO()


/** @brief ArrayAccess::offsetGet($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offsetget, 0, 0, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()

#if PHP_VERSION_ID >= 50304

/** @brief & ArrayAccess::offsetGet($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offsetgetref, 0, 1, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()

#else

/** @brief ArrayAccess::offsetGet($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offsetgetref, 0, 0, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()

#endif

/** @brief ArrayAccess::offsetSet($property, $value) */
ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offsetset, 0, 0, 2)
ZEND_ARG_INFO(0, property)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

/** @brief ArrayAccess::offsetExists($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offsetexists, 0, 0, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()

/** @brief ArrayAccess::offsetUnset($property) */
ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offsetunset, 0, 0, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()


/** @brief Iterator::current() */
ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_current, 0, 0, 0)
ZEND_END_ARG_INFO()

/** @brief Iterator::key() */
ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_key, 0, 0, 0)
ZEND_END_ARG_INFO()

/** @brief Iterator::next() */
ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_next, 0, 0, 0)
ZEND_END_ARG_INFO()

/** @brief Iterator::rewind() */
ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_rewind, 0, 0, 0)
ZEND_END_ARG_INFO()

/** @brief Iterator::valid() */
ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_valid, 0, 0, 0)
ZEND_END_ARG_INFO()

#endif /* PHALCON_INTERNAL_ARGINFO_H */
4 changes: 2 additions & 2 deletions ext/kernel/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ zval** phalcon_hash_get(HashTable *ht, zval *key, int type)
case BP_VAR_W: {
zval *value;
ALLOC_INIT_ZVAL(value);
zend_hash_index_update(ht, index, (void**)&value, sizeof(void*), NULL);
zend_hash_index_update(ht, index, (void**)&value, sizeof(void*), (void**)&ret);
break;
}
}
Expand Down Expand Up @@ -284,7 +284,7 @@ zval** phalcon_hash_get(HashTable *ht, zval *key, int type)
case BP_VAR_W: {
zval *value;
ALLOC_INIT_ZVAL(value);
zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key)+1, (void**)&value, sizeof(void*), NULL);
zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key)+1, (void**)&value, sizeof(void*), (void**)&ret);
break;
}
}
Expand Down
28 changes: 24 additions & 4 deletions ext/kernel/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,10 +1010,10 @@ int phalcon_update_property_array(zval *object, char *property, unsigned int pro

if (Z_TYPE_P(index) == IS_STRING) {
zend_symtable_update(Z_ARRVAL_P(tmp), Z_STRVAL_P(index), Z_STRLEN_P(index) + 1, &value, sizeof(zval*), NULL);
} else {
if (Z_TYPE_P(index) == IS_LONG) {
zend_hash_index_update(Z_ARRVAL_P(tmp), Z_LVAL_P(index), &value, sizeof(zval *), NULL);
}
} else if (Z_TYPE_P(index) == IS_LONG) {
zend_hash_index_update(Z_ARRVAL_P(tmp), Z_LVAL_P(index), &value, sizeof(zval *), NULL);
} else if (Z_TYPE_P(index) == IS_NULL) {
zend_hash_next_index_insert(Z_ARRVAL_P(tmp), (void**)&value, sizeof(zval*), NULL);
}

if (separated) {
Expand Down Expand Up @@ -1454,3 +1454,23 @@ int phalcon_property_decr(zval *object, char *property_name, unsigned int proper

return SUCCESS;
}

#if PHP_VERSION_ID < 50400

void object_properties_init(zend_object *object, zend_class_entry *class_type)
{
zval *tmp;

if (UNEXPECTED(!object->properties)) {
ALLOC_HASHTABLE(object->properties);
zend_hash_init(object->properties, zend_hash_num_elements(&class_type->default_properties), NULL, ZVAL_PTR_DTOR, 0);
}

#if PHP_VERSION_ID < 50304
zend_hash_copy(object->properties, &class_type->default_properties, (copy_ctor_func_t)zval_add_ref, (void*)&tmp, sizeof(zval*));
#else
zend_hash_copy(object->properties, &class_type->default_properties, zval_copy_property_ctor(class_type), (void*)&tmp, sizeof(zval*));
#endif
}

#endif
8 changes: 8 additions & 0 deletions ext/kernel/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
+------------------------------------------------------------------------+
*/

#ifndef PHALCON_KERNEL_OBJECT_H
#define PHALCON_KERNEL_OBJECT_H

/** Class Retrieving/Checking */
int phalcon_class_exists(const zval *class_name, int autoload TSRMLS_DC);
int phalcon_class_exists_ex(zend_class_entry **zce, const zval *class_name, int autoload TSRMLS_DC);
Expand Down Expand Up @@ -102,3 +105,8 @@ int phalcon_create_instance_params_ce(zval *return_value, zend_class_entry *ce,
int phalcon_create_instance(zval *return_value, const zval *class_name TSRMLS_DC);
int phalcon_create_instance_params(zval *return_value, const zval *class_name, zval *params TSRMLS_DC);

#if PHP_VERSION_ID < 50400
void object_properties_init(zend_object *object, zend_class_entry *class_type);
#endif

#endif /* PHALCON_KERNEL_OBJECT_H */
2 changes: 0 additions & 2 deletions ext/mvc/model/row.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ static zend_object_value phalcon_mvc_model_row_object_ctor(zend_class_entry* ce
zend_object_value retval;

zend_object_std_init(&obj->obj, ce TSRMLS_CC);
#if PHP_VERSION_ID >= 50400
object_properties_init(&obj->obj, ce);
#endif

ALLOC_HASHTABLE(obj->props);
zend_hash_init(obj->props, 0, NULL, ZVAL_PTR_DTOR, 0);
Expand Down
Loading