當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。