diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 1708180..459bb9d 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\Template; + use ArrayAccess; use IteratorAggregate; @@ -37,20 +38,35 @@ use IteratorAggregate; * @see drupal_attributes() */ class Attribute implements ArrayAccess, IteratorAggregate { + + /** + * Stores the attribute data. + * + * @var array + */ protected $storage = array(); + /** + * Implements the magic __construct() method. + */ public function __construct($attributes = array()) { foreach ($attributes as $name => $value) { $this->offsetSet($name, $value); } } + /** + * Implements ArrayAccess::offsetGet(). + */ public function offsetGet($name) { if (isset($this->storage[$name])) { return $this->storage[$name]; } } + /** + * Implements ArrayAccess::offsetSet(). + */ public function offsetSet($name, $value) { if (is_array($value)) { $value = new AttributeArray($name, $value); @@ -70,14 +86,23 @@ class Attribute implements ArrayAccess, IteratorAggregate { } } + /** + * Implements ArrayAccess::offsetUnset(). + */ public function offsetUnset($name) { unset($this->storage[$name]); } + /** + * Implements ArrayAccess::offsetExists(). + */ public function offsetExists($name) { return isset($this->storage[$name]); } + /** + * Implements the magic __toString() method. + */ public function __toString() { $return = ''; foreach ($this->storage as $name => $value) { @@ -91,6 +116,9 @@ class Attribute implements ArrayAccess, IteratorAggregate { return $return; } + /** + * Implements the magic __clone() method. + */ public function __clone() { foreach ($this->storage as $name => $value) { if (is_object($value)) { @@ -99,6 +127,9 @@ class Attribute implements ArrayAccess, IteratorAggregate { } } + /** + * Implements IteratorAggregate::getIterator(). + */ public function getIterator() { return new ArrayIterator($this->storage); } @@ -109,4 +140,5 @@ class Attribute implements ArrayAccess, IteratorAggregate { public function value() { return $this->value; } + } diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index b6dc889..d4f8771 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -5,6 +5,11 @@ * Definition of Drupal\Core\Template\AttributeArray. */ +namespace Drupal\Core\Template; + +use ArrayAccess; +use IteratorAggregate; + /** * A class that defines a type of Attribute that can be added to as an array. * @@ -23,15 +28,18 @@ * * @see Drupal\Core\Template\Attribute */ -namespace Drupal\Core\Template; -use ArrayAccess; -use IteratorAggregate; - class AttributeArray extends AttributeValueBase implements ArrayAccess, IteratorAggregate { + + /** + * Implements ArrayAccess::offsetGet(). + */ public function offsetGet($offset) { return $this->value[$offset]; } + /** + * Implements ArrayAccess::offsetSet(). + */ public function offsetSet($offset, $value) { if (isset($offset)) { $this->value[$offset] = $value; @@ -41,19 +49,31 @@ class AttributeArray extends AttributeValueBase implements ArrayAccess, Iterator } } + /** + * Implements ArrayAccess::offsetUnset(). + */ public function offsetUnset($offset) { unset($this->value[$offset]); } + /** + * Implements ArrayAccess::offsetExists(). + */ public function offsetExists($offset) { return isset($this->value[$offset]); } + /** + * Implements the magic __toString() method. + */ public function __toString() { $this->printed = TRUE; return implode(' ', array_map('check_plain', $this->value)); } + /** + * Implements IteratorAggregate::getIterator(). + */ public function getIterator() { return new ArrayIterator($this->value); } @@ -64,4 +84,5 @@ class AttributeArray extends AttributeValueBase implements ArrayAccess, Iterator public function value() { return $this->value; } + } diff --git a/core/lib/Drupal/Core/Template/AttributeBoolean.php b/core/lib/Drupal/Core/Template/AttributeBoolean.php index 8886ff5..48ca388 100644 --- a/core/lib/Drupal/Core/Template/AttributeBoolean.php +++ b/core/lib/Drupal/Core/Template/AttributeBoolean.php @@ -28,11 +28,20 @@ namespace Drupal\Core\Template; * @see Drupal\Core\Template\Attribute */ class AttributeBoolean extends AttributeValueBase { + + /** + * Overrides AttributeValueBase::render(). + */ public function render() { return $this->__toString(); } + + /** + * Implements the magic __toString() method. + */ public function __toString() { $this->printed = TRUE; return $this->value === FALSE ? '' : check_plain($this->name); } + } diff --git a/core/lib/Drupal/Core/Template/AttributeString.php b/core/lib/Drupal/Core/Template/AttributeString.php index cee327a..9776467 100644 --- a/core/lib/Drupal/Core/Template/AttributeString.php +++ b/core/lib/Drupal/Core/Template/AttributeString.php @@ -23,8 +23,13 @@ namespace Drupal\Core\Template; * @see Drupal\Core\Template\Attribute */ class AttributeString extends AttributeValueBase { + + /** + * Implements the magic __toString() method. + */ public function __toString() { $this->printed = TRUE; return check_plain($this->value); } + } diff --git a/core/lib/Drupal/Core/Template/AttributeValueBase.php b/core/lib/Drupal/Core/Template/AttributeValueBase.php index 4b04f4a..e54a1e5 100644 --- a/core/lib/Drupal/Core/Template/AttributeValueBase.php +++ b/core/lib/Drupal/Core/Template/AttributeValueBase.php @@ -13,8 +13,31 @@ namespace Drupal\Core\Template; * @see Drupal\Core\Template\Attribute */ abstract class AttributeValueBase { - protected $printed = FALSE, $value, $name; + /** + * Whether this attribute hsa been printed already. + * + * @var bool + */ + protected $printed = FALSE; + + /** + * The value itself. + * + * @var mixed + */ + protected $value; + + /** + * The name of the value. + * + * @var mixed + */ + protected $name; + + /** + * Implements the magic __construct() method. + */ public function __construct($name, $value) { $this->name = $name; $this->value = $value; @@ -26,7 +49,7 @@ abstract class AttributeValueBase { * While __toString only returns the value in a string form, render() * contains the name of the attribute as well. * - * @return + * @return string * The string representation of the attribute. */ public function render() { @@ -36,11 +59,16 @@ abstract class AttributeValueBase { /** * Whether this attribute hsa been printed already. * - * @return + * @return bool * TRUE if this attribute has been printed, FALSE otherwise. */ public function printed() { return $this->printed; } + + /** + * Implements the magic __toString() method. + */ abstract function __toString(); + }