コード例 #1
0
 protected function makeRightColumnFn($key, $value)
 {
     if (is_scalar($value)) {
         $value = [$value];
     }
     if (preg_match('/(#?)([a-zA-Z0-9_\\-\\.\\+\\*\\/]*)\\s*/i', $key, $match)) {
         $fn = $match[2];
         $reflection = new ReflectionMySQLFunction($fn);
         if (!$reflection->isDefined()) {
             return null;
         }
         if (is_array($value) && (count($value) >= $reflection->getNumberOfRequiredParameters() && count($value) <= $reflection->getNumberOfParameters())) {
             $stack = [];
             foreach ($value as $k => $v) {
                 if ($v[0] == "#" || is_array($v)) {
                     array_push($stack, $this->makeRightColumn($k, $v));
                 } elseif (is_scalar($v)) {
                     array_push($stack, $this->addParam($v));
                 }
             }
             if ($reflection->isInfix()) {
                 return "(" . implode(" {$fn} ", $stack) . ")";
             } else {
                 return "{$fn}(" . implode(", ", $stack) . ")";
             }
         }
     } else {
         throw new Exception();
     }
     return null;
 }
コード例 #2
0
 protected function makeColumnFn($key, $value)
 {
     if (is_scalar($value)) {
         $value = [$value];
     }
     preg_match('/([a-zA-Z0-9_\\-\\.\\+\\-\\*\\/]*)\\s*\\(([a-zA-Z0-9_\\-]*)\\)/i', $key, $match);
     if (isset($match[1], $match[2])) {
         $fn = $match[1];
         $alias = $match[2];
     } else {
         $fn = $key;
         $alias = null;
     }
     $reflection = new ReflectionMySQLFunction($fn);
     if (!$reflection->isDefined()) {
         return null;
     }
     if (is_array($value) && (count($value) >= $reflection->getNumberOfRequiredParameters() && count($value) <= $reflection->getNumberOfParameters())) {
         $stack = [];
         foreach ($value as $k => $v) {
             array_push($stack, $this->makeColumn($k, $v));
         }
         if ($reflection->isInfix()) {
             return "(" . implode(" {$fn} ", $stack) . ")" . ($alias ? " AS {$this->columnQuote($alias)}" : "");
         } else {
             return "{$fn}(" . implode(", ", $stack) . ")" . ($alias ? " AS {$this->columnQuote($alias)}" : "");
         }
     }
     return null;
 }