Ejemplo n.º 1
0
    /**
     * Creates definition for trait method body
     *
     * @param ParsedMethod $method Method reflection
     *
     * @return string new method body
     */
    protected function getJoinpointInvocationBody(ParsedMethod $method)
    {
        $isStatic = $method->isStatic();
        $class = '\\' . __CLASS__;
        $scope = $isStatic ? $this->staticLsbExpression : '$this';
        $prefix = $isStatic ? AspectContainer::STATIC_METHOD_PREFIX : AspectContainer::METHOD_PREFIX;
        $args = join(', ', array_map(function (ParsedParameter $param) {
            $byReference = $param->isPassedByReference() ? '&' : '';
            return $byReference . '$' . $param->name;
        }, $method->getParameters()));
        $args = $scope . ($args ? ", array({$args})" : '');
        return <<<BODY
static \$__joinPoint = null;
if (!\$__joinPoint) {
    \$__joinPoint = {$class}::getJoinPoint(__TRAIT__, __CLASS__, '{$prefix}', '{$method->name}');
}
return \$__joinPoint->__invoke({$args});
BODY;
    }
Ejemplo n.º 2
0
 /**
  * Creates a method code from Reflection
  *
  * @param ParsedMethod $method Reflection for method
  * @param string $body Body of method
  *
  * @return string
  */
 protected function getOverriddenMethod(ParsedMethod $method, $body)
 {
     $code = preg_replace('/ {4}|\\t/', '', $method->getDocComment()) . "\n" . join(' ', Reflection::getModifierNames($method->getModifiers())) . ' function ' . ($method->returnsReference() ? '&' : '') . $method->name . '(' . join(', ', $this->getParameters($method->getParameters())) . ")\n" . "{\n" . $this->indent($body) . "\n" . "}\n";
     return $code;
 }