From 31e1b1c6ba815bbde6791960437927e79b659a1f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 7 May 2016 13:09:39 +0200 Subject: [PATCH] refactoring --- src/Bridges/DatabaseDI/DatabaseExtension.php | 16 ++++++++-------- src/Database/Table/Selection.php | 11 ++++------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Bridges/DatabaseDI/DatabaseExtension.php b/src/Bridges/DatabaseDI/DatabaseExtension.php index b6e7a05ea..9a3b670f2 100644 --- a/src/Bridges/DatabaseDI/DatabaseExtension.php +++ b/src/Bridges/DatabaseDI/DatabaseExtension.php @@ -62,7 +62,7 @@ public function loadConfiguration() private function setupDatabase($config, $name) { - $container = $this->getContainerBuilder(); + $builder = $this->getContainerBuilder(); foreach ((array) $config['options'] as $key => $value) { if (preg_match('#^PDO::\w+\z#', $key)) { @@ -71,11 +71,11 @@ private function setupDatabase($config, $name) } } - $connection = $container->addDefinition($this->prefix("$name.connection")) + $connection = $builder->addDefinition($this->prefix("$name.connection")) ->setClass(Nette\Database\Connection::class, [$config['dsn'], $config['user'], $config['password'], $config['options']]) ->setAutowired($config['autowired']); - $structure = $container->addDefinition($this->prefix("$name.structure")) + $structure = $builder->addDefinition($this->prefix("$name.structure")) ->setClass(Nette\Database\Structure::class) ->setArguments([$connection]) ->setAutowired($config['autowired']); @@ -94,7 +94,7 @@ private function setupDatabase($config, $name) $conventions = NULL; } elseif (is_string($config['conventions'])) { - $conventions = $container->addDefinition($this->prefix("$name.$conventionsServiceName")) + $conventions = $builder->addDefinition($this->prefix("$name.$conventionsServiceName")) ->setClass(preg_match('#^[a-z]+\z#i', $config['conventions']) ? 'Nette\Database\Conventions\\' . ucfirst($config['conventions']) . 'Conventions' : $config['conventions']) @@ -106,7 +106,7 @@ private function setupDatabase($config, $name) $conventions = reset($tmp); } - $container->addDefinition($this->prefix("$name.context")) + $builder->addDefinition($this->prefix("$name.context")) ->setClass(Nette\Database\Context::class, [$connection, $structure, $conventions]) ->setAutowired($config['autowired']); @@ -120,9 +120,9 @@ private function setupDatabase($config, $name) } if ($this->name === 'database') { - $container->addAlias($this->prefix($name), $this->prefix("$name.connection")); - $container->addAlias("nette.database.$name", $this->prefix($name)); - $container->addAlias("nette.database.$name.context", $this->prefix("$name.context")); + $builder->addAlias($this->prefix($name), $this->prefix("$name.connection")); + $builder->addAlias("nette.database.$name", $this->prefix($name)); + $builder->addAlias("nette.database.$name.context", $this->prefix("$name.context")); } } diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 9f95eda27..6fd24d114 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -342,7 +342,7 @@ public function joinWhere($tableChain, $condition, ...$params) /** * Adds condition, more calls appends with AND. * @param string condition possibly containing ? - * @return self + * @return void */ protected function condition($condition, array $params, $tableChain = NULL) { @@ -355,14 +355,11 @@ protected function condition($condition, array $params, $tableChain = NULL) $this->condition($key, [$val], $tableChain); // where('column', 1) } } + } elseif ($tableChain) { + $this->sqlBuilder->addJoinCondition($tableChain, $condition, ...$params); } else { - if ($tableChain) { - $this->sqlBuilder->addJoinCondition($tableChain, $condition, ...$params); - } else { - $this->sqlBuilder->addWhere($condition, ...$params); - } + $this->sqlBuilder->addWhere($condition, ...$params); } - return $this; }