Doctrine\ODM\CouchDB\Proxy\ProxyFactory::generateMethods PHP Method

generateMethods() private method

Generates the methods of a proxy class.
private generateMethods ( ClassMetadata $class ) : string
$class Doctrine\ODM\CouchDB\Mapping\ClassMetadata
return string The code of the generated methods.
    private function generateMethods(ClassMetadata $class)
    {
        $methods = '';
        foreach ($class->reflClass->getMethods() as $method) {
            /* @var $method \ReflectionMethod */
            if ($method->isConstructor() || strtolower($method->getName()) == "__sleep") {
                continue;
            }
            if ($method->isPublic() && !$method->isFinal() && !$method->isStatic()) {
                $methods .= PHP_EOL . '    public function ';
                if ($method->returnsReference()) {
                    $methods .= '&';
                }
                $methods .= $method->getName() . '(';
                $firstParam = true;
                $parameterString = $argumentString = '';
                foreach ($method->getParameters() as $param) {
                    if ($firstParam) {
                        $firstParam = false;
                    } else {
                        $parameterString .= ', ';
                        $argumentString .= ', ';
                    }
                    // We need to pick the type hint class too
                    if (($paramClass = $param->getClass()) !== null) {
                        $parameterString .= '\\' . $paramClass->getName() . ' ';
                    } else {
                        if ($param->isArray()) {
                            $parameterString .= 'array ';
                        }
                    }
                    if ($param->isPassedByReference()) {
                        $parameterString .= '&';
                    }
                    $parameterString .= '$' . $param->getName();
                    $argumentString .= '$' . $param->getName();
                    if ($param->isDefaultValueAvailable()) {
                        $parameterString .= ' = ' . var_export($param->getDefaultValue(), true);
                    }
                }
                $methods .= $parameterString . ')';
                $methods .= PHP_EOL . '    {' . PHP_EOL;
                $methods .= '        $this->__load();' . PHP_EOL;
                $methods .= '        return parent::' . $method->getName() . '(' . $argumentString . ');';
                $methods .= PHP_EOL . '    }' . PHP_EOL;
            }
        }
        return $methods;
    }