本文整理汇总了PHP中Operator::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Operator::parse方法的具体用法?PHP Operator::parse怎么用?PHP Operator::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Operator
的用法示例。
在下文中一共展示了Operator::parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testParse
/**
* @covers Phramework\Models\Operator::parse
* @dataProvider parseProvider
*/
public function testParse($input, $expected)
{
list($expectedOperator, $expectedOperant) = $expected;
list($operator, $operant) = Operator::parse($input);
$this->assertEquals($operator, $expectedOperator);
$this->assertEquals($operant, $expectedOperant);
}
示例2: parse
/**
* Method to parse the columns to create $where and $param arrays
*
* @param array $columns
* @param string $placeholder
* @return array
*/
public static function parse($columns, $placeholder)
{
$params = [];
$where = [];
$i = 1;
foreach ($columns as $column => $value) {
if (!is_array($value) && substr($value, -3) == ' OR') {
$value = substr($value, 0, -3);
$combine = ' OR';
} else {
$combine = null;
}
$operator = Operator::parse($column);
if ($placeholder == ':') {
$pHolder = $placeholder . $operator['column'];
} else {
if ($placeholder == '$') {
$pHolder = $placeholder . $i;
} else {
$pHolder = $placeholder;
}
}
// IS NULL or IS NOT NULL
if (null === $value) {
if (substr($column, -1) == '-') {
$column = substr($column, 0, -1);
$where[] = $column . ' IS NOT NULL' . $combine;
} else {
$where[] = $column . ' IS NULL' . $combine;
}
// IN or NOT IN
} else {
if (is_array($value)) {
if (substr($column, -1) == '-') {
$column = substr($column, 0, -1);
$where[] = $column . ' NOT IN (' . implode(', ', $value) . ')' . $combine;
} else {
$where[] = $column . ' IN (' . implode(', ', $value) . ')' . $combine;
}
// BETWEEN or NOT BETWEEN
} else {
if (substr($value, 0, 1) == '(' && substr($value, -1) == ')' && strpos($value, ',') !== false) {
if (substr($column, -1) == '-') {
$column = substr($column, 0, -1);
$where[] = $column . ' NOT BETWEEN ' . $value . $combine;
} else {
$where[] = $column . ' BETWEEN ' . $value . $combine;
}
// LIKE or NOT LIKE
} else {
if (substr($value, 0, 2) == '-%' || substr($value, -2) == '%-' || substr($value, 0, 1) == '%' || substr($value, -1) == '%') {
$op = substr($value, 0, 2) == '-%' || substr($value, -2) == '%-' ? 'NOT LIKE' : 'LIKE';
$where[] = $column . ' ' . $op . ' ' . $pHolder . $combine;
if (substr($value, 0, 2) == '-%') {
$value = substr($value, 1);
}
if (substr($value, -2) == '%-') {
$value = substr($value, 0, -1);
}
if (isset($params[$column])) {
if (is_array($params[$column])) {
if ($placeholder == ':') {
$where[count($where) - 1] .= $i;
}
$params[$column][] = $value;
} else {
if ($placeholder == ':') {
$where[0] .= $i - 1;
$where[1] .= $i;
}
$params[$column] = [$params[$column], $value];
}
} else {
$params[$column] = $value;
}
// Standard operators
} else {
$column = $operator['column'];
$where[] = $column . ' ' . $operator['op'] . ' ' . $pHolder . $combine;
if (isset($params[$column])) {
if (is_array($params[$column])) {
if ($placeholder == ':') {
$where[count($where) - 1] .= $i;
}
$params[$column][] = $value;
} else {
if ($placeholder == ':') {
$where[0] .= $i - 1;
$where[1] .= $i;
}
$params[$column] = [$params[$column], $value];
}
} else {
//.........这里部分代码省略.........