示例#1
0
 /**
  * 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);
 }
示例#2
0
 /**
  * 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()))));
 }
示例#3
0
 /**
  * @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;
 }
示例#4
0
 /**
  * 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())));
 }
示例#5
0
文件: Union.php 项目: harp-orm/query
 /**
  * @param  Query\Union $query
  * @return array
  */
 public static function parameters(Query\Union $query)
 {
     return Compiler::parameters(array($query->getSelects(), $query->getOrder()));
 }
示例#6
0
文件: Update.php 项目: harp-orm/query
 /**
  * @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()));
 }
示例#7
0
 /**
  * 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;
 }
示例#8
0
 /**
  * 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()));
 }
示例#9
0
文件: Select.php 项目: harp-orm/query
 /**
  * @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()));
 }
示例#10
0
 /**
  * @return string
  */
 public function humanize()
 {
     return Compiler::humanize($this->sql(), $this->getParameters());
 }
示例#11
0
文件: Join.php 项目: harp-orm/query
 /**
  * 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));
 }
示例#12
0
文件: Set.php 项目: harp-orm/query
 /**
  * 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)));
 }
示例#13
0
 /**
  * @dataProvider dataParameters
  * @covers ::parameters
  */
 public function testParameters($items, $expected)
 {
     $this->assertEquals($expected, Compiler::parameters($items));
 }
示例#14
0
文件: Insert.php 项目: harp-orm/query
 /**
  * @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()));
 }