Add isPristine method.

This commit is contained in:
Teddy Grenman
2009-09-03 16:04:17 +03:00
parent 682de86552
commit 85ba5125c9
3 changed files with 57 additions and 0 deletions

View File

@@ -149,6 +149,8 @@ class Memcached {
public function isPersistent( ) {}
public function isPristine( ) {}
}
class MemcachedException extends Exception {

View File

@@ -178,6 +178,7 @@ typedef struct {
} *obj;
bool is_persistent;
bool is_pristine;
int rescode;
int memc_errno;
} php_memc_t;
@@ -282,6 +283,7 @@ static PHP_METHOD(Memcached, __construct)
}
i_obj = (php_memc_t *) zend_object_store_get_object(object TSRMLS_CC);
i_obj->is_pristine = false;
if (persistent_id) {
zend_rsrc_list_entry *le = NULL;
@@ -317,6 +319,7 @@ static PHP_METHOD(Memcached, __construct)
m_obj->serializer = MEMC_G(serializer);
m_obj->compression = true;
i_obj->is_pristine = true;
if (is_persistent) {
zend_rsrc_list_entry le;
@@ -2015,6 +2018,23 @@ static PHP_METHOD(Memcached, isPersistent)
RETURN_BOOL(i_obj->is_persistent);
}
/* }}} */
/* {{{ Memcached::isPristine()
Returns the true if instance is recently created */
static PHP_METHOD(Memcached, isPristine)
{
MEMC_METHOD_INIT_VARS;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
return;
}
MEMC_METHOD_FETCH_OBJECT;
RETURN_BOOL(i_obj->is_pristine);
}
/* }}} */
/****************************************
Internal support code
@@ -2947,6 +2967,9 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_isPersistent, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_isPristine, 0)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ memcached_class_methods */
@@ -3002,6 +3025,7 @@ static zend_function_entry memcached_class_methods[] = {
MEMC_ME(setOptions, arginfo_setOptions)
MEMC_ME(isPersistent, arginfo_isPersistent)
MEMC_ME(isPristine, arginfo_isPristine)
{ NULL, NULL, NULL }
};
#undef MEMC_ME

View File

@@ -0,0 +1,31 @@
--TEST--
Check if persistent object is new or an old persistent one
--SKIPIF--
<?php if (!extension_loaded("memcached")) print "skip";
?>
--FILE--
<?php
$m1 = new Memcached('id1');
$m1->setOption(Memcached::OPT_PREFIX_KEY, "foo_");
var_dump($m1->isPristine());
$m1 = new Memcached('id1');
var_dump($m1->isPristine());
$m2 = new Memcached('id1');
var_dump($m2->isPristine());
// this change affects $m1
$m2->setOption(Memcached::OPT_PREFIX_KEY, "bar_");
$m3 = new Memcached('id2');
var_dump($m3->isPristine());
$m3 = new Memcached();
var_dump($m3->isPristine());
--EXPECT--
bool(true)
bool(false)
bool(false)
bool(true)
bool(true)