Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #309 from FabioBatSilva/DDC-1686

Fix DDC-1686
  • Loading branch information...
commit 2811d161bbb1b1e667cae5f0fb065018e82d6b25 2 parents 8a52e30 + 449d8a6
@guilhermeblanco guilhermeblanco authored
View
22 lib/Doctrine/ORM/Query/Expr/Andx.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,18 +25,32 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Andx extends Composite
{
- protected $_separator = ' AND ';
- protected $_allowedClasses = array(
+ /**
+ * @var string
+ */
+ protected $separator = ' AND ';
+
+ /**
+ * @var array
+ */
+ protected $allowedClasses = array(
'Doctrine\ORM\Query\Expr\Comparison',
'Doctrine\ORM\Query\Expr\Func',
'Doctrine\ORM\Query\Expr\Orx',
'Doctrine\ORM\Query\Expr\Andx',
);
+
+ /**
+ * @return array
+ */
+ public function getParts()
+ {
+ return $this->parts;
+ }
}
View
58 lib/Doctrine/ORM/Query/Expr/Base.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,25 +25,49 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
abstract class Base
{
- protected $_preSeparator = '(';
- protected $_separator = ', ';
- protected $_postSeparator = ')';
- protected $_allowedClasses = array();
+ /**
+ * @var string
+ */
+ protected $preSeparator = '(';
+
+ /**
+ * @var string
+ */
+ protected $separator = ', ';
+
+ /**
+ * @var string
+ */
+ protected $postSeparator = ')';
+
+ /**
+ * @var array
+ */
+ protected $allowedClasses = array();
- protected $_parts = array();
+ /**
+ * @var array
+ */
+ protected $parts = array();
+ /**
+ * @param array $args
+ */
public function __construct($args = array())
{
$this->addMultiple($args);
}
+ /**
+ * @param array $args
+ * @return Base
+ */
public function addMultiple($args = array())
{
foreach ((array) $args as $arg) {
@@ -55,6 +77,10 @@ public function addMultiple($args = array())
return $this;
}
+ /**
+ * @param mixed $arg
+ * @return Base
+ */
public function add($arg)
{
if ( $arg !== null || ($arg instanceof self && $arg->count() > 0) ) {
@@ -62,28 +88,34 @@ public function add($arg)
if ( ! is_string($arg)) {
$class = get_class($arg);
- if ( ! in_array($class, $this->_allowedClasses)) {
+ if ( ! in_array($class, $this->allowedClasses)) {
throw new \InvalidArgumentException("Expression of type '$class' not allowed in this context.");
}
}
- $this->_parts[] = $arg;
+ $this->parts[] = $arg;
}
return $this;
}
+ /**
+ * @return integer
+ */
public function count()
{
- return count($this->_parts);
+ return count($this->parts);
}
+ /**
+ * @return string
+ */
public function __toString()
{
if ($this->count() == 1) {
- return (string) $this->_parts[0];
+ return (string) $this->parts[0];
}
- return $this->_preSeparator . implode($this->_separator, $this->_parts) . $this->_postSeparator;
+ return $this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator;
}
}
View
62 lib/Doctrine/ORM/Query/Expr/Comparison.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,7 +25,6 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
@@ -41,19 +38,64 @@ class Comparison
const GT = '>';
const GTE = '>=';
- private $_leftExpr;
- private $_operator;
- private $_rightExpr;
+ /**
+ * @var mixed
+ */
+ protected $leftExpr;
+
+ /**
+ * @var string
+ */
+ protected $operator;
+
+ /**
+ * @var mixed
+ */
+ protected $rightExpr;
+ /**
+ * Creates a comparison expression with the given arguments.
+ *
+ * @param mixed $leftExpr
+ * @param string $operator
+ * @param mixed $rightExpr
+ */
public function __construct($leftExpr, $operator, $rightExpr)
{
- $this->_leftExpr = $leftExpr;
- $this->_operator = $operator;
- $this->_rightExpr = $rightExpr;
+ $this->leftExpr = $leftExpr;
+ $this->operator = $operator;
+ $this->rightExpr = $rightExpr;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getLeftExpr()
+ {
+ return $this->leftExpr;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOperator()
+ {
+ return $this->operator;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getRightExpr()
+ {
+ return $this->rightExpr;
}
+ /**
+ * @return string
+ */
public function __toString()
{
- return $this->_leftExpr . ' ' . $this->_operator . ' ' . $this->_rightExpr;
+ return $this->leftExpr . ' ' . $this->operator . ' ' . $this->rightExpr;
}
}
View
20 lib/Doctrine/ORM/Query/Expr/Composite.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,40 +25,46 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Composite extends Base
{
+ /**
+ * @return string
+ */
public function __toString()
{
if ($this->count() === 1) {
- return (string) $this->_parts[0];
+ return (string) $this->parts[0];
}
$components = array();
- foreach ($this->_parts as $part) {
+ foreach ($this->parts as $part) {
$components[] = $this->processQueryPart($part);
}
- return implode($this->_separator, $components);
+ return implode($this->separator, $components);
}
+ /**
+ * @param string $part
+ * @return string
+ */
private function processQueryPart($part)
{
$queryPart = (string) $part;
if (is_object($part) && $part instanceof self && $part->count() > 1) {
- return $this->_preSeparator . $queryPart . $this->_postSeparator;
+ return $this->preSeparator . $queryPart . $this->postSeparator;
}
// Fixes DDC-1237: User may have added a where item containing nested expression (with "OR" or "AND")
if (stripos($queryPart, ' OR ') !== false || stripos($queryPart, ' AND ') !== false) {
- return $this->_preSeparator . $queryPart . $this->_postSeparator;
+ return $this->preSeparator . $queryPart . $this->postSeparator;
}
return $queryPart;
View
31 lib/Doctrine/ORM/Query/Expr/From.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,7 +25,6 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
@@ -37,17 +34,17 @@ class From
/**
* @var string
*/
- private $_from;
+ protected $from;
/**
* @var string
*/
- private $_alias;
+ protected $alias;
/**
* @var string
*/
- private $_indexBy;
+ protected $indexBy;
/**
* @param string $from The class name.
@@ -56,9 +53,9 @@ class From
*/
public function __construct($from, $alias, $indexBy = null)
{
- $this->_from = $from;
- $this->_alias = $alias;
- $this->_indexBy = $indexBy;
+ $this->from = $from;
+ $this->alias = $alias;
+ $this->indexBy = $indexBy;
}
/**
@@ -66,7 +63,7 @@ public function __construct($from, $alias, $indexBy = null)
*/
public function getFrom()
{
- return $this->_from;
+ return $this->from;
}
/**
@@ -74,7 +71,15 @@ public function getFrom()
*/
public function getAlias()
{
- return $this->_alias;
+ return $this->alias;
+ }
+
+ /**
+ * @return string
+ */
+ public function getIndexBy()
+ {
+ return $this->indexBy;
}
/**
@@ -82,7 +87,7 @@ public function getAlias()
*/
public function __toString()
{
- return $this->_from . ' ' . $this->_alias .
- ($this->_indexBy ? ' INDEX BY ' . $this->_indexBy : '');
+ return $this->from . ' ' . $this->alias .
+ ($this->indexBy ? ' INDEX BY ' . $this->indexBy : '');
}
}
View
45 lib/Doctrine/ORM/Query/Expr/Func.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,24 +25,55 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Func
{
- private $_name;
- private $_arguments;
+ /**
+ * @var string
+ */
+ protected $name;
+
+ /**
+ * @var array
+ */
+ protected $arguments;
+ /**
+ * Creates a function, with the given argument.
+ *
+ * @param string $name
+ * @param array $arguments
+ */
public function __construct($name, $arguments)
{
- $this->_name = $name;
- $this->_arguments = (array) $arguments;
+ $this->name = $name;
+ $this->arguments = (array) $arguments;
+ }
+
+ /**
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * @return array
+ */
+ public function getArguments()
+ {
+ return $this->arguments;
}
+ /**
+ * @return string
+ */
public function __toString()
{
- return $this->_name . '(' . implode(', ', $this->_arguments) . ')';
+ return $this->name . '(' . implode(', ', $this->arguments) . ')';
}
}
View
22 lib/Doctrine/ORM/Query/Expr/GroupBy.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,13 +25,27 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class GroupBy extends Base
{
- protected $_preSeparator = '';
- protected $_postSeparator = '';
+ /**
+ * @var string
+ */
+ protected $preSeparator = '';
+
+ /**
+ * @var string
+ */
+ protected $postSeparator = '';
+
+ /**
+ * @return array
+ */
+ public function getParts()
+ {
+ return $this->parts;
+ }
}
View
126 lib/Doctrine/ORM/Query/Expr/Join.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,41 +25,123 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Join
{
- const INNER_JOIN = 'INNER';
- const LEFT_JOIN = 'LEFT';
+ const INNER_JOIN = 'INNER';
+ const LEFT_JOIN = 'LEFT';
+
+ const ON = 'ON';
+ const WITH = 'WITH';
+
+ /**
+ * @var string
+ */
+ protected $joinType;
+
+ /**
+ * @var string
+ */
+ protected $join;
- const ON = 'ON';
- const WITH = 'WITH';
+ /**
+ * @var string
+ */
+ protected $alias;
- private $_joinType;
- private $_join;
- private $_alias;
- private $_conditionType;
- private $_condition;
- private $_indexBy;
+ /**
+ * @var string
+ */
+ protected $conditionType;
+ /**
+ * @var string
+ */
+ protected $condition;
+
+ /**
+ * @var string
+ */
+ protected $indexBy;
+
+ /**
+ * @param string $joinType The condition type constant. Either INNER_JOIN or LEFT_JOIN.
+ * @param string $join The relationship to join
+ * @param string $alias The alias of the join
+ * @param string $conditionType The condition type constant. Either ON or WITH.
+ * @param string $condition The condition for the join
+ * @param string $indexBy The index for the join
+ */
public function __construct($joinType, $join, $alias = null, $conditionType = null, $condition = null, $indexBy = null)
{
- $this->_joinType = $joinType;
- $this->_join = $join;
- $this->_alias = $alias;
- $this->_conditionType = $conditionType;
- $this->_condition = $condition;
- $this->_indexBy = $indexBy;
+ $this->joinType = $joinType;
+ $this->join = $join;
+ $this->alias = $alias;
+ $this->conditionType = $conditionType;
+ $this->condition = $condition;
+ $this->indexBy = $indexBy;
}
+ /**
+ * @return string
+ */
+ public function getJoinType()
+ {
+ return $this->joinType;
+ }
+
+ /**
+ * @return string
+ */
+ public function getJoin()
+ {
+ return $this->join;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAlias()
+ {
+ return $this->alias;
+ }
+
+ /**
+ * @return string
+ */
+ public function getConditionType()
+ {
+ return $this->conditionType;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCondition()
+ {
+ return $this->condition;
+ }
+
+ /**
+ * @return string
+ */
+ public function getIndexBy()
+ {
+ return $this->indexBy;
+ }
+
+
+ /**
+ * @return string
+ */
public function __toString()
{
- return strtoupper($this->_joinType) . ' JOIN ' . $this->_join
- . ($this->_alias ? ' ' . $this->_alias : '')
- . ($this->_condition ? ' ' . strtoupper($this->_conditionType) . ' ' . $this->_condition : '')
- . ($this->_indexBy ? ' INDEX BY ' . $this->_indexBy : '');
+ return strtoupper($this->joinType) . ' JOIN ' . $this->join
+ . ($this->alias ? ' ' . $this->alias : '')
+ . ($this->condition ? ' ' . strtoupper($this->conditionType) . ' ' . $this->condition : '')
+ . ($this->indexBy ? ' INDEX BY ' . $this->indexBy : '');
}
}
View
47 lib/Doctrine/ORM/Query/Expr/Literal.php
@@ -1,9 +1,52 @@
<?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\Expr;
+/**
+ * Expression class for generating DQL functions
+ *
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @link www.doctrine-project.org
+ * @since 2.0
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @author Jonathan Wage <jonwage@gmail.com>
+ * @author Roman Borschel <roman@code-factory.org>
+ */
class Literal extends Base
{
- protected $_preSeparator = '';
- protected $_postSeparator = '';
+ /**
+ * @var string
+ */
+ protected $preSeparator = '';
+
+ /**
+ * @var string
+ */
+ protected $postSeparator = '';
+
+ /**
+ * @return array
+ */
+ public function getParts()
+ {
+ return $this->parts;
+ }
+
}
View
70 lib/Doctrine/ORM/Query/Expr/Math.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,40 +25,84 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Math
{
- private $_leftExpr;
- private $_operator;
- private $_rightExpr;
+ /**
+ * @var mixed
+ */
+ protected $leftExpr;
+
+ /**
+ * @var string
+ */
+ protected $operator;
+
+ /**
+ * @var mixed
+ */
+ protected $rightExpr;
+ /**
+ * Creates a mathematical expression with the given arguments.
+ *
+ * @param mixed $leftExpr
+ * @param string $operator
+ * @param mixed $rightExpr
+ */
public function __construct($leftExpr, $operator, $rightExpr)
{
- $this->_leftExpr = $leftExpr;
- $this->_operator = $operator;
- $this->_rightExpr = $rightExpr;
+ $this->leftExpr = $leftExpr;
+ $this->operator = $operator;
+ $this->rightExpr = $rightExpr;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getLeftExpr()
+ {
+ return $this->leftExpr;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOperator()
+ {
+ return $this->operator;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getRightExpr()
+ {
+ return $this->rightExpr;
}
+ /**
+ * @return string
+ */
public function __toString()
{
// Adjusting Left Expression
- $leftExpr = (string) $this->_leftExpr;
+ $leftExpr = (string) $this->leftExpr;
- if ($this->_leftExpr instanceof Math) {
+ if ($this->leftExpr instanceof Math) {
$leftExpr = '(' . $leftExpr . ')';
}
// Adjusting Right Expression
- $rightExpr = (string) $this->_rightExpr;
+ $rightExpr = (string) $this->rightExpr;
- if ($this->_rightExpr instanceof Math) {
+ if ($this->rightExpr instanceof Math) {
$rightExpr = '(' . $rightExpr . ')';
}
- return $leftExpr . ' ' . $this->_operator . ' ' . $rightExpr;
+ return $leftExpr . ' ' . $this->operator . ' ' . $rightExpr;
}
}
View
59 lib/Doctrine/ORM/Query/Expr/OrderBy.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,20 +25,41 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class OrderBy
{
- protected $_preSeparator = '';
- protected $_separator = ', ';
- protected $_postSeparator = '';
- protected $_allowedClasses = array();
+ /**
+ * @var string
+ */
+ protected $preSeparator = '';
+
+ /**
+ * @var string
+ */
+ protected $separator = ', ';
+
+ /**
+ * @var string
+ */
+ protected $postSeparator = '';
+
+ /**
+ * @var array
+ */
+ protected $allowedClasses = array();
- private $_parts = array();
+ /**
+ * @var array
+ */
+ protected $parts = array();
+ /**
+ * @param string $sort
+ * @param string $order
+ */
public function __construct($sort = null, $order = null)
{
if ($sort) {
@@ -48,19 +67,37 @@ public function __construct($sort = null, $order = null)
}
}
+ /**
+ * @param string $sort
+ * @param string $order
+ */
public function add($sort, $order = null)
{
$order = ! $order ? 'ASC' : $order;
- $this->_parts[] = $sort . ' '. $order;
+ $this->parts[] = $sort . ' '. $order;
}
+ /**
+ * @return integer
+ */
public function count()
{
- return count($this->_parts);
+ return count($this->parts);
+ }
+
+ /**
+ * @return array
+ */
+ public function getParts()
+ {
+ return $this->parts;
}
+ /**
+ * @return string
+ */
public function __tostring()
{
- return $this->_preSeparator . implode($this->_separator, $this->_parts) . $this->_postSeparator;
+ return $this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator;
}
}
View
22 lib/Doctrine/ORM/Query/Expr/Orx.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,18 +25,32 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Orx extends Composite
{
- protected $_separator = ' OR ';
- protected $_allowedClasses = array(
+ /**
+ * @var string
+ */
+ protected $separator = ' OR ';
+
+ /**
+ * @var array
+ */
+ protected $allowedClasses = array(
'Doctrine\ORM\Query\Expr\Comparison',
'Doctrine\ORM\Query\Expr\Func',
'Doctrine\ORM\Query\Expr\Andx',
'Doctrine\ORM\Query\Expr\Orx',
);
+
+ /**
+ * @return array
+ */
+ public function getParts()
+ {
+ return $this->parts;
+ }
}
View
28 lib/Doctrine/ORM/Query/Expr/Select.php
@@ -1,7 +1,5 @@
<?php
/*
- * $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
@@ -27,16 +25,34 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Select extends Base
{
- protected $_preSeparator = '';
- protected $_postSeparator = '';
- protected $_allowedClasses = array(
+ /**
+ * @var string
+ */
+ protected $preSeparator = '';
+
+ /**
+ * @var string
+ */
+ protected $postSeparator = '';
+
+ /**
+ * @var array
+ */
+ protected $allowedClasses = array(
'Doctrine\ORM\Query\Expr\Func'
);
+
+ /**
+ * @return array
+ */
+ public function getParts()
+ {
+ return $this->parts;
+ }
}
View
64 tests/Doctrine/Tests/ORM/Query/ExprTest.php
@@ -345,4 +345,68 @@ public function testBooleanLiteral()
$this->assertEquals('true', $this->_expr->literal(true));
$this->assertEquals('false', $this->_expr->literal(false));
}
+
+
+ /**
+ * @group DDC-1686
+ */
+ public function testExpressionGetter()
+ {
+
+ // Andx
+ $andx = new Expr\Andx(array('1 = 1', '2 = 2'));
+ $this->assertEquals(array('1 = 1', '2 = 2'), $andx->getParts());
+
+ // Comparison
+ $comparison = new Expr\Comparison('foo', Expr\Comparison::EQ, 'bar');
+ $this->assertEquals('foo', $comparison->getLeftExpr());
+ $this->assertEquals('bar', $comparison->getRightExpr());
+ $this->assertEquals(Expr\Comparison::EQ, $comparison->getOperator());
+
+ // From
+ $from = new Expr\From('Foo', 'f', 'f.id');
+ $this->assertEquals('f', $from->getAlias());
+ $this->assertEquals('Foo', $from->getFrom());
+ $this->assertEquals('f.id', $from->getIndexBy());
+
+ // Func
+ $func = new Expr\Func('MAX', array('f.id'));
+ $this->assertEquals('MAX', $func->getName());
+ $this->assertEquals(array('f.id'), $func->getArguments());
+
+ // GroupBy
+ $group = new Expr\GroupBy(array('foo DESC', 'bar ASC'));
+ $this->assertEquals(array('foo DESC', 'bar ASC'), $group->getParts());
+
+ // Join
+ $join = new Expr\Join(Expr\Join::INNER_JOIN, 'f.bar', 'b', Expr\Join::ON, 'b.bar_id = 1', 'b.bar_id');
+ $this->assertEquals(Expr\Join::INNER_JOIN, $join->getJoinType());
+ $this->assertEquals(Expr\Join::ON, $join->getConditionType());
+ $this->assertEquals('b.bar_id = 1', $join->getCondition());
+ $this->assertEquals('b.bar_id', $join->getIndexBy());
+ $this->assertEquals('f.bar', $join->getJoin());
+ $this->assertEquals('b', $join->getAlias());
+
+ // Literal
+ $literal = new Expr\Literal(array('foo'));
+ $this->assertEquals(array('foo'), $literal->getParts());
+
+ // Math
+ $math = new Expr\Math(10, '+', 20);
+ $this->assertEquals(10, $math->getLeftExpr());
+ $this->assertEquals(20, $math->getRightExpr());
+ $this->assertEquals('+', $math->getOperator());
+
+ // OrderBy
+ $order = new Expr\OrderBy('foo', 'DESC');
+ $this->assertEquals(array('foo DESC'), $order->getParts());
+
+ // Andx
+ $orx = new Expr\Orx(array('foo = 1', 'bar = 2'));
+ $this->assertEquals(array('foo = 1', 'bar = 2'), $orx->getParts());
+
+ // Select
+ $select = new Expr\Select(array('foo', 'bar'));
+ $this->assertEquals(array('foo', 'bar'), $select->getParts());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.