Newer
Older
Dries Buytaert
committed
<?php
/**
* @file
* Definition of Drupal\Core\Template\AttributeValueBase.
*/
namespace Drupal\Core\Template;
Alex Pott
committed
use Drupal\Component\Utility\String;
Dries Buytaert
committed
/**
* Defines the base class for an attribute type.
*
Alex Pott
committed
* @see \Drupal\Core\Template\Attribute
Dries Buytaert
committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
*/
abstract class AttributeValueBase {
/**
* 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;
/**
* Constructs a \Drupal\Core\Template\AttributeValueBase object.
*/
public function __construct($name, $value) {
$this->name = $name;
$this->value = $value;
}
/**
* Returns a string representation of the attribute.
*
* While __toString only returns the value in a string form, render()
* contains the name of the attribute as well.
*
* @return string
* The string representation of the attribute.
*/
public function render() {
Alex Pott
committed
return String::checkPlain($this->name) . '="' . $this . '"';
Dries Buytaert
committed
}
/**
* Whether this attribute hsa been printed already.
*
* @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();
}