Fix some CS
This commit is contained in:
parent
de93983dff
commit
1bd6e841bf
@ -236,10 +236,12 @@ abstract class AbstractHydrator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->_rsm->newObjectMappings[$key])) {
|
if (isset($this->_rsm->newObjectMappings[$key])) {
|
||||||
|
$mapping = $this->_rsm->newObjectMappings[$key];
|
||||||
|
|
||||||
$cache[$key]['isNewObjectParameter'] = true;
|
$cache[$key]['isNewObjectParameter'] = true;
|
||||||
$cache[$key]['argIndex'] = $this->_rsm->newObjectMappings[$key]['argIndex'];
|
$cache[$key]['argIndex'] = $mapping['argIndex'];
|
||||||
$cache[$key]['objIndex'] = $this->_rsm->newObjectMappings[$key]['objIndex'];
|
$cache[$key]['objIndex'] = $mapping['objIndex'];
|
||||||
$cache[$key]['class'] = new \ReflectionClass($this->_rsm->newObjectMappings[$key]['className']);
|
$cache[$key]['class'] = new \ReflectionClass($mapping['className']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,8 +249,7 @@ abstract class AbstractHydrator
|
|||||||
$class = $cache[$key]['class'];
|
$class = $cache[$key]['class'];
|
||||||
$argIndex = $cache[$key]['argIndex'];
|
$argIndex = $cache[$key]['argIndex'];
|
||||||
$objIndex = $cache[$key]['objIndex'];
|
$objIndex = $cache[$key]['objIndex'];
|
||||||
$value = $cache[$key]['type']
|
$value = $cache[$key]['type']->convertToPHPValue($value, $this->_platform);
|
||||||
->convertToPHPValue($value, $this->_platform);
|
|
||||||
|
|
||||||
$rowData['newObjects'][$objIndex]['class'] = $class;
|
$rowData['newObjects'][$objIndex]['class'] = $class;
|
||||||
$rowData['newObjects'][$objIndex]['args'][$argIndex] = $value;
|
$rowData['newObjects'][$objIndex]['args'][$argIndex] = $value;
|
||||||
|
@ -514,6 +514,7 @@ class ObjectHydrator extends AbstractHydrator
|
|||||||
// check for existing result from the iterations before
|
// check for existing result from the iterations before
|
||||||
if ( ! isset($this->identifierMap[$dqlAlias][$id[$dqlAlias]])) {
|
if ( ! isset($this->identifierMap[$dqlAlias][$id[$dqlAlias]])) {
|
||||||
$element = $this->getEntity($rowData[$dqlAlias], $dqlAlias);
|
$element = $this->getEntity($rowData[$dqlAlias], $dqlAlias);
|
||||||
|
|
||||||
if ($this->_rsm->isMixed) {
|
if ($this->_rsm->isMixed) {
|
||||||
$element = array($entityKey => $element);
|
$element = array($entityKey => $element);
|
||||||
}
|
}
|
||||||
@ -585,6 +586,7 @@ class ObjectHydrator extends AbstractHydrator
|
|||||||
|
|
||||||
if ($count === 1) {
|
if ($count === 1) {
|
||||||
$result[$resultKey] = $obj;
|
$result[$resultKey] = $obj;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,24 +585,14 @@ class Parser
|
|||||||
$token = $deferredItem['token'];
|
$token = $deferredItem['token'];
|
||||||
$className = $expression->className;
|
$className = $expression->className;
|
||||||
$args = $expression->args;
|
$args = $expression->args;
|
||||||
|
$fromClassName = isset($AST->fromClause->identificationVariableDeclarations[0]->rangeVariableDeclaration->abstractSchemaName)
|
||||||
|
? $AST->fromClause->identificationVariableDeclarations[0]->rangeVariableDeclaration->abstractSchemaName
|
||||||
|
: null;
|
||||||
|
|
||||||
//first from item
|
// If the namespace is not given then assumes the first from entity namespace
|
||||||
if ( strpos($className, '\\') === false
|
if (strpos($className, '\\') === false && ! class_exists($className) && strpos($fromClassName, '\\') !== false) {
|
||||||
&& ! class_exists($className)
|
$namespace = substr($fromClassName, 0 , strrpos($fromClassName, '\\'));
|
||||||
&& isset($AST->fromClause
|
$className = $namespace . '\\' . $className;
|
||||||
->identificationVariableDeclarations[0]
|
|
||||||
->rangeVariableDeclaration
|
|
||||||
->abstractSchemaName)) {
|
|
||||||
|
|
||||||
$fromClassName = $AST->fromClause
|
|
||||||
->identificationVariableDeclarations[0]
|
|
||||||
->rangeVariableDeclaration
|
|
||||||
->abstractSchemaName;
|
|
||||||
|
|
||||||
if (strpos($fromClassName, '\\') !== false) {
|
|
||||||
$fromClassName = substr($fromClassName, 0 , strrpos($fromClassName, '\\'));
|
|
||||||
$className = $fromClassName . '\\' . $className;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (class_exists($className)) {
|
if (class_exists($className)) {
|
||||||
$expression->className = $className;
|
$expression->className = $className;
|
||||||
@ -610,26 +600,21 @@ class Parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ! class_exists($className)) {
|
if ( ! class_exists($className)) {
|
||||||
$this->semanticalError(sprintf(
|
$this->semanticalError(sprintf('Class "%s" is not defined.', $expression->className), $token);
|
||||||
'Class "%s" is not defined.',
|
|
||||||
$expression->className
|
|
||||||
), $token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = new \ReflectionClass($className);
|
$class = new \ReflectionClass($className);
|
||||||
|
|
||||||
if($class->getConstructor() === null) {
|
if ( ! $class->isInstantiable()) {
|
||||||
$this->semanticalError(sprintf(
|
$this->semanticalError(sprintf('Class "%s" can not be instantiated.', $className), $token);
|
||||||
'Class "%s" has not a valid contructor.',
|
|
||||||
$className
|
|
||||||
), $token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($class->getConstructor()->getNumberOfRequiredParameters() > sizeof($args)) {
|
if ($class->getConstructor() === null) {
|
||||||
$this->semanticalError(sprintf(
|
$this->semanticalError(sprintf('Class "%s" has not a valid contructor.', $className), $token);
|
||||||
'Number of arguments does not match with "%s" constructor declaration.',
|
}
|
||||||
$className
|
|
||||||
), $token);
|
if ($class->getConstructor()->getNumberOfRequiredParameters() > sizeof($args)) {
|
||||||
|
$this->semanticalError(sprintf('Number of arguments does not match with "%s" constructor declaration.', $className), $token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1719,6 +1704,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* NewObjectExpression ::= "NEW" IdentificationVariable "(" NewObjectArg {"," NewObjectArg}* ")"
|
* NewObjectExpression ::= "NEW" IdentificationVariable "(" NewObjectArg {"," NewObjectArg}* ")"
|
||||||
|
*
|
||||||
* @return \Doctrine\ORM\Query\AST\NewObjectExpression
|
* @return \Doctrine\ORM\Query\AST\NewObjectExpression
|
||||||
*/
|
*/
|
||||||
public function NewObjectExpression()
|
public function NewObjectExpression()
|
||||||
@ -1732,6 +1718,7 @@ class Parser
|
|||||||
$this->match(Lexer::T_OPEN_PARENTHESIS);
|
$this->match(Lexer::T_OPEN_PARENTHESIS);
|
||||||
|
|
||||||
$args[] = $this->NewObjectArg();
|
$args[] = $this->NewObjectArg();
|
||||||
|
|
||||||
while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
|
while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
|
||||||
$this->match(Lexer::T_COMMA);
|
$this->match(Lexer::T_COMMA);
|
||||||
|
|
||||||
|
@ -1406,15 +1406,14 @@ class SqlWalker implements TreeWalker
|
|||||||
public function walkNewObject($newObjectExpression)
|
public function walkNewObject($newObjectExpression)
|
||||||
{
|
{
|
||||||
$sqlSelectExpressions = array();
|
$sqlSelectExpressions = array();
|
||||||
$objIndex = $this->newObjectCounter ++;
|
$objIndex = $this->newObjectCounter++;
|
||||||
|
|
||||||
foreach ($newObjectExpression->args as $argIndex => $e) {
|
foreach ($newObjectExpression->args as $argIndex => $e) {
|
||||||
|
|
||||||
$resultAlias = $this->scalarResultCounter++;
|
$resultAlias = $this->scalarResultCounter++;
|
||||||
$columnAlias = $this->getSQLColumnAlias('sclr');
|
$columnAlias = $this->getSQLColumnAlias('sclr');
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case $e instanceof AST\NewObjectExpression:
|
case ($e instanceof AST\NewObjectExpression):
|
||||||
$sqlSelectExpressions[] = $e->dispatch($this);
|
$sqlSelectExpressions[] = $e->dispatch($this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -504,6 +504,16 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$dql = "SELECT new Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs(u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u";
|
$dql = "SELECT new Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs(u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u";
|
||||||
$this->_em->createQuery($dql)->getResult();
|
$this->_em->createQuery($dql)->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Doctrine\ORM\Query\QueryException
|
||||||
|
* @expectedExceptionMessage [Semantical Error] line 0, col 11 near 'Doctrine\Tests\ORM\Functional\ClassWithPrivateConstructor(u.name)': Error: Class "Doctrine\Tests\ORM\Functional\ClassWithPrivateConstructor" can not be instantiated.
|
||||||
|
*/
|
||||||
|
public function testClassCantBeInstantiatedException()
|
||||||
|
{
|
||||||
|
$dql = "SELECT new Doctrine\Tests\ORM\Functional\ClassWithPrivateConstructor(u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u";
|
||||||
|
$this->_em->createQuery($dql)->getResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithTooMuchArgs
|
class ClassWithTooMuchArgs
|
||||||
@ -514,3 +524,11 @@ class ClassWithTooMuchArgs
|
|||||||
$this->bor = $bar;
|
$this->bor = $bar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClassWithPrivateConstructor
|
||||||
|
{
|
||||||
|
private function __construct($foo)
|
||||||
|
{
|
||||||
|
$this->foo = $foo;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user