[prev in list] [next in list] [prev in thread] [next in thread] 

List:       phpdoc
Subject:    [PHP-DOC] cvs: php-src(PHP_5_3) / NEWS  /ext/spl spl_observer.c  /ext/spl/internal splobjectstorage.
From:       "Marcus Boerger" <helly () php ! net>
Date:       2008-01-28 22:48:15
Message-ID: cvshelly1201560495 () cvsserver
[Download RAW message or body]

helly		Mon Jan 28 22:48:15 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src	NEWS 
    /php-src/ext/spl	spl_observer.c 
    /php-src/ext/spl/internal	splobjectstorage.inc 
  Log:
  - MFH Make SplObjectStorage implement ArrayAccess
  [DOC]
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.93&r2=1.2027.2.547.2.965.2.94&diff_format=u
                
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.93 php-src/NEWS:1.2027.2.547.2.965.2.94
--- php-src/NEWS:1.2027.2.547.2.965.2.93	Mon Jan 28 21:12:41 2008
+++ php-src/NEWS	Mon Jan 28 22:48:15 2008
@@ -24,8 +24,11 @@
     DateTimeZone::getTranstions() to limit the range of transitions being
     returned.
 
-- Added ability to store associative infor with objects in SplObjectStorage.
-  (Marcus)
+- Improved SPL extension:
+  . Added ability to store associative information with objects in 
+    SplObjectStorage. (Marcus)
+  . Added ArrayAccess support to SplObjectStorage. (Marcus)
+  . Added SplDoublyLinkedList, SplStack, SplQueue classes. (Etienne)
 - Added ability to use Traversable objects instead of plain arrays in ext/soap.
   (Joshua Reese, Dmitry)
 - Added "?:" operator. (Marcus)
@@ -51,7 +54,6 @@
   (Etienne Kneuss)
 - Added "compact" handler for Zend MM storage. (Dmitry)
 - Added "+" and "*" specifiers to zend_parse_parameters(). (Andrei)
-- Added SplDoublyLinkedList, SplStack, SplQueue classes. (Etienne)
 
 - Removed the experimental RPL (master/slave) functions from mysqli. (Andrey)
 
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_observer.c?r1=1.2.2.6.2.3.2.6&r2=1.2.2.6.2.3.2.7&diff_format=u
                
Index: php-src/ext/spl/spl_observer.c
diff -u php-src/ext/spl/spl_observer.c:1.2.2.6.2.3.2.6 \
                php-src/ext/spl/spl_observer.c:1.2.2.6.2.3.2.7
--- php-src/ext/spl/spl_observer.c:1.2.2.6.2.3.2.6	Sun Jan 27 18:07:20 2008
+++ php-src/ext/spl/spl_observer.c	Mon Jan 28 22:48:15 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_observer.c,v 1.2.2.6.2.3.2.6 2008/01/27 18:07:20 helly Exp $ */
+/* $Id: spl_observer.c,v 1.2.2.6.2.3.2.7 2008/01/28 22:48:15 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -288,6 +288,25 @@
 	intern->index = 0;
 } /* }}} */
 
+/* {{{ proto mixed SplObjectStorage::offsetGet($object)
+ 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)
  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.2.2.2.4.2&r2=1.2.2.2.4.3&diff_format=u
                
Index: php-src/ext/spl/internal/splobjectstorage.inc
diff -u php-src/ext/spl/internal/splobjectstorage.inc:1.2.2.2.4.2 \
                php-src/ext/spl/internal/splobjectstorage.inc:1.2.2.2.4.3
--- php-src/ext/spl/internal/splobjectstorage.inc:1.2.2.2.4.2	Sun Jan 27 18:07:20 \
                2008
+++ php-src/ext/spl/internal/splobjectstorage.inc	Mon Jan 28 22:48:15 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);
+	}
 }
 
 ?>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic