Example #1
0
 /**
  * @param  mixed  $child
  */
 public function __construct($child)
 {
     if (!$child instanceof ExpressionInterface) {
         $child = is_array($child) ? e\in($child) : e\eq($child);
     }
     $this->child = $child;
     parent::__construct('NOT (%s)', $this->child->getBinds());
 }
Example #2
0
 /**
  * @return  array
  */
 private function compilePart($alias, $type, $expr, array $params)
 {
     $ret = [];
     // Passing a simple string like 'foo.bar = ?', [$bar] should
     // work fine, so we can skip the complicated array syntax.
     if (is_string($expr)) {
         return [['expr' => $expr, 'params' => $params, 'type' => $type]];
     }
     // Allow passing completely bare expressions.
     if ($expr instanceof ExpressionInterface) {
         return [['expr' => $expr->getExpr($alias), 'params' => $expr->getBinds(), 'type' => $type]];
     }
     foreach ($expr as $column => $value) {
         // Allow passing a literal string, which is useful for
         // completely literal expressions (such as those used for joins).
         if (is_int($column)) {
             $ret[] = ['expr' => $value, 'type' => $type, 'params' => []];
             continue;
         }
         // Try and provide a table alias if possible.
         $column = e\columnize($column, $alias);
         // And automatically detect an IN if possible.
         if (is_array($value)) {
             $value = e\in($value);
         }
         if (!$value instanceof ExpressionInterface) {
             $value = e\eq($value);
         }
         $ret[] = ['expr' => $value->getExpr($column), 'params' => $value->getBinds(), 'type' => $type];
     }
     return $ret;
 }