You are here

protected function ProxyBuilder::buildParameter in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php \Drupal\Component\ProxyBuilder\ProxyBuilder::buildParameter()
  2. 9 core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php \Drupal\Component\ProxyBuilder\ProxyBuilder::buildParameter()

Builds a string for a single parameter of a method.

Parameters

\ReflectionParameter $parameter: A reflection object of the parameter.

Return value

string

File

core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php, line 264

Class

ProxyBuilder
Generates the string representation of the proxy service.

Namespace

Drupal\Component\ProxyBuilder

Code

protected function buildParameter(\ReflectionParameter $parameter) {
  $parameter_string = '';
  if ($parameter
    ->hasType()) {
    $type = $parameter
      ->getType();
    if ($type
      ->allowsNull()) {
      $parameter_string .= '?';
    }
    if (!$type
      ->isBuiltin()) {

      // The parameter is a class or interface.
      $parameter_string .= '\\';
    }
    $type_name = $type
      ->getName();
    if ($type_name === 'self') {
      $type_name = $parameter
        ->getDeclaringClass()
        ->getName();
    }
    $parameter_string .= $type_name . ' ';
  }
  if ($parameter
    ->isPassedByReference()) {
    $parameter_string .= '&';
  }
  $parameter_string .= '$' . $parameter
    ->getName();
  if ($parameter
    ->isDefaultValueAvailable()) {
    $parameter_string .= ' = ';
    $parameter_string .= var_export($parameter
      ->getDefaultValue(), TRUE);
  }
  return $parameter_string;
}