Class Kitab\Compiler\IntermediateRepresentation\Attribute
class Attribute
{
public function __construct(string $name);
public function __toString(): string;
}
An attribute intermediate representation.
An attribute is a property of a class like entity.
Examples
In this example, a new attribute foo
is built, with a protected
visibility, and a default value sets to 42.
$attribute = new Kitab\Compiler\IntermediateRepresentation\Attribute('foo');
$attribute->visibility = $attribute::VISIBILITY_PROTECTED;
$attribute->default = '42';
assert('protected $foo = 42' === (string) $attribute);
Constants
public const VISIBILITY_PUBLIC = 0;
-
Represent a public attribute.
public const VISIBILITY_PROTECTED = 1;
-
Represent a protected attribute.
public const VISIBILITY_PRIVATE = 2;
-
Represent a private private.
Attributes
public $visibility = self::VISIBILITY_PUBLIC;
-
The visibility of the attribute, represented by the
self::VISIBILITY_*
constants. public $static = false;
-
Represent whether the attribute is static or not.
public $name
-
Represent the name of the attribute, without the leading
$
. public $default = null;
-
A string containing only PHP code representing the default value of the attribute if any.
public $documentation = '';
-
Associated documentation of the attribute.
Methods
-
public function __construct(string $name)
-
Allocate an attribute with a name. This is the only mandatory information.
-
public function __toString(): string
-
Transform this intermediate representation into its PHP representation.
The original formatting is not kept. The applied formatting is designed for Kitab.