final class Token in Hook Event Dispatcher 8
Token ValueObject.
Convenience object to handle the integrity and assembly of tokens.
Hierarchy
- class \Drupal\hook_event_dispatcher\Value\Token
Expanded class hierarchy of Token
4 files declare their use of Token
- ExampleTokenEventSubscriber.php in src/
Example/ ExampleTokenEventSubscriber.php - TokenEventTest.php in tests/
src/ Unit/ Token/ TokenEventTest.php - TokensInfoEvent.php in src/
Event/ Token/ TokensInfoEvent.php - TokenTest.php in tests/
src/ Unit/ Token/ TokenTest.php
File
- src/
Value/ Token.php, line 14
Namespace
Drupal\hook_event_dispatcher\ValueView source
final class Token {
/**
* Type.
*
* @var string
*/
private $type;
/**
* Token.
*
* @var string
*/
private $token;
/**
* Description.
*
* @var string
*/
private $description;
/**
* Name.
*
* @var string|\Drupal\Component\Render\MarkupInterface
*/
private $name;
/**
* Is a dynamic field.
*
* @var bool
*/
private $dynamic = FALSE;
/**
* Use create function instead.
*/
private function __construct() {
}
/**
* Token factory function.
*
* @param string $type
* The group name, like 'node'.
* @param string $token
* The token, like 'url' or 'id'.
* @param string|\Drupal\Component\Render\MarkupInterface $name
* The print-able name of the type.
*
* @return \Drupal\hook_event_dispatcher\Value\Token
* Creates a new token.
*
* @throws \UnexpectedValueException
*/
public static function create($type, $token, $name) {
$instance = new self();
if (!is_string($type)) {
throw new UnexpectedValueException('Type should be a string');
}
if (!is_string($token)) {
throw new UnexpectedValueException('Token should be a string');
}
if (!is_string($name) && !$name instanceof MarkupInterface) {
throw new UnexpectedValueException('Name should be a string or an instance of MarkupInterface');
}
$instance->type = $type;
$instance->token = $token;
$instance->name = $name;
return $instance;
}
/**
* Set description and return a new instance.
*
* @param string $description
* The description of the token type.
*
* @return \Drupal\hook_event_dispatcher\Value\Token
* New instance with the given description.
*
* @throws \UnexpectedValueException
*/
public function setDescription($description) {
if (!is_string($description) && !$description instanceof MarkupInterface) {
throw new UnexpectedValueException('Description should be a string or an instance of MarkupInterface');
}
$clone = clone $this;
$clone->description = $description;
return $clone;
}
/**
* Set whether or not the token is dynamic.
*
* @param bool $dynamic
* TRUE if the token is dynamic.
*
* @return \Drupal\hook_event_dispatcher\Value\Token
* New instance with the given dynamic.
*/
public function setDynamic($dynamic) {
$clone = clone $this;
$clone->dynamic = $dynamic;
return $clone;
}
/**
* Getter.
*
* @return string|MarkupInterface|null
* The description.
*/
public function getDescription() {
return $this->description;
}
/**
* Getter.
*
* @return string
* The type like 'node'.
*/
public function getType() {
return $this->type;
}
/**
* Getter.
*
* @return string|MarkupInterface
* The label of the token.
*/
public function getName() {
return $this->name;
}
/**
* Getter.
*
* @return string
* The token name like 'url'.
*/
public function getToken() {
return $this->token;
}
/**
* Getter.
*
* @return bool
* Whether or not the token is dynamic.
*/
public function isDynamic() {
return $this->dynamic;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Token:: |
private | property | Description. | |
Token:: |
private | property | Is a dynamic field. | |
Token:: |
private | property | Name. | |
Token:: |
private | property | Token. | |
Token:: |
private | property | Type. | |
Token:: |
public static | function | Token factory function. | |
Token:: |
public | function | Getter. | |
Token:: |
public | function | Getter. | |
Token:: |
public | function | Getter. | |
Token:: |
public | function | Getter. | |
Token:: |
public | function | Getter. | |
Token:: |
public | function | Set description and return a new instance. | |
Token:: |
public | function | Set whether or not the token is dynamic. | |
Token:: |
private | function | Use create function instead. |