Skip to content

Commit

Permalink
Merge pull request #50 from phenixphp/release/0.5.2
Browse files Browse the repository at this point in the history
Release v0.5.2
  • Loading branch information
barbosa89 authored Jan 3, 2025
2 parents 6854886 + c8db3e0 commit 066d5bd
Show file tree
Hide file tree
Showing 54 changed files with 1,041 additions and 424 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Release Notes for 0.5.x

## [v0.5.2 (2025-01-03)](https://github.com/phenixphp/framework/compare/0.5.1...0.5.2)

### Added
- Session management with support for local in memory and redis drivers. ([#49](https://github.com/phenixphp/framework/pull/49))

## [v0.5.1 (2024-12-24)](https://github.com/phenixphp/framework/compare/0.5.0...0.5.1)

### Added
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
"php": "^8.2",
"ext-pcntl": "*",
"adbario/php-dot-notation": "^3.1",
"amphp/cache": "^2.0",
"amphp/file": "^v3.0.0",
"amphp/http-client": "^v5.0.1",
"amphp/http-server": "^v3.2.0",
"amphp/http-server-form-parser": "^2.0",
"amphp/http-server-router": "^v2.0.0",
"amphp/http-server-session": "^3.0",
"amphp/log": "^v2.0.0",
"amphp/mysql": "^v3.0.0",
"amphp/postgres": "v2.0.0",
"amphp/redis": "^2.0",
"amphp/socket": "^2.1.0",
"egulias/email-validator": "^4.0",
"fakerphp/faker": "^1.23",
Expand Down Expand Up @@ -82,6 +85,6 @@
"test:parallel": "vendor/bin/pest --parallel",
"format": "vendor/bin/php-cs-fixer fix",
"analyze": "vendor/bin/phpinsights",
"analyze:static": "vendor/bin/phpstan"
"analyze:static": "vendor/bin/phpstan --memory-limit=1G"
}
}
16 changes: 14 additions & 2 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
use Phenix\Facades\Route;
use Phenix\Logging\LoggerFactory;
use Phenix\Runtime\Log;
use Phenix\Session\SessionMiddleware;

class App implements AppContract, Makeable
{
private static string $path;
private static Container $container;
private string $host;
private RequestHandler $router;
private Logger $logger;
private SocketHttpServer $server;
Expand All @@ -46,6 +48,8 @@ public function setup(): void
\Phenix\Runtime\Config::build(...)
)->setShared(true);

$this->host = $this->getHost();

/** @var array $providers */
$providers = Config::get('app.providers', []);

Expand All @@ -69,10 +73,9 @@ public function run(): void

$this->setRouter();

$uri = Uri::new(Config::get('app.url'));
$port = (int) Config::get('app.port');

$this->server->expose(new Socket\InternetAddress($uri->getHost(), $port));
$this->server->expose(new Socket\InternetAddress($this->host, $port));

$this->server->start($this->router, $this->errorHandler);

Expand Down Expand Up @@ -142,6 +145,15 @@ private function setRouter(): void
/** @var array<int, Middleware> $globalMiddlewares */
$globalMiddlewares = array_map(fn (string $middleware) => new $middleware(), $middlewares['global']);

$globalMiddlewares[] = SessionMiddleware::make($this->host);

$this->router = Middleware\stackMiddleware($router, ...$globalMiddlewares);
}

private function getHost(): string
{
$uri = Uri::new(Config::get('app.url'));

return $uri->getHost();
}
}
24 changes: 12 additions & 12 deletions src/Database/Clause.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Phenix\Contracts\Database\Builder;
use Phenix\Database\Concerns\Query\HasWhereClause;
use Phenix\Database\Concerns\Query\PrepareColumns;
use Phenix\Database\Constants\LogicalOperators;
use Phenix\Database\Constants\Operators;
use Phenix\Database\Constants\LogicalOperator;
use Phenix\Database\Constants\Operator;
use Phenix\Database\Constants\SQL;
use Phenix\Util\Arr;

Expand All @@ -25,9 +25,9 @@ abstract class Clause implements Builder

protected function resolveWhereMethod(
string $column,
Operators $operator,
Operator $operator,
Closure|array|string|int $value,
LogicalOperators $logicalConnector = LogicalOperators::AND
LogicalOperator $logicalConnector = LogicalOperator::AND
): void {
if ($value instanceof Closure) {
$this->whereSubquery(
Expand All @@ -43,10 +43,10 @@ protected function resolveWhereMethod(

protected function whereSubquery(
Closure $subquery,
Operators $comparisonOperator,
Operator $comparisonOperator,
string|null $column = null,
Operators|null $operator = null,
LogicalOperators $logicalConnector = LogicalOperators::AND
Operator|null $operator = null,
LogicalOperator $logicalConnector = LogicalOperator::AND
): void {
$builder = new Subquery();
$builder->select(['*']);
Expand All @@ -64,9 +64,9 @@ protected function whereSubquery(

protected function pushWhereWithArgs(
string $column,
Operators $operator,
Operator $operator,
array|string|int $value,
LogicalOperators $logicalConnector = LogicalOperators::AND
LogicalOperator $logicalConnector = LogicalOperator::AND
): void {
$placeholders = is_array($value)
? array_fill(0, count($value), SQL::PLACEHOLDER->value)
Expand All @@ -77,7 +77,7 @@ protected function pushWhereWithArgs(
$this->arguments = array_merge($this->arguments, (array) $value);
}

protected function pushClause(array $where, LogicalOperators $logicalConnector = LogicalOperators::AND): void
protected function pushClause(array $where, LogicalOperator $logicalConnector = LogicalOperator::AND): void
{
if (count($this->clauses) > 0) {
array_unshift($where, $logicalConnector);
Expand All @@ -91,8 +91,8 @@ protected function prepareClauses(array $clauses): array
return array_map(function (array $clause): array {
return array_map(function ($value) {
return match (true) {
$value instanceof Operators => $value->value,
$value instanceof LogicalOperators => $value->value,
$value instanceof Operator => $value->value,
$value instanceof LogicalOperator => $value->value,
is_array($value) => '(' . Arr::implodeDeeply($value, ', ') . ')',
default => $value,
};
Expand Down
44 changes: 22 additions & 22 deletions src/Database/Concerns/Query/BuildsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Phenix\Database\Concerns\Query;

use Closure;
use Phenix\Database\Constants\Actions;
use Phenix\Database\Constants\Operators;
use Phenix\Database\Constants\Action;
use Phenix\Database\Constants\Operator;
use Phenix\Database\Constants\Order;
use Phenix\Database\Constants\SQL;
use Phenix\Database\Functions;
Expand Down Expand Up @@ -54,7 +54,7 @@ public function from(Closure|string $table): static

public function select(array $columns): static
{
$this->action = Actions::SELECT;
$this->action = Action::SELECT;

$this->columns = $columns;

Expand All @@ -70,7 +70,7 @@ public function selectAllColumns(): static

public function insert(array $data): static
{
$this->action = Actions::INSERT;
$this->action = Action::INSERT;

$this->prepareDataToInsert($data);

Expand All @@ -88,7 +88,7 @@ public function insertOrIgnore(array $values): static

public function upsert(array $values, array $columns): static
{
$this->action = Actions::INSERT;
$this->action = Action::INSERT;

$this->uniqueColumns = $columns;

Expand All @@ -110,7 +110,7 @@ public function insertFrom(Closure $subquery, array $columns, bool $ignore = fal

$this->arguments = array_merge($this->arguments, $arguments);

$this->action = Actions::INSERT;
$this->action = Action::INSERT;

$this->ignore = $ignore;

Expand All @@ -121,7 +121,7 @@ public function insertFrom(Closure $subquery, array $columns, bool $ignore = fal

public function update(array $values): static
{
$this->action = Actions::UPDATE;
$this->action = Action::UPDATE;

$this->values = $values;

Expand All @@ -130,7 +130,7 @@ public function update(array $values): static

public function delete(): static
{
$this->action = Actions::DELETE;
$this->action = Action::DELETE;

return $this;
}
Expand All @@ -142,7 +142,7 @@ public function groupBy(Functions|array|string $column)
default => $column,
};

$this->groupBy = [Operators::GROUP_BY->value, Arr::implodeDeeply((array) $column, ', ')];
$this->groupBy = [Operator::GROUP_BY->value, Arr::implodeDeeply((array) $column, ', ')];

return $this;
}
Expand All @@ -169,14 +169,14 @@ public function orderBy(SelectCase|array|string $column, Order $order = Order::D
default => $column,
};

$this->orderBy = [Operators::ORDER_BY->value, Arr::implodeDeeply((array) $column, ', '), $order->value];
$this->orderBy = [Operator::ORDER_BY->value, Arr::implodeDeeply((array) $column, ', '), $order->value];

return $this;
}

public function limit(int $number): static
{
$this->limit = [Operators::LIMIT->value, abs($number)];
$this->limit = [Operator::LIMIT->value, abs($number)];

return $this;
}
Expand All @@ -189,14 +189,14 @@ public function page(int $page = 1, int $perPage = 15): static

$offset = $page === 1 ? 0 : (($page - 1) * abs($perPage));

$this->offset = [Operators::OFFSET->value, $offset];
$this->offset = [Operator::OFFSET->value, $offset];

return $this;
}

public function count(string $column = '*'): static
{
$this->action = Actions::SELECT;
$this->action = Action::SELECT;

$this->columns = [Functions::count($column)];

Expand All @@ -205,18 +205,18 @@ public function count(string $column = '*'): static

public function exists(): static
{
$this->action = Actions::EXISTS;
$this->action = Action::EXISTS;

$this->columns = [Operators::EXISTS->value];
$this->columns = [Operator::EXISTS->value];

return $this;
}

public function doesntExist(): static
{
$this->action = Actions::EXISTS;
$this->action = Action::EXISTS;

$this->columns = [Operators::NOT_EXISTS->value];
$this->columns = [Operator::NOT_EXISTS->value];

return $this;
}
Expand All @@ -227,11 +227,11 @@ public function doesntExist(): static
public function toSql(): array
{
$sql = match ($this->action) {
Actions::SELECT => $this->buildSelectQuery(),
Actions::EXISTS => $this->buildExistsQuery(),
Actions::INSERT => $this->buildInsertSentence(),
Actions::UPDATE => $this->buildUpdateSentence(),
Actions::DELETE => $this->buildDeleteSentence(),
Action::SELECT => $this->buildSelectQuery(),
Action::EXISTS => $this->buildExistsQuery(),
Action::INSERT => $this->buildInsertSentence(),
Action::UPDATE => $this->buildUpdateSentence(),
Action::DELETE => $this->buildDeleteSentence(),
};

return [
Expand Down
Loading

0 comments on commit 066d5bd

Please sign in to comment.