You are here

private function ProxyGenerator::generateMethods in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php \Doctrine\Common\Proxy\ProxyGenerator::generateMethods()

Generates decorated methods by picking those available in the parent class.

Parameters

\Doctrine\Common\Persistence\Mapping\ClassMetadata $class:

Return value

string

File

vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php, line 742

Class

ProxyGenerator
This factory is used to generate proxy classes. It builds proxies from given parameters, a template and class metadata.

Namespace

Doctrine\Common\Proxy

Code

private function generateMethods(ClassMetadata $class) {
  $methods = '';
  $methodNames = array();
  $reflectionMethods = $class
    ->getReflectionClass()
    ->getMethods(\ReflectionMethod::IS_PUBLIC);
  $skippedMethods = array(
    '__sleep' => true,
    '__clone' => true,
    '__wakeup' => true,
    '__get' => true,
    '__set' => true,
    '__isset' => true,
  );
  foreach ($reflectionMethods as $method) {
    $name = $method
      ->getName();
    if ($method
      ->isConstructor() || isset($skippedMethods[strtolower($name)]) || isset($methodNames[$name]) || $method
      ->isFinal() || $method
      ->isStatic() || !$method
      ->isPublic()) {
      continue;
    }
    $methodNames[$name] = true;
    $methods .= "\n    /**\n" . "     * {@inheritDoc}\n" . "     */\n" . '    public function ';
    if ($method
      ->returnsReference()) {
      $methods .= '&';
    }
    $methods .= $name . '(' . $this
      ->buildParametersString($class, $method, $method
      ->getParameters()) . ')';
    $methods .= "\n" . '    {' . "\n";
    if ($this
      ->isShortIdentifierGetter($method, $class)) {
      $identifier = lcfirst(substr($name, 3));
      $fieldType = $class
        ->getTypeOfField($identifier);
      $cast = in_array($fieldType, array(
        'integer',
        'smallint',
      )) ? '(int) ' : '';
      $methods .= '        if ($this->__isInitialized__ === false) {' . "\n";
      $methods .= '            return ' . $cast . ' parent::' . $method
        ->getName() . "();\n";
      $methods .= '        }' . "\n\n";
    }
    $invokeParamsString = implode(', ', $this
      ->getParameterNamesForInvoke($method
      ->getParameters()));
    $callParamsString = implode(', ', $this
      ->getParameterNamesForParentCall($method
      ->getParameters()));
    $methods .= "\n        \$this->__initializer__ " . "&& \$this->__initializer__->__invoke(\$this, " . var_export($name, true) . ", array(" . $invokeParamsString . "));" . "\n\n        return parent::" . $name . '(' . $callParamsString . ');' . "\n" . '    }' . "\n";
  }
  return $methods;
}