start work
This commit is contained in:
parent
831f0acdc5
commit
ee7b5da64a
60
lib/Doctrine/ORM/Query/AST/NewObjectExpression.php
Normal file
60
lib/Doctrine/ORM/Query/AST/NewObjectExpression.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*
|
||||
* 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\AST;
|
||||
|
||||
/**
|
||||
* NewObjectExpression ::= "NEW" IdentificationVariable "(" SimpleSelectExpression {"," SimpleSelectExpression}* ")"
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.3
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class NewObjectExpression extends Node
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $identificationVariable;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $fieldSet;
|
||||
|
||||
/**
|
||||
* @param type $identificationVariable
|
||||
* @param array $fieldSet
|
||||
*/
|
||||
public function __construct($identificationVariable, array $fieldSet)
|
||||
{
|
||||
$this->identificationVariable = $identificationVariable;
|
||||
$this->fieldSet = $fieldSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
|
||||
* @return string
|
||||
*/
|
||||
public function dispatch($sqlWalker)
|
||||
{
|
||||
return $sqlWalker->walkNewObject($this);
|
||||
}
|
||||
}
|
@ -108,6 +108,7 @@ class Lexer extends \Doctrine\Common\Lexer
|
||||
const T_WHERE = 154;
|
||||
const T_WITH = 155;
|
||||
const T_PARTIAL = 156;
|
||||
const T_NEW = 157;
|
||||
|
||||
/**
|
||||
* Creates a new query scanner object.
|
||||
|
@ -1629,6 +1629,35 @@ class Parser
|
||||
return $partialObjectExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* NewObjectExpression ::= "NEW" IdentificationVariable "(" SimpleSelectExpression {"," SimpleSelectExpression}* ")"
|
||||
* @return \Doctrine\ORM\Query\AST\NewObjectExpression
|
||||
*/
|
||||
public function NewObjectExpression()
|
||||
{
|
||||
$this->match(Lexer::T_NEW);
|
||||
$this->match(Lexer::T_IDENTIFIER);
|
||||
|
||||
$identificationVariable = $this->_lexer->token['value'];
|
||||
|
||||
$this->match(Lexer::T_OPEN_PARENTHESIS);
|
||||
|
||||
$fieldSet[] = $this->SimpleSelectExpression();
|
||||
while ($this->_lexer->isNextToken(Lexer::T_COMMA)) {
|
||||
$this->match(Lexer::T_COMMA);
|
||||
|
||||
$fieldSet[] = $this->SimpleSelectExpression();
|
||||
}
|
||||
|
||||
$this->match(Lexer::T_CLOSE_PARENTHESIS);
|
||||
|
||||
$expression = new AST\NewObjectExpression($identificationVariable, $fieldSet);
|
||||
|
||||
// @TODO : Defer NewObjectExpression validation
|
||||
throw new \BadMethodCallException("Not complete yet !");
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* IndexBy ::= "INDEX" "BY" StateFieldPathExpression
|
||||
*
|
||||
@ -1953,6 +1982,12 @@ class Parser
|
||||
$expression = $this->SimpleArithmeticExpression();
|
||||
break;
|
||||
|
||||
// NewObjectExpression (New ClassName(id, name))
|
||||
case ($lookaheadType === Lexer::T_NEW):
|
||||
$expression = $this->NewObjectExpression();
|
||||
//$identVariable = $expression->identificationVariable;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->syntaxError(
|
||||
'IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression',
|
||||
|
17
tests/Doctrine/Tests/Models/CMS/CmsUserDTO.php
Normal file
17
tests/Doctrine/Tests/Models/CMS/CmsUserDTO.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\CMS;
|
||||
|
||||
class CmsUserDTO
|
||||
{
|
||||
public $name;
|
||||
public $email;
|
||||
public $city;
|
||||
|
||||
public function __construct($name = null, $email = null, $city = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->email = $email;
|
||||
$this->city = $city;
|
||||
}
|
||||
}
|
@ -1555,6 +1555,18 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1574
|
||||
*/
|
||||
public function testSupportsNewOperator()
|
||||
{
|
||||
$this->markTestIncomplete('not complete yet !');
|
||||
$this->assertSqlGeneration(
|
||||
'SELECT new Doctrine\Tests\Models\CMS\CmsUser(u.name, e.email, a.city) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a',
|
||||
'SELECT c0_.name AS name0, c1_.email AS email1, c2_.city AS city2 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function testCustomTypeValueSql()
|
||||
{
|
||||
if (DBALType::hasType('negative_to_positive')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user