[2.0] Fixed 4 issues with ProxyGenerator. It was not considering the type hint and it was generating an E_STRICT error with incompatible method declaration. Some cosmetic changes in Query
This commit is contained in:
parent
cdc102fc23
commit
8fbee579d3
@ -46,9 +46,11 @@ class ProxyClassGenerator
|
||||
public function __construct(EntityManager $em, $cacheDir = null)
|
||||
{
|
||||
$this->_em = $em;
|
||||
|
||||
if ($cacheDir === null) {
|
||||
$cacheDir = sys_get_temp_dir();
|
||||
}
|
||||
|
||||
$this->_cacheDir = rtrim($cacheDir, '/') . '/';
|
||||
}
|
||||
|
||||
@ -64,9 +66,11 @@ class ProxyClassGenerator
|
||||
{
|
||||
$class = $this->_em->getClassMetadata($className);
|
||||
$proxyClassName = str_replace('\\', '_', $className) . 'RProxy';
|
||||
|
||||
if ( ! class_exists($proxyClassName, false)) {
|
||||
$this->_em->getMetadataFactory()->setMetadataFor(self::$_ns . $proxyClassName, $class);
|
||||
$fileName = $this->_cacheDir . $proxyClassName . '.g.php';
|
||||
|
||||
if (file_exists($fileName)) {
|
||||
require $fileName;
|
||||
$proxyClassName = '\\' . self::$_ns . $proxyClassName;
|
||||
@ -90,56 +94,76 @@ class ProxyClassGenerator
|
||||
|
||||
file_put_contents($fileName, $file);
|
||||
require $fileName;
|
||||
|
||||
$proxyClassName = '\\' . self::$_ns . $proxyClassName;
|
||||
|
||||
return $proxyClassName;
|
||||
}
|
||||
|
||||
protected function _generateMethods(ClassMetadata $class)
|
||||
{
|
||||
$methods = '';
|
||||
|
||||
foreach ($class->reflClass->getMethods() as $method) {
|
||||
if ($method->getName() == '__construct') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($method->isPublic() && ! $method->isFinal()) {
|
||||
$methods .= PHP_EOL . 'public function ' . $method->getName() . '(';
|
||||
$firstParam = true;
|
||||
$parameterString = '';
|
||||
$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() . ' ';
|
||||
}
|
||||
|
||||
$parameterString .= '$' . $param->getName();
|
||||
$argumentString .= '$' . $param->getName();
|
||||
}
|
||||
|
||||
$methods .= $parameterString . ') {' . PHP_EOL;
|
||||
$methods .= '$this->_load();' . PHP_EOL;
|
||||
$methods .= 'return parent::' . $method->getName() . '(' . $parameterString . ');';
|
||||
$methods .= 'return parent::' . $method->getName() . '(' . $argumentString . ');';
|
||||
$methods .= '}' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
return $methods;
|
||||
}
|
||||
|
||||
public function _generateSleep(ClassMetadata $class)
|
||||
{
|
||||
$sleepImpl = '';
|
||||
|
||||
if ($class->reflClass->hasMethod('__sleep')) {
|
||||
$sleepImpl .= 'return parent::__sleep();';
|
||||
} else {
|
||||
$sleepImpl .= 'return array(';
|
||||
$first = true;
|
||||
|
||||
foreach ($class->getReflectionProperties() as $name => $prop) {
|
||||
if ($first) {
|
||||
$first = false;
|
||||
} else {
|
||||
$sleepImpl .= ', ';
|
||||
}
|
||||
|
||||
$sleepImpl .= "'" . $name . "'";
|
||||
}
|
||||
|
||||
$sleepImpl .= ');';
|
||||
}
|
||||
|
||||
return $sleepImpl;
|
||||
}
|
||||
|
||||
@ -157,19 +181,23 @@ class ProxyClassGenerator
|
||||
$file = self::$_assocProxyClassTemplate;
|
||||
|
||||
$methods = '';
|
||||
|
||||
foreach ($class->reflClass->getMethods() as $method) {
|
||||
if ($method->isPublic() && ! $method->isFinal()) {
|
||||
$methods .= PHP_EOL . 'public function ' . $method->getName() . '(';
|
||||
$firstParam = true;
|
||||
$parameterString = '';
|
||||
|
||||
foreach ($method->getParameters() as $param) {
|
||||
if ($firstParam) {
|
||||
$firstParam = false;
|
||||
} else {
|
||||
$parameterString .= ', ';
|
||||
}
|
||||
|
||||
$parameterString .= '$' . $param->getName();
|
||||
}
|
||||
|
||||
$methods .= $parameterString . ') {' . PHP_EOL;
|
||||
$methods .= '$this->_load();' . PHP_EOL;
|
||||
$methods .= 'return parent::' . $method->getName() . '(' . $parameterString . ');';
|
||||
@ -178,19 +206,23 @@ class ProxyClassGenerator
|
||||
}
|
||||
|
||||
$sleepImpl = '';
|
||||
|
||||
if ($class->reflClass->hasMethod('__sleep')) {
|
||||
$sleepImpl .= 'return parent::__sleep();';
|
||||
} else {
|
||||
$sleepImpl .= 'return array(';
|
||||
$first = true;
|
||||
|
||||
foreach ($class->getReflectionProperties() as $name => $prop) {
|
||||
if ($first) {
|
||||
$first = false;
|
||||
} else {
|
||||
$sleepImpl .= ', ';
|
||||
}
|
||||
|
||||
$sleepImpl .= "'" . $name . "'";
|
||||
}
|
||||
|
||||
$sleepImpl .= ');';
|
||||
}
|
||||
|
||||
@ -205,6 +237,7 @@ class ProxyClassGenerator
|
||||
$file = str_replace($placeholders, $replacements, $file);
|
||||
|
||||
file_put_contents($fileName, $file);
|
||||
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
|
@ -256,7 +256,7 @@ class Parser
|
||||
$message .= "'{$this->_lexer->lookahead['value']}'";
|
||||
}
|
||||
|
||||
throw DoctrineException::updateMe($message);
|
||||
throw QueryException::syntaxError($message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,7 +280,7 @@ class Parser
|
||||
$message = 'line 0, col ' . (isset($token['position']) ? $token['position'] : '-1')
|
||||
. " near '" . substr($dql, $token['position'], $length) . "'): Error: " . $message;
|
||||
|
||||
throw DoctrineException::updateMe($message);
|
||||
throw QueryException::semanticalError($message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -352,6 +352,7 @@ class Parser
|
||||
|
||||
default:
|
||||
$this->syntaxError('SELECT, UPDATE or DELETE');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Query;
|
||||
@ -9,6 +24,23 @@ namespace Doctrine\ORM\Query;
|
||||
/**
|
||||
* Description of QueryException
|
||||
*
|
||||
* @author robo
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class QueryException extends \Doctrine\Common\DoctrineException {}
|
||||
class QueryException extends \Doctrine\Common\DoctrineException
|
||||
{
|
||||
public static function syntaxError($message)
|
||||
{
|
||||
return new self('[Syntax Error] ' . $message);
|
||||
}
|
||||
|
||||
|
||||
public static function semanticalError($message)
|
||||
{
|
||||
return new self('[Semantical Error] ' . $message);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user