Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Utility/Variable.php \Drupal\Component\Utility\Variable::callableToString()

Generates a human-readable name for a callable.

Parameters

callable $callable: A callable.

Return value

string A human-readable name for the callable.

5 calls to Variable::callableToString()
Datelist::processDatelist in core/lib/Drupal/Core/Datetime/Element/Datelist.php
Expands a date element into an array of individual elements.
DatelistElementFormTest::testDatelistElementUntrustedCallbacks in core/tests/Drupal/KernelTests/Core/Datetime/DatelistElementFormTest.php
Tests that exceptions are raised if untrusted callbacks are used.
Datetime::processDatetime in core/lib/Drupal/Core/Datetime/Element/Datetime.php
Expands a datetime element type into date and/or time elements.
DatetimeElementFormTest::providerUntrusted in core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php
Data provider for ::testDatetimeElementUntrustedCallbacks().
VariableTest::testCallableToString in core/tests/Drupal/Tests/Component/Utility/VariableTest.php
Tests generating a human-readable name for a callable.

File

core/lib/Drupal/Component/Utility/Variable.php, line 21

Class

Variable
Provides helpers for dealing with variables.

Namespace

Drupal\Component\Utility

Code

public static function callableToString($callable) : string {
  if ($callable instanceof \Closure) {
    return '[closure]';
  }
  elseif (is_array($callable) && $callable) {
    if (is_object($callable[0])) {
      $callable[0] = get_class($callable[0]);
    }
    return implode('::', $callable);
  }
  elseif (is_string($callable)) {
    return $callable;
  }
  else {
    return '[unknown]';
  }
}