helly Mon Jan 28 22:43:21 2008 UTC Modified files: /php-src/ext/spl spl_observer.c /php-src/ext/spl/internal splobjectstorage.inc Log: - Make SplObjectStorage implement ArrayAccess http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_observer.c?r1=1.22&r2=1.23&diff_format=u Index: php-src/ext/spl/spl_observer.c diff -u php-src/ext/spl/spl_observer.c:1.22 php-src/ext/spl/spl_observer.c:1.23 --- php-src/ext/spl/spl_observer.c:1.22 Sun Jan 27 18:04:54 2008 +++ php-src/ext/spl/spl_observer.c Mon Jan 28 22:43:21 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_observer.c,v 1.22 2008/01/27 18:04:54 helly Exp $ */ +/* $Id: spl_observer.c,v 1.23 2008/01/28 22:43:21 helly Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -288,6 +288,25 @@ intern->index = 0; } /* }}} */ +/* {{{ proto mixed SplObjectStorage::offsetGet($object) U + Returns associated information for a stored object */ +SPL_METHOD(SplObjectStorage, offsetGet) +{ + zval *obj; + spl_SplObjectStorageElement *element; + spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { + return; + } + element = spl_object_storage_get(intern, obj TSRMLS_CC); + if (!element) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Object not found"); + } else { + RETURN_ZVAL(element->inf,1, 0); + } +} /* }}} */ + /* {{{ proto bool SplObjectStorage::contains($obj) U Determine whethe an object is contained in the storage */ SPL_METHOD(SplObjectStorage, contains) @@ -565,20 +584,39 @@ ZEND_ARG_INFO(0, info) ZEND_END_ARG_INFO(); +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) + ZEND_ARG_INFO(0, object) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) + ZEND_ARG_INFO(0, object) + ZEND_ARG_INFO(0, info) +ZEND_END_ARG_INFO() + static const zend_function_entry spl_funcs_SplObjectStorage[] = { SPL_ME(SplObjectStorage, attach, arginfo_attach, 0) SPL_ME(SplObjectStorage, detach, arginfo_Object, 0) SPL_ME(SplObjectStorage, contains, arginfo_Object, 0) + SPL_ME(SplObjectStorage, getInfo, NULL, 0) + SPL_ME(SplObjectStorage, setInfo, arginfo_setInfo, 0) + /* Countable */ SPL_ME(SplObjectStorage, count, NULL, 0) + /* Iterator */ SPL_ME(SplObjectStorage, rewind, NULL, 0) SPL_ME(SplObjectStorage, valid, NULL, 0) SPL_ME(SplObjectStorage, key, NULL, 0) SPL_ME(SplObjectStorage, current, NULL, 0) SPL_ME(SplObjectStorage, next, NULL, 0) + /* Serializable */ SPL_ME(SplObjectStorage, unserialize, arginfo_Serialized, 0) SPL_ME(SplObjectStorage, serialize, NULL, 0) - SPL_ME(SplObjectStorage, getInfo, NULL, 0) - SPL_ME(SplObjectStorage, setInfo, arginfo_setInfo, 0) + /* ArrayAccess */ + SPL_MA(SplObjectStorage, offsetExists, SplObjectStorage, contains, arginfo_offsetGet, 0) + SPL_MA(SplObjectStorage, offsetSet, SplObjectStorage, attach, arginfo_offsetSet, 0) + SPL_MA(SplObjectStorage, offsetUnset, SplObjectStorage, detach, arginfo_offsetGet, 0) + SPL_ME(SplObjectStorage, offsetGet, arginfo_offsetGet, 0) {NULL, NULL, NULL} }; @@ -595,6 +633,7 @@ REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Countable); REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Iterator); REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Serializable); + REGISTER_SPL_IMPLEMENTS(SplObjectStorage, ArrayAccess); return SUCCESS; } http://cvs.php.net/viewvc.cgi/php-src/ext/spl/internal/splobjectstorage.inc?r1=1.5&r2=1.6&diff_format=u Index: php-src/ext/spl/internal/splobjectstorage.inc diff -u php-src/ext/spl/internal/splobjectstorage.inc:1.5 php-src/ext/spl/internal/splobjectstorage.inc:1.6 --- php-src/ext/spl/internal/splobjectstorage.inc:1.5 Sun Jan 27 18:04:54 2008 +++ php-src/ext/spl/internal/splobjectstorage.inc Mon Jan 28 22:43:21 2008 @@ -20,7 +20,7 @@ * here therefore has a complexity of O(n) while the actual implementation has * complexity O(1). */ -class SplObjectStorage implements Iterator, Countable +class SplObjectStorage implements Iterator, Countable, ArrayAccess { private $storage = array(); private $index = 0; @@ -88,9 +88,9 @@ return count($this->storage); } - /** @param obj object to look for + /** @param $obj object to look for * @return whether $obj is contained in storage - */ + */ function contains($obj) { if (is_object($obj)) @@ -106,7 +106,9 @@ return false; } - /** @param $obj new object to attach to storage if not yet contained + /** @param $obj new object to attach to storage or object whose + * associative information is to be replaced + * @param $inf associative information stored along the object */ function attach($obj, $inf = NULL) { @@ -133,6 +135,54 @@ } } } + + /** @param $obj new object to attach to storage or object whose + * associative information is to be replaced + * @param $inf associative information stored along the object + * @since 5.3.0 + */ + function offsetSet($obj, $inf) + { + $this->attach($obj, $inf); + } + + /** @param $obj Exising object to look for + * @return associative information stored with object + * @throw UnexpectedValueException if Object $obj is not contained in + * storage + * @since 5.3.0 + */ + function offsetGet($obj) + { + if (is_object($obj)) + { + foreach($this->storage as $idx => $element) + { + if ($object === $element[0]) + { + return $element[1]; + } + } + } + throw new UnexpectedValueException('Object not found'); + } + + /** @param $obj Exising object to look for + * @return associative information stored with object + * @since 5.3.0 + */ + function offsetUnset($obj) + { + $this->detach($obj); + } + + /** @param $obj object to look for + * @return whether $obj is contained in storage + */ + function offsetEsists($obj) + { + return $this->contains($obj); + } } ?>
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php