Skip to content

Commit

Permalink
#13 removed ParameterBag from the library
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinKuklin committed Oct 3, 2014
1 parent c8e3d7b commit 6cdb530
Show file tree
Hide file tree
Showing 27 changed files with 638 additions and 613 deletions.
2 changes: 1 addition & 1 deletion src/HS/Builder/DeleteQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getQueryClassPath()
public function where($comparison, array $list)
{
$columnList = array_keys($list);
$this->getParameterBag()->setParameter('columnList', $columnList);
$this->columnList = $columnList;
parent::where($comparison, $list);

return $this;
Expand Down
45 changes: 21 additions & 24 deletions src/HS/Builder/FindQueryBuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use HS\Component\Filter;
use HS\Component\InList;
use HS\Exception\InvalidArgumentException;
use HS\Query\SelectQuery;

/**
* @author KonstantinKuklin <[email protected]>
Expand All @@ -16,7 +17,7 @@ abstract class FindQueryBuilderAbstract extends QueryBuilderAbstract
*/
public function __construct(array $columnList)
{
parent::__construct(array('columnList' => $columnList));
$this->columnList = $columnList;
}

/**
Expand All @@ -26,7 +27,7 @@ public function __construct(array $columnList)
*/
public function fromDataBase($databaseName)
{
$this->getParameterBag()->setParameter('dbName', $databaseName);
$this->dbName = $databaseName;

return $this;
}
Expand All @@ -38,7 +39,7 @@ public function fromDataBase($databaseName)
*/
public function fromTable($tableName)
{
$this->getParameterBag()->setParameter('tableName', $tableName);
$this->tableName = $tableName;

return $this;
}
Expand All @@ -50,7 +51,7 @@ public function fromTable($tableName)
*/
public function fromIndex($indexName)
{
$this->getParameterBag()->setParameter('indexName', $indexName);
$this->indexName = $indexName;

return $this;
}
Expand All @@ -60,7 +61,7 @@ public function fromIndex($indexName)
*/
public function getColumnList()
{
return $this->getParameter('columnList', array());
return $this->columnList;
}

/**
Expand All @@ -72,9 +73,9 @@ public function getColumnList()
*/
public function where($comparison, array $list)
{
$this->getParameterBag()->setParameter('comparison', $comparison);
$keyList = $this->getParameter('keyList', array());
$this->comparison = $comparison;
$columnList = $this->getColumnList();

// check is ordered list of keys
for ($i = 0, $countWhere = count($list); $i < $countWhere; $i++) {
$key = $columnList[$i];
Expand All @@ -83,9 +84,8 @@ public function where($comparison, array $list)
"The key`s must be set with out skip on select( key1, key2). Where(key2,key1)"
);
}
$keyList[] = $list[$key];
$this->keyList[] = $list[$key];
}
$this->getParameterBag()->setParameter('keyList', $keyList);

return $this;
}
Expand All @@ -100,14 +100,14 @@ public function where($comparison, array $list)
public function whereIn($key, array $values)
{
$columnList = $this->getColumnList();
$this->getParameterBag()->setParameter('comparison', Comparison::EQUAL);
$this->getParameterBag()->setParameter('keyList', array(1));
$this->comparison = Comparison::EQUAL;
$this->keyList = array(1);

if (false === $index = array_search($key, $columnList)) {
throw new InvalidArgumentException("Can't find key in columns list.");
}
$inList = new InList($index, $values);
$this->getParameterBag()->setParameter('inKeyList', $inList);
$this->inKeyList = $inList;

return $this;
}
Expand All @@ -122,16 +122,13 @@ public function whereIn($key, array $values)
*/
public function andWhere($columnName, $comparison, $key, $type = Filter::FILTER_TYPE_SKIP)
{
$filterColumnList = $this->getParameter('filterColumnList', array());
$position = array_search($columnName, $filterColumnList);
$position = array_search($columnName, $this->filterColumnList);
if ($position === false) {
$filterColumnList[] = $columnName;
$position = count($filterColumnList) - 1;
$this->getParameterBag()->setParameter('filterColumnList', $filterColumnList);
$this->filterColumnList[] = $columnName;
$position = count($this->filterColumnList) - 1;
}
$filter = new Filter($comparison, $position, $key, $type);

$this->getParameterBag()->addRowToParameter('filterList', $filter);
$this->filterList[] = $filter;

return $this;
}
Expand All @@ -141,15 +138,15 @@ public function andWhere($columnName, $comparison, $key, $type = Filter::FILTER_
*/
public function getFilterList()
{
return $this->getParameter('filterList', array());
return $this->filterList;
}

/**
* @return array
*/
public function getFilterColumnList()
{
return $this->getParameter('filterColumnList', array());
return $this->filterColumnList;
}

/**
Expand All @@ -159,7 +156,7 @@ public function getFilterColumnList()
*/
public function limit($limit)
{
$this->getParameterBag()->setParameter('limit', $limit);
$this->limit = $limit;

return $this;
}
Expand All @@ -171,7 +168,7 @@ public function limit($limit)
*/
public function offset($offset)
{
$this->getParameterBag()->setParameter('offset', $offset);
$this->offset = $offset;

return $this;
}
Expand All @@ -181,7 +178,7 @@ public function offset($offset)
*/
public function withSuffix()
{
$this->getParameterBag()->setParameter('suffix', true);
$this->suffix = true;

return $this;
}
Expand Down
19 changes: 9 additions & 10 deletions src/HS/Builder/InsertQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class InsertQueryBuilder extends QueryBuilderAbstract

public function __construct()
{
parent::__construct(array());
}

/**
Expand All @@ -20,10 +19,10 @@ public function __construct()
*/
public function addRow(array $row)
{
if ($this->getParameter('columnList') === null) {
$this->getParameterBag()->setParameter('columnList', array_keys($row));
if (empty($this->columnList)) {
$this->columnList = array_keys($row);
}
$this->getParameterBag()->addRowToParameter('valueList', array_values($row));
$this->valueList[] = array_values($row);

return $this;
}
Expand All @@ -49,7 +48,7 @@ public function addRowList(array $rowList)
*/
public function toDatabase($dbName)
{
$this->getParameterBag()->setParameter('dbName', $dbName);
$this->dbName = $dbName;

return $this;
}
Expand All @@ -61,7 +60,7 @@ public function toDatabase($dbName)
*/
public function toTable($tableName)
{
$this->getParameterBag()->setParameter('tableName', $tableName);
$this->tableName = $tableName;

return $this;
}
Expand All @@ -73,7 +72,7 @@ public function toTable($tableName)
*/
public function toIndex($indexName)
{
$this->getParameterBag()->setParameter('indexName', $indexName);
$this->indexName = $indexName;

return $this;
}
Expand All @@ -83,7 +82,7 @@ public function toIndex($indexName)
*/
public function getQueryClassPath()
{
return "HS\\Query\\InsertQuery";
return 'HS\Query\InsertQuery';
}

/**
Expand All @@ -93,7 +92,7 @@ public function getQueryClassPath()
*/
public function limit($limit)
{
$this->getParameterBag()->setParameter('limit', $limit);
$this->limit = $limit;

return $this;
}
Expand All @@ -105,7 +104,7 @@ public function limit($limit)
*/
public function offset($offset)
{
$this->getParameterBag()->setParameter('offset', $offset);
$this->offset = $offset;

return $this;
}
Expand Down
Loading

0 comments on commit 6cdb530

Please sign in to comment.