Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 7, 2016
1 parent bbad472 commit 31e1b1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/Bridges/DatabaseDI/DatabaseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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']);
Expand All @@ -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'])
Expand All @@ -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']);

Expand All @@ -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"));
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/Database/Table/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}


Expand Down

0 comments on commit 31e1b1c

Please sign in to comment.