From 1d315f5e6c61297bb30201fc380b2260acf3ca2c Mon Sep 17 00:00:00 2001 From: Vitalii Date: Wed, 13 Jan 2021 13:30:09 +0300 Subject: [PATCH] Add factory method for Column (#35) --- src/Query/BaseBuilder.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Query/BaseBuilder.php b/src/Query/BaseBuilder.php index a4b8447..1476ff3 100644 --- a/src/Query/BaseBuilder.php +++ b/src/Query/BaseBuilder.php @@ -227,6 +227,16 @@ public function addSelect(...$columns) return $this; } + /** + * A factory method for Column. + * + * @return Column + */ + protected function makeColumn(): Column + { + return new Column($this); + } + /** * Prepares columns given by user to Column objects. * @@ -242,7 +252,7 @@ protected function processColumns(array $columns, bool $withAliases = true): arr foreach ($columns as $column => $value) { if ($value instanceof Closure) { $columnName = $column; - $column = (new Column($this)); + $column = $this->makeColumn(); if (!is_int($columnName)) { $column->name($columnName); @@ -257,7 +267,7 @@ protected function processColumns(array $columns, bool $withAliases = true): arr if ($value instanceof BaseBuilder) { $alias = is_string($column) ? $column : null; - $column = (new Column($this))->query($value); + $column = $this->makeColumn()->query($value); if (!is_null($alias) && $withAliases) { $column->as($alias); @@ -272,7 +282,7 @@ protected function processColumns(array $columns, bool $withAliases = true): arr if (!$column instanceof Column) { $alias = is_string($value) ? $value : null; - $column = (new Column($this))->name($column); + $column = $this->makeColumn()->name($column); if (!is_null($alias) && $withAliases) { $column->as($alias);