W3cubDocs

/Drupal 8

protected function ProxyBuilder::buildMethod

protected ProxyBuilder::buildMethod(\ReflectionMethod $reflection_method)

Generates the string representation of a single method: signature, body.

Parameters

\ReflectionMethod $reflection_method: A reflection method for the method.

Return value

string

File

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

Class

ProxyBuilder
Generates the string representation of the proxy service.

Namespace

Drupal\Component\ProxyBuilder

Code

protected function buildMethod(\ReflectionMethod $reflection_method) {

  $parameters = [];
  foreach ($reflection_method->getParameters() as $parameter) {
    $parameters[] = $this->buildParameter($parameter);
  }

  $function_name = $reflection_method->getName();

  $reference = '';
  if ($reflection_method->returnsReference()) {
    $reference = '&';
  }

  $signature_line = <<<'EOS'
/**
 * {@inheritdoc}
 */

EOS;

  if ($reflection_method->isStatic()) {
    $signature_line .= 'public static function ' . $reference . $function_name . '(';
  }
  else {
    $signature_line .= 'public function ' . $reference . $function_name . '(';
  }

  $signature_line .= implode(', ', $parameters);
  $signature_line .= ')';

  $output = $signature_line . "\n{\n";

  $output .= $this->buildMethodBody($reflection_method);

  $output .= "\n" . '}';
  return $output;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!ProxyBuilder!ProxyBuilder.php/function/ProxyBuilder::buildMethod/8.1.x