Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/Libraries/Database/Sleekdb/Statements/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ trait Result

/**
* @inheritDoc
* @throws \Quantum\Exceptions\DatabaseException
* @throws \SleekDB\Exceptions\IOException
* @throws \SleekDB\Exceptions\InvalidArgumentException
* @throws \SleekDB\Exceptions\InvalidConfigurationException
*/
public function get()
{
Expand All @@ -37,61 +35,57 @@ public function get()

/**
* @inheritDoc
* @throws \Quantum\Exceptions\DatabaseException
* @throws \SleekDB\Exceptions\IOException
* @return \Quantum\Libraries\Database\DbalInterface
* @throws \SleekDB\Exceptions\InvalidArgumentException
* @throws \SleekDB\Exceptions\InvalidConfigurationException
*/
public function findOne(int $id): DbalInterface
{
$result = $this->getOrmModel()->findById($id);

$this->data = $result;
$this->modifiedFields = $result;
$this->isNew = false;

return $this;
}

/**
* @inheritDoc
* @throws \Quantum\Exceptions\DatabaseException
* @throws \SleekDB\Exceptions\IOException
* @throws \SleekDB\Exceptions\InvalidArgumentException
* @throws \SleekDB\Exceptions\InvalidConfigurationException
*/
public function findOneBy(string $column, $value): DbalInterface
{
$result = $this->getOrmModel()->findOneBy([$column, '=', $value]);

$this->data = $result;
$this->modifiedFields = $result;
$this->isNew = false;

return $this;
}

/**
* @inheritDoc
* @throws \Quantum\Exceptions\DatabaseException
* @return \Quantum\Libraries\Database\DbalInterface
* @throws \SleekDB\Exceptions\IOException
* @throws \SleekDB\Exceptions\InvalidArgumentException
* @throws \SleekDB\Exceptions\InvalidConfigurationException
*/
public function first(): DbalInterface
{
$result = $this->getBuilder()->getQuery()->first();

$this->data = $result;
$this->modifiedFields = $result;
$this->isNew = false;

return $this;
}

/**
* @inheritDoc
* @throws \Quantum\Exceptions\DatabaseException
* @throws \SleekDB\Exceptions\IOException
* @throws \SleekDB\Exceptions\InvalidArgumentException
* @throws \SleekDB\Exceptions\InvalidConfigurationException
*/
public function count(): int
{
Expand Down
10 changes: 7 additions & 3 deletions src/Mvc/QtModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ public function setOrm(DbalInterface $orm)

/**
* Fills the object properties
* @param array $arguments
* @param array $props
* @return \Quantum\Mvc\QtModel
* @throws \Quantum\Exceptions\ModelException
*/
public function fillObjectProps(array $arguments): QtModel
public function fillObjectProps(array $props): QtModel
{
foreach ($arguments as $key => $value) {
foreach ($props as $key => $value) {
if ($key == $this->idColumn) {
continue;
}

if (!in_array($key, $this->fillable)) {
throw ModelException::inappropriateProperty($key);
}
Expand Down
23 changes: 11 additions & 12 deletions src/Routes/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class Route
*/
private $module;

/**
/**`
* Identifies the group middleware
* @var bool
*/
private $isGroupeMiddlewares;
private $isGroupMiddlewares;

/**
* Identifies the group
* @var boolean
*/
private $isGroupe = false;
private $isGroup = false;

/**
* Current group name
Expand Down Expand Up @@ -138,10 +138,10 @@ public function group(string $groupName, Closure $callback): self
{
$this->currentGroupName = $groupName;

$this->isGroupe = true;
$this->isGroupeMiddlewares = false;
$this->isGroup = true;
$this->isGroupMiddlewares = false;
$callback($this);
$this->isGroupeMiddlewares = true;
$this->isGroupMiddlewares = true;
$this->currentGroupName = null;

return $this;
Expand All @@ -154,23 +154,22 @@ public function group(string $groupName, Closure $callback): self
*/
public function middlewares(array $middlewares = []): self
{
if (!$this->isGroupe) {
if (!$this->isGroup) {
end($this->virtualRoutes['*']);
$lastKey = key($this->virtualRoutes['*']);
$this->virtualRoutes['*'][$lastKey]['middlewares'] = $middlewares;
} else {
end($this->virtualRoutes);
$lastKeyOfFirstRound = key($this->virtualRoutes);

if (!$this->isGroupeMiddlewares) {
if (!$this->isGroupMiddlewares) {
end($this->virtualRoutes[$lastKeyOfFirstRound]);
$lastKeyOfSecondRound = key($this->virtualRoutes[$lastKeyOfFirstRound]);
$this->virtualRoutes[$lastKeyOfFirstRound][$lastKeyOfSecondRound]['middlewares'] = $middlewares;
} else {
$this->isGroupe = false;
$this->isGroup = false;
foreach ($this->virtualRoutes[$lastKeyOfFirstRound] as &$route) {
$hasMiddleware = end($route);
if (!is_array($hasMiddleware)) {
if(!key_exists('middlewares', $route)) {
$route['middlewares'] = $middlewares;
} else {
$reversedMiddlewares = array_reverse($middlewares);
Expand All @@ -197,7 +196,7 @@ public function name(string $name): self
throw RouteException::nameBeforeDefinition();
}

if ($this->isGroupeMiddlewares) {
if ($this->isGroupMiddlewares) {
throw RouteException::nameOnGroup();
}

Expand Down