Skip to content

Commit

Permalink
finalize - two methods
Browse files Browse the repository at this point in the history
  • Loading branch information
forrest79 committed Apr 25, 2024
1 parent e7e7371 commit 03873b7
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 72 deletions.
21 changes: 14 additions & 7 deletions src/Db/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,22 @@ public function setRowFactory(RowFactory $rowFactory): static


/**
* @param \Closure(Row): void|non-empty-array<string, callable> $fetchMutator
* @param \Closure(Row): void $rowFetchMutator
*/
public function setFetchMutator(\Closure|array $fetchMutator): self
public function setRowFetchMutator(\Closure $rowFetchMutator): self
{
if (is_array($fetchMutator)) {
$this->columnsFetchMutator = $fetchMutator;
} else {
$this->rowFetchMutator = $fetchMutator;
}
$this->rowFetchMutator = $rowFetchMutator;

return $this;
}


/**
* @param non-empty-array<string, callable> $columnsFetchMutator
*/
public function setColumnsFetchMutator(array $columnsFetchMutator): self
{
$this->columnsFetchMutator = $columnsFetchMutator;

return $this;
}
Expand Down
33 changes: 22 additions & 11 deletions src/Fluent/QueryExecute.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class QueryExecute extends Query implements \Countable, \IteratorAggregate
/** @var \Closure(Db\Row): void|NULL */
private \Closure|NULL $rowFetchMutator = NULL;

/** @var array<string, \Closure(mixed): mixed> */
/** @var array<string, callable> */
private array $columnsFetchMutator = [];


Expand All @@ -28,18 +28,29 @@ public function __construct(QueryBuilder $queryBuilder, Db\Connection $connectio


/**
* @param \Closure(Db\Row): void|non-empty-array<string, \Closure(mixed): mixed> $fetchMutator
* @param \Closure(Db\Row): void $rowFetchMutator
*/
public function setFetchMutator(\Closure|array $fetchMutator): self
public function setRowFetchMutator(\Closure $rowFetchMutator): self
{
if ($this->result !== NULL) {
$this->result->setFetchMutator($fetchMutator);
$this->result->setRowFetchMutator($rowFetchMutator);
} else {
if (is_array($fetchMutator)) {
$this->columnsFetchMutator = $fetchMutator;
} else {
$this->rowFetchMutator = $fetchMutator;
}
$this->rowFetchMutator = $rowFetchMutator;
}

return $this;
}


/**
* @param non-empty-array<string, callable> $columnsFetchMutator
*/
public function setColumnsFetchMutator(array $columnsFetchMutator): self
{
if ($this->result !== NULL) {
$this->result->setColumnsFetchMutator($columnsFetchMutator);
} else {
$this->columnsFetchMutator = $columnsFetchMutator;
}

return $this;
Expand Down Expand Up @@ -71,11 +82,11 @@ public function execute(): Db\Result
$this->result = $this->connection->query($this->createSqlQuery());

if ($this->rowFetchMutator !== NULL) {
$this->result->setFetchMutator($this->rowFetchMutator);
$this->result->setRowFetchMutator($this->rowFetchMutator);
}

if ($this->columnsFetchMutator !== []) {
$this->result->setFetchMutator($this->columnsFetchMutator);
$this->result->setColumnsFetchMutator($this->columnsFetchMutator);
}
}

Expand Down
Loading

0 comments on commit 03873b7

Please sign in to comment.