]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2597: Pulled identical {{{Iterator}}} and {{{ArrayAccess}}} implementations...
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 30 Oct 2010 23:28:11 +0000 (23:28 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 30 Oct 2010 23:28:11 +0000 (23:28 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7154 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggData.php
engine/classes/ElggEntity.php
engine/classes/ElggExtender.php
engine/classes/ElggRelationship.php

index 5f152024cab4b177e5cb252a04ccf2011b316bbc..f200a7c216d5b2fd0145ef7c095f1d72cc96b8c4 100644 (file)
@@ -1,5 +1,149 @@
 <?php
-abstract class ElggData
+abstract class ElggData implements
+       Iterator,       // Override foreach behaviour
+       ArrayAccess // Override for array access
 {
+       /**
+        * The main attributes of an entity.
+        * Holds attributes to save to database
+        * This contains the site's main properties (id, etc)
+        * Blank entries for all database fields should be created by the constructor.
+        * Subclasses should add to this in their constructors.
+        * Any field not appearing in this will be viewed as a
+        */
+       protected $attributes;
        
+       /*
+        * ITERATOR INTERFACE
+        */
+
+       /*
+        * This lets an entity's attributes be displayed using foreach as a normal array.
+        * Example: http://www.sitepoint.com/print/php5-standard-library
+        */
+       protected $valid = FALSE;
+
+       /**
+        * Iterator interface
+        *
+        * @see Iterator::rewind()
+        *
+        * @return void
+        */
+       public function rewind() {
+               $this->valid = (FALSE !== reset($this->attributes));
+       }
+
+       /**
+        * Iterator interface
+        *
+        * @see Iterator::current()
+        *
+        * @return void
+        */
+       public function current() {
+               return current($this->attributes);
+       }
+
+       /**
+        * Iterator interface
+        *
+        * @see Iterator::key()
+        *
+        * @return void
+        */
+       public function key() {
+               return key($this->attributes);
+       }
+
+       /**
+        * Iterator interface
+        *
+        * @see Iterator::next()
+        *
+        * @return void
+        */
+       public function next() {
+               $this->valid = (FALSE !== next($this->attributes));
+       }
+
+       /**
+        * Iterator interface
+        *
+        * @see Iterator::valid()
+        *
+        * @return void
+        */
+       public function valid() {
+               return $this->valid;
+       }
+
+       /*
+        * ARRAY ACCESS INTERFACE
+        */
+
+       /*
+        * This lets an entity's attributes be accessed like an associative array.
+        * Example: http://www.sitepoint.com/print/php5-standard-library
+        */
+
+       /**
+        * Array access interface
+        *
+        * @see ArrayAccess::offsetSet()
+        *
+        * @param mixed $key   Name
+        * @param mixed $value Value
+        *
+        * @return void
+        */
+       public function offsetSet($key, $value) {
+               if (array_key_exists($key, $this->attributes)) {
+                       $this->attributes[$key] = $value;
+               }
+       }
+
+       /**
+        * Array access interface
+        *
+        * @see ArrayAccess::offsetGet()
+        *
+        * @param mixed $key Name
+        *
+        * @return void
+        */
+       public function offsetGet($key) {
+               if (array_key_exists($key, $this->attributes)) {
+                       return $this->attributes[$key];
+               }
+       }
+
+       /**
+        * Array access interface
+        *
+        * @see ArrayAccess::offsetUnset()
+        *
+        * @param mixed $key Name
+        *
+        * @return void
+        */
+       public function offsetUnset($key) {
+               if (array_key_exists($key, $this->attributes)) {
+                       // Full unsetting is dangerous for our objects
+                       $this->attributes[$key] = "";
+               }
+       }
+
+       /**
+        * Array access interface
+        *
+        * @see ArrayAccess::offsetExists()
+        *
+        * @param int $offset Offset
+        *
+        * @return int
+        */
+       public function offsetExists($offset) {
+               return array_key_exists($offset, $this->attributes);
+       }
 }
\ No newline at end of file
index 3d0e112f30c67c155678a79267fca49d0d430fb0..56ac96f8f53d383e8dcb88bfe3cddb59dc88f837 100644 (file)
@@ -31,17 +31,8 @@ abstract class ElggEntity extends ElggData implements
        Locatable,  // Geocoding interface
        Exportable, // Allow export of data
        Importable, // Allow import of data
-       Loggable,       // Can events related to this object class be logged
-       Iterator,       // Override foreach behaviour
-       ArrayAccess // Override for array access
+       Loggable        // Can events related to this object class be logged
 {
-       /**
-        * The main attributes of an entity.
-        * Blank entries for all database fields should be created by the constructor.
-        * Subclasses should add to this in their constructors.
-        * Any field not appearing in this will be viewed as a
-        */
-       protected $attributes;
 
        /**
         * If set, overrides the value of getURL()
@@ -1383,138 +1374,4 @@ abstract class ElggEntity extends ElggData implements
 
                return $entity_tags;
        }
-
-       /*
-        * ITERATOR INTERFACE
-        */
-
-       /*
-        * This lets an entity's attributes be displayed using foreach as a normal array.
-        * Example: http://www.sitepoint.com/print/php5-standard-library
-        */
-       private $valid = FALSE;
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::rewind()
-        *
-        * @return void
-        */
-       function rewind() {
-               $this->valid = (FALSE !== reset($this->attributes));
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::current()
-        *
-        * @return void
-        */
-       function current() {
-               return current($this->attributes);
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::key()
-        *
-        * @return void
-        */
-       function key() {
-               return key($this->attributes);
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::next()
-        *
-        * @return void
-        */
-       function next() {
-               $this->valid = (FALSE !== next($this->attributes));
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::valid()
-        *
-        * @return void
-        */
-       function valid() {
-               return $this->valid;
-       }
-
-       /*
-        * ARRAY ACCESS INTERFACE
-        */
-
-       /*
-        * This lets an entity's attributes be accessed like an associative array.
-        * Example: http://www.sitepoint.com/print/php5-standard-library
-        */
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetSet()
-        *
-        * @param mixed $key   Name
-        * @param mixed $value Value
-        *
-        * @return void
-        */
-       function offsetSet($key, $value) {
-               if (array_key_exists($key, $this->attributes)) {
-                       $this->attributes[$key] = $value;
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetGet()
-        *
-        * @param mixed $key Name
-        *
-        * @return void
-        */
-       function offsetGet($key) {
-               if (array_key_exists($key, $this->attributes)) {
-                       return $this->attributes[$key];
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetUnset()
-        *
-        * @param mixed $key Name
-        *
-        * @return void
-        */
-       function offsetUnset($key) {
-               if (array_key_exists($key, $this->attributes)) {
-                       // Full unsetting is dangerous for our objects
-                       $this->attributes[$key] = "";
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetExists()
-        *
-        * @param int $offset Offset
-        *
-        * @return int
-        */
-       function offsetExists($offset) {
-               return array_key_exists($offset, $this->attributes);
-       }
 }
\ No newline at end of file
index 707906bac7b601fe895086686e6aa8e68b222a19..d6ea14ba8edd5fbd9bc2d537df426aaddb7834fd 100644 (file)
  */
 abstract class ElggExtender extends ElggData implements
        Exportable,
-       Loggable,       // Can events related to this object class be logged
-       Iterator,       // Override foreach behaviour
-       ArrayAccess // Override for array access
+       Loggable        // Can events related to this object class be logged
 {
-       /**
-        * Holds attributes to save to database
-        *
-        * @var array
-        */
-       protected $attributes;
-
+       
        /**
         * Returns an attribute
         *
@@ -231,138 +223,4 @@ abstract class ElggExtender extends ElggData implements
                return $this->name;
        }
 
-
-       /*
-        * ITERATOR INTERFACE
-        */
-
-       /*
-        * This lets an entity's attributes be displayed using foreach as a normal array.
-        * Example: http://www.sitepoint.com/print/php5-standard-library
-        */
-       private $valid = FALSE;
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::rewind()
-        *
-        * @return void
-        */
-       function rewind() {
-               $this->valid = (FALSE !== reset($this->attributes));
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::current()
-        *
-        * @return void
-        */
-       function current() {
-               return current($this->attributes);
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::key()
-        *
-        * @return void
-        */
-       function key() {
-               return key($this->attributes);
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::next()
-        *
-        * @return void
-        */
-       function next() {
-               $this->valid = (FALSE !== next($this->attributes));
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::valid()
-        *
-        * @return void
-        */
-       function valid() {
-               return $this->valid;
-       }
-
-       /*
-        * ARRAY ACCESS INTERFACE
-        */
-
-       /*
-        * This lets an entity's attributes be accessed like an associative array.
-        * Example: http://www.sitepoint.com/print/php5-standard-library
-        */
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetSet()
-        *
-        * @param mixed $key   Name
-        * @param mixed $value Value
-        *
-        * @return void
-        */
-       function offsetSet($key, $value) {
-               if (array_key_exists($key, $this->attributes)) {
-                       $this->attributes[$key] = $value;
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetGet()
-        *
-        * @param mixed $key Name
-        *
-        * @return void
-        */
-       function offsetGet($key) {
-               if (array_key_exists($key, $this->attributes)) {
-                       return $this->attributes[$key];
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetUnset()
-        *
-        * @param mixed $key Name
-        *
-        * @return void
-        */
-       function offsetUnset($key) {
-               if (array_key_exists($key, $this->attributes)) {
-                       // Full unsetting is dangerious for our objects
-                       $this->attributes[$key] = "";
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetExists()
-        *
-        * @param int $offset Offset
-        *
-        * @return int
-        */
-       function offsetExists($offset) {
-               return array_key_exists($offset, $this->attributes);
-       }
 }
index c072e1cc66c188f3d71303b2deba0283dbaf2851..e2b0e4e1321169b59f4543c5c3323663caf32ff2 100644 (file)
@@ -8,15 +8,8 @@
 class ElggRelationship extends ElggData implements
        Importable,
        Exportable,
-       Loggable,       // Can events related to this object class be logged
-       Iterator,       // Override foreach behaviour
-       ArrayAccess // Override for array access
-       {
-       /**
-        * This contains the site's main properties (id, etc)
-        * @var array
-        */
-       protected $attributes;
+       Loggable        // Can events related to this object class be logged
+{
 
        /**
         * Construct a new site object, optionally from a given id value or row.
@@ -247,132 +240,4 @@ class ElggRelationship extends ElggData implements
                return $this->relationship;
        }
 
-       // ITERATOR INTERFACE //////////////////////////////////////////////////////////////
-       /*
-        * This lets an entity's attributes be displayed using foreach as a normal array.
-        * Example: http://www.sitepoint.com/print/php5-standard-library
-        */
-
-       private $valid = FALSE;
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::rewind()
-        *
-        * @return void
-        */
-       function rewind() {
-               $this->valid = (FALSE !== reset($this->attributes));
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::current()
-        *
-        * @return void
-        */
-       function current() {
-               return current($this->attributes);
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::key()
-        *
-        * @return void
-        */
-       function key() {
-               return key($this->attributes);
-       }
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::next()
-        *
-        * @return void
-        */
-       function next() {
-               $this->valid = (FALSE !== next($this->attributes));
-       }
-
-
-       /**
-        * Iterator interface
-        *
-        * @see Iterator::valid()
-        *
-        * @return void
-        */
-       function valid() {
-               return $this->valid;
-       }
-
-       // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
-       /*
-        * This lets an entity's attributes be accessed like an associative array.
-        * Example: http://www.sitepoint.com/print/php5-standard-library
-        */
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetSet()
-        *
-        * @param mixed $key   Name
-        * @param mixed $value Value
-        *
-        * @return void
-        */
-       function offsetSet($key, $value) {
-               if (array_key_exists($key, $this->attributes)) {
-                       $this->attributes[$key] = $value;
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetGet()
-        *
-        * @param mixed $key Name
-        *
-        * @return void
-        */
-       function offsetGet($key) {
-               if (array_key_exists($key, $this->attributes)) {
-                       return $this->attributes[$key];
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetUnset()
-        *
-        * @param mixed $key Name
-        *
-        * @return void
-        */
-       function offsetUnset($key) {
-               if (array_key_exists($key, $this->attributes)) {
-                       $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects
-               }
-       }
-
-       /**
-        * Array access interface
-        *
-        * @see ArrayAccess::offsetExists()
-        *
-        * @param int $offset Offset
-        *
-        * @return int
-        */
-       function offsetExists($offset) {
-               return array_key_exists($offset, $this->attributes);
-       }
 }
\ No newline at end of file