/** * Replace ? for arrays with (?, ?, ?) * * @param string $content * @param array $parameters * @return string */ public static function expandParameterArrays($content, array $parameters) { return preg_replace_callback('/\\?/', function () use(&$parameters) { $parameter = current(each($parameters)); return is_array($parameter) ? Compiler::toPlaceholders($parameter) : '?'; }, $content); }
/** * Render SQL for Aliased * * @param SQL\Aliased $aliased * @return string */ public static function render(SQL\Aliased $aliased) { $content = $aliased->getContent(); if ($content instanceof Query\Select) { $content = "(" . Select::render($content) . ")"; } else { $content = Compiler::name($content); } return Compiler::expression(array($content, Compiler::word('AS', Compiler::name($aliased->getAlias())))); }
/** * @param mixed $name * @return mixed */ public static function name($name) { if (is_string($name)) { $parts = explode('.', $name); $parts = array_map(function ($part) { return Compiler::escapeName($part); }, $parts); return implode('.', $parts); } return $name; }
/** * Render Columns object * @param SQL\Columns $item * @return string */ public static function renderItem(SQL\Columns $item) { return Compiler::braced(Arr::join(', ', Arr::map(__NAMESPACE__ . '\\Compiler::name', $item->all()))); }
/** * @param Query\Union $query * @return array */ public static function parameters(Query\Union $query) { return Compiler::parameters(array($query->getSelects(), $query->getOrder())); }
/** * @param Query\Update $query * @return array */ public static function parameters(Query\Update $query) { return Compiler::parameters(array($query->getTable(), $query->getJoin(), $query->getSet(), $query->getWhere(), $query->getOrder(), $query->getLimit())); }
/** * Logs with an arbitrary level. * * @param mixed $level * @param string $message * @param array $context * @return null */ public function log($level, $message, array $context = array()) { $this->entries[] = isset($context['parameters']) ? Compiler::humanize($message, $context['parameters']) : $message; }
/** * Render a Direction object * * @param SQL\Direction $item * @return string */ public static function render(SQL\Direction $item) { return Compiler::expression(array(Compiler::name($item->getContent()), $item->getDirection())); }
/** * @param Query\Select $query * @return array */ public static function parameters(Query\Select $query) { return Compiler::parameters(array($query->getColumns(), $query->getFrom(), $query->getJoin(), $query->getWhere(), $query->getGroup(), $query->getHaving(), $query->getOrder(), $query->getLimit(), $query->getOffset())); }
/** * @return string */ public function humanize() { return Compiler::humanize($this->sql(), $this->getParameters()); }
/** * Render a Join object * * @param SQL\Join $join * @return string */ public static function render(SQL\Join $join) { $condition = $join->getCondition(); $table = $join->getTable(); return Compiler::expression(array($join->getType(), 'JOIN', $table instanceof SQL\Aliased ? Aliased::render($table) : $table, is_array($condition) ? self::renderArrayCondition($condition) : $condition)); }
/** * Render a Set object * @param SQL\Set $item * @return string */ public static function render(SQL\Set $item) { return Compiler::expression(array(Compiler::name($item->getContent()), '=', self::renderValue($item))); }
/** * @dataProvider dataParameters * @covers ::parameters */ public function testParameters($items, $expected) { $this->assertEquals($expected, Compiler::parameters($items)); }
/** * @param Query\Insert $query * @return array */ public static function parameters(Query\Insert $query) { return Compiler::parameters(array($query->getTable(), $query->getSet(), $query->getValues(), $query->getSelect())); }