You are here

private function ProxyGenerator::isShortIdentifierGetter in Plug 7

Checks if the method is a short identifier getter.

What does this mean? For proxy objects the identifier is already known, however accessing the getter for this identifier usually triggers the lazy loading, leading to a query that may not be necessary if only the ID is interesting for the userland code (for example in views that generate links to the entity, but do not display anything else).

Parameters

\ReflectionMethod $method:

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

Return value

boolean

1 call to ProxyGenerator::isShortIdentifierGetter()
ProxyGenerator::generateMethods in lib/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php
Generates decorated methods by picking those available in the parent class.

File

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

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 isShortIdentifierGetter($method, ClassMetadata $class) {
  $identifier = lcfirst(substr($method
    ->getName(), 3));
  $startLine = $method
    ->getStartLine();
  $endLine = $method
    ->getEndLine();
  $cheapCheck = $method
    ->getNumberOfParameters() == 0 && substr($method
    ->getName(), 0, 3) == 'get' && in_array($identifier, $class
    ->getIdentifier(), true) && $class
    ->hasField($identifier) && $endLine - $startLine <= 4;
  if ($cheapCheck) {
    $code = file($method
      ->getDeclaringClass()
      ->getFileName());
    $code = trim(implode(' ', array_slice($code, $startLine - 1, $endLine - $startLine + 1)));
    $pattern = sprintf(self::PATTERN_MATCH_ID_METHOD, $method
      ->getName(), $identifier);
    if (preg_match($pattern, $code)) {
      return true;
    }
  }
  return false;
}