当前位置: 首页>>代码示例>>PHP>>正文


PHP Operator::parse方法代码示例

本文整理汇总了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);
 }
开发者ID:phramework,项目名称:phramework,代码行数:11,代码来源:OperatorTest.php

示例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 {
//.........这里部分代码省略.........
开发者ID:popphp,项目名称:pop-db,代码行数:101,代码来源:Column.php


注:本文中的Operator::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。