Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / Sql / Predicate / Operator.php
blobcc2765cf67bb46bc7d9afcebae3243fcf580cd84
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Db\Sql\Predicate;
12 use Zend\Db\Sql\Exception;
14 class Operator implements PredicateInterface
16 const OPERATOR_EQUAL_TO = '=';
17 const OP_EQ = '=';
19 const OPERATOR_NOT_EQUAL_TO = '!=';
20 const OP_NE = '!=';
22 const OPERATOR_LESS_THAN = '<';
23 const OP_LT = '<';
25 const OPERATOR_LESS_THAN_OR_EQUAL_TO = '<=';
26 const OP_LTE = '<=';
28 const OPERATOR_GREATER_THAN = '>';
29 const OP_GT = '>';
31 const OPERATOR_GREATER_THAN_OR_EQUAL_TO = '>=';
32 const OP_GTE = '>=';
34 protected $allowedTypes = array(
35 self::TYPE_IDENTIFIER,
36 self::TYPE_VALUE,
39 protected $left = null;
40 protected $leftType = self::TYPE_IDENTIFIER;
41 protected $operator = self::OPERATOR_EQUAL_TO;
42 protected $right = null;
43 protected $rightType = self::TYPE_VALUE;
45 /**
46 * Constructor
48 * @param int|float|bool|string $left
49 * @param string $operator
50 * @param int|float|bool|string $right
51 * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes}
52 * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes}
54 public function __construct($left = null, $operator = self::OPERATOR_EQUAL_TO, $right = null, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE)
56 if ($left !== null) {
57 $this->setLeft($left);
60 if ($operator !== self::OPERATOR_EQUAL_TO) {
61 $this->setOperator($operator);
64 if ($right !== null) {
65 $this->setRight($right);
68 if ($leftType !== self::TYPE_IDENTIFIER) {
69 $this->setLeftType($leftType);
72 if ($rightType !== self::TYPE_VALUE) {
73 $this->setRightType($rightType);
77 /**
78 * Set left side of operator
80 * @param int|float|bool|string $left
81 * @return Operator
83 public function setLeft($left)
85 $this->left = $left;
86 return $this;
89 /**
90 * Get left side of operator
92 * @return int|float|bool|string
94 public function getLeft()
96 return $this->left;
99 /**
100 * Set parameter type for left side of operator
102 * @param string $type TYPE_IDENTIFIER or TYPE_VALUE {@see allowedTypes}
103 * @throws Exception\InvalidArgumentException
104 * @return Operator
106 public function setLeftType($type)
108 if (!in_array($type, $this->allowedTypes)) {
109 throw new Exception\InvalidArgumentException(sprintf(
110 'Invalid type "%s" provided; must be of type "%s" or "%s"',
111 $type,
112 __CLASS__ . '::TYPE_IDENTIFIER',
113 __CLASS__ . '::TYPE_VALUE'
116 $this->leftType = $type;
117 return $this;
121 * Get parameter type on left side of operator
123 * @return string
125 public function getLeftType()
127 return $this->leftType;
131 * Set operator string
133 * @param string $operator
134 * @return Operator
136 public function setOperator($operator)
138 $this->operator = $operator;
139 return $this;
143 * Get operator string
145 * @return string
147 public function getOperator()
149 return $this->operator;
153 * Set right side of operator
155 * @param int|float|bool|string $value
156 * @return Operator
158 public function setRight($value)
160 $this->right = $value;
161 return $this;
165 * Get right side of operator
167 * @return int|float|bool|string
169 public function getRight()
171 return $this->right;
175 * Set parameter type for right side of operator
177 * @param string $type TYPE_IDENTIFIER or TYPE_VALUE {@see allowedTypes}
178 * @throws Exception\InvalidArgumentException
179 * @return Operator
181 public function setRightType($type)
183 if (!in_array($type, $this->allowedTypes)) {
184 throw new Exception\InvalidArgumentException(sprintf(
185 'Invalid type "%s" provided; must be of type "%s" or "%s"',
186 $type,
187 __CLASS__ . '::TYPE_IDENTIFIER',
188 __CLASS__ . '::TYPE_VALUE'
191 $this->rightType = $type;
192 return $this;
196 * Get parameter type on right side of operator
198 * @return string
200 public function getRightType()
202 return $this->rightType;
206 * Get predicate parts for where statement
208 * @return array
210 public function getExpressionData()
212 return array(array(
213 '%s ' . $this->operator . ' %s',
214 array($this->left, $this->right),
215 array($this->leftType, $this->rightType)