for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace DBAL\Modifiers;
class Operators
{
const OPERATORS = array(
'>' => array(
'format' => '> ?',
'prepared' => true
),
'>=' => array(
'format' => '>= ?',
'<' => array(
'format' => '< ?',
'<=' => array(
'format' => '<= ?',
'!=' => array(
'format' => '!= ?',
'LIKE' => array(
'format' => 'LIKE ?',
'NOT LIKE' => array(
'format' => 'NOT LIKE ?',
'IN' => array(
'format' => 'IN (%s)',
'NOT IN' => array(
'format' => 'NOT IN (%s)',
'BETWEEN' => array(
'format' => 'BETWEEN ? AND ?',
'NOT BETWEEN' => array(
'format' => 'NOT BETWEEN ? AND ?',
'IS NULL' => array(
'format' => 'IS NULL',
'prepared' => false
'IS NOT NULL' => array(
'format' => 'IS NOT NULL',
)
);
/**
* Gets the correct formated string for the operator
* @param string $value This should be the operator value
* @return string The string to add to the database will be added
*/
public static function getOperatorFormat($value)
if (array_key_exists(strtoupper(strval($value)), self::OPERATORS)) {
return self::OPERATORS[strtoupper($value)]['format'];
}
return '= ?';
* Checks to see if the operator is valid
* @param string $operator This should be the operator value
* @return boolean If the operator exists in the array will return true else returns false
public static function isOperatorValid($operator)
if (array_key_exists(strtoupper(strval($operator)), self::OPERATORS)) {
return true;
return false;
* Checks to see if a prepared statement value should be added
* @return boolean If the operator should be prepared returns true else returns false
public static function isOperatorPrepared($value)
return self::OPERATORS[strtoupper(strval($value))]['prepared'];