Skip to content

Commit

Permalink
AND NOT and OR NOT
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Feb 8, 2016
1 parent 41a192c commit 01de3cf
Showing 1 changed file with 46 additions and 40 deletions.
86 changes: 46 additions & 40 deletions src/Syntax/Where.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace NilPortugues\Sql\QueryBuilder\Syntax;

use NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface;
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryException;
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryFactory;
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;

/**
Expand All @@ -29,7 +29,9 @@ class Where
const OPERATOR_EQUAL = '=';
const OPERATOR_NOT_EQUAL = '<>';
const CONJUNCTION_AND = 'AND';
const CONJUNCTION_AND_NOT = 'AND NOT';
const CONJUNCTION_OR = 'OR';
const CONJUNCTION_OR_NOT = 'OR NOT';
const CONJUNCTION_EXISTS = 'EXISTS';
const CONJUNCTION_NOT_EXISTS = 'NOT EXISTS';

Expand Down Expand Up @@ -149,6 +151,29 @@ public function getConjunction()
return $this->conjunction;
}

/**
* @param string $operator
*
* @return $this
*
* @throws QueryException
*/
public function conjunction($operator)
{
if (false === \in_array(
$operator,
[self::CONJUNCTION_AND, self::CONJUNCTION_OR, self::CONJUNCTION_OR_NOT, self::CONJUNCTION_AND_NOT]
)
) {
throw new QueryException(
"Invalid conjunction specified, must be one of AND or OR, but '".$operator."' was found."
);
}
$this->conjunction = $operator;

return $this;
}

/**
* @return array
*/
Expand All @@ -174,25 +199,6 @@ public function subWhere($operator = 'OR')
return $filter;
}

/**
* @param string $operator
*
* @return $this
*
* @throws QueryException
*/
public function conjunction($operator)
{
if (false === \in_array($operator, [self::CONJUNCTION_AND, self::CONJUNCTION_OR])) {
throw new QueryException(
"Invalid conjunction specified, must be one of AND or OR, but '".$operator."' was found."
);
}
$this->conjunction = $operator;

return $this;
}

/**
* @return Table
*/
Expand All @@ -218,7 +224,7 @@ public function setTable($table)
/**
* equals alias.
*
* @param $column
* @param $column
* @param int $value
*
* @return static
Expand All @@ -240,8 +246,8 @@ public function equals($column, $value)
}

/**
* @param $column
* @param $value
* @param $column
* @param $value
* @param string $operator
*
* @return $this
Expand Down Expand Up @@ -333,7 +339,7 @@ public function lessThanOrEqual($column, $value)

/**
* @param string $column
* @param $value
* @param $value
*
* @return static
*/
Expand Down Expand Up @@ -509,6 +515,14 @@ public function exists(Select $select)
return $this;
}

/**
* @return array
*/
public function getExists()
{
return $this->exists;
}

/**
* @param Select $select
*
Expand All @@ -521,6 +535,14 @@ public function notExists(Select $select)
return $this;
}

/**
* @return array
*/
public function getNotExists()
{
return $this->notExists;
}

/**
* @return array
*/
Expand Down Expand Up @@ -584,20 +606,4 @@ public function getNull()
{
return $this->isNull;
}

/**
* @return array
*/
public function getExists()
{
return $this->exists;
}

/**
* @return array
*/
public function getNotExists()
{
return $this->notExists;
}
}

0 comments on commit 01de3cf

Please sign in to comment.