$type
$type : \Phabstractic\Data\Types\Phabstractic\Data\Types\Type
The type of the data at any given moment.
Tagged Union Class - Defines A Dynamic Tagged Union
An instantiated TaggedUnion is a 'variable' that can hold only specifically defined data types, such as string, integer, resource, or object. One TaggedUnion for instance may only hold strings, and objects of a particular class. Code can detect what type a given TaggedUnion's value is at run time, thus enabling a form of 'data structure polymorphism'.
NOTE: since v3.0 restrictions aren't only configurable at construction
CHANGELOG
1.0: Created TaggedUnion - April 21st, 2013 Documented TaggedUnion - May 5th, 2013 1.1: public function getValue( $value ) -> getValue() - May 5th, 2013 2.0: Refactored and reformatted for Primus - April 11th, 2015 3.0: eliminated need for restrictions to only be defined at construction, reformatted for inclusion in phabstractic - July 18th, 2016
setRestrictions(\Phabstractic\Data\Types\Resource\FilterInterface $restrictions)
Set the restrictions
Allows any type of object that has an isAllowed method
\Phabstractic\Data\Types\Resource\FilterInterface | $restrictions |
__construct(\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\FilterInterface $restrictions)
Defines a TaggedUnion
OBSOLETE: This is the only place where you can define the data type restrictions of the tagged union.
Since v3 you can specify restrictions dynamically using setRestrictions
NOTE: $this->type will be of Type::BASIC_NULL until set regardless of restrictions.
\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\FilterInterface | $restrictions | The data restrictions |
set(mixed $value)
Sets the value, making sure it is allowed by the restrictions
Checks the value type of the given value, if it's allowed then sets both the type member and value member. Does not return true/false/null because those are values that may be passed. Throws errors instead if there's a problem setting the value.
mixed | $value | The value to set |
if the given value is untypeable
if the given value is not allowed