Skip to content

Commit

Permalink
Merge pull request #422 from FabioBatSilva/DDC-1574
Browse files Browse the repository at this point in the history
DDC-1574 - "new" operator
  • Loading branch information
beberlei committed Oct 5, 2012
2 parents 91caff1 + dd984c7 commit 13762f2
Show file tree
Hide file tree
Showing 11 changed files with 1,441 additions and 426 deletions.
19 changes: 19 additions & 0 deletions lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
Expand Up @@ -234,6 +234,25 @@ protected function gatherRowData(array $data, array &$cache, array &$id, array &
// maybe from an additional column that has not been defined in a NativeQuery ResultSetMapping.
continue 2;
}

if (isset($this->_rsm->newObjectMappings[$key])) {
$mapping = $this->_rsm->newObjectMappings[$key];

$cache[$key]['isNewObjectParameter'] = true;
$cache[$key]['argIndex'] = $mapping['argIndex'];
$cache[$key]['objIndex'] = $mapping['objIndex'];
$cache[$key]['class'] = new \ReflectionClass($mapping['className']);
}
}

if (isset($cache[$key]['isNewObjectParameter'])) {
$class = $cache[$key]['class'];
$argIndex = $cache[$key]['argIndex'];
$objIndex = $cache[$key]['objIndex'];
$value = $cache[$key]['type']->convertToPHPValue($value, $this->_platform);

$rowData['newObjects'][$objIndex]['class'] = $class;
$rowData['newObjects'][$objIndex]['args'][$argIndex] = $value;
}

if (isset($cache[$key]['isScalar'])) {
Expand Down
253 changes: 158 additions & 95 deletions lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions lib/Doctrine/ORM/Query/AST/NewObjectExpression.php
@@ -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 "(" NewObjectArg {"," NewObjectArg}* ")"
*
* @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 $className;

/**
* @var array
*/
public $args;

/**
* @param type $className
* @param array $args
*/
public function __construct($className, array $args)
{
$this->className = $className;
$this->args = $args;
}

/**
* @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
* @return string
*/
public function dispatch($sqlWalker)
{
return $sqlWalker->walkNewObject($this);
}
}
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/Query/Lexer.php
Expand Up @@ -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.
Expand Down

0 comments on commit 13762f2

Please sign in to comment.