You are here

public static function Token::create in Hook Event Dispatcher 8

Token factory function.

Parameters

string $type: The group name, like 'node'.

string $token: The token, like 'url' or 'id'.

string|\Drupal\Component\Render\MarkupInterface $name: The print-able name of the type.

Return value

\Drupal\hook_event_dispatcher\Value\Token Creates a new token.

Throws

\UnexpectedValueException

4 calls to Token::create()
TokenEventTest::testTokenInfoEvent in tests/src/Unit/Token/TokenEventTest.php
Test TokenInfoEvent.
TokenTest::testTokenInvalidNameException in tests/src/Unit/Token/TokenTest.php
Test Token invalid token exception.
TokenTest::testTokenInvalidTokenException in tests/src/Unit/Token/TokenTest.php
Test Token invalid token exception.
TokenTest::testTokenInvalidTypeException in tests/src/Unit/Token/TokenTest.php
Test Token invalid type exception.

File

src/Value/Token.php, line 68

Class

Token
Token ValueObject.

Namespace

Drupal\hook_event_dispatcher\Value

Code

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;
}