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
35 changes: 24 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup MySQL
uses: mirromutth/mysql-action@v1.1
with:
host port: 3306
container port: 3306
character set server: 'utf8mb4'
collation server: 'utf8mb4_general_ci'
mysql version: '5.7'
mysql database: 'test_db'
mysql root password: 'password'

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -46,6 +35,30 @@ jobs:
- name: Set Docker containers
run: docker compose up -d

- name: Wait for MySQL to be ready
run: |
echo "Waiting for MySQL to be ready..."
for i in {1..30}; do
if docker exec bowphp_mysql mysqladmin ping -h localhost -u root -ppassword --silent 2>/dev/null; then
echo "MySQL is ready!"
break
fi
echo "Waiting for MySQL... ($i/30)"
sleep 2
done

- name: Wait for PostgreSQL to be ready
run: |
echo "Waiting for PostgreSQL to be ready..."
for i in {1..30}; do
if docker exec bowphp_postgres pg_isready -U postgres --silent 2>/dev/null; then
echo "PostgreSQL is ready!"
break
fi
echo "Waiting for PostgreSQL... ($i/30)"
sleep 2
done

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
Expand Down
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,41 @@ services:
interval: 10s
timeout: 5s
retries: 5
zookeeper:
container_name: bowphp_zookeeper
image: confluentinc/cp-zookeeper:7.5.0
restart: unless-stopped
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
networks:
- bowphp_network
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "2181"]
interval: 10s
timeout: 5s
retries: 5
kafka:
container_name: bowphp_kafka
image: confluentinc/cp-kafka:7.5.0
restart: unless-stopped
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
depends_on:
- zookeeper
networks:
- bowphp_network
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "9092"]
interval: 15s
timeout: 10s
retries: 5

2 changes: 1 addition & 1 deletion src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function run(): bool

// We launch the search of the method that arrived in the query
// then start checking the url of the request
if (!$route->match($this->request->path())) {
if (!$route->match($this->request->path(), $this->request->domain())) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Console/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class WorkerCommand extends AbstractCommand
*/
public function run(?string $connection = null): void
{
$tries = (int)$this->arg->getParameter('--tries', 3);
$tries = (int) $this->arg->getParameter('--tries', 3);
$default = $this->arg->getParameter('--queue', "default");
$memory = (int)$this->arg->getParameter('--memory', 126);
$timout = (int)$this->arg->getParameter('--timout', 60);
$sleep = (int)$this->arg->getParameter('--sleep', 60);
$memory = (int) $this->arg->getParameter('--memory', 126);
$timout = (int) $this->arg->getParameter('--timout', 3);
$sleep = (int) $this->arg->getParameter('--sleep', 60);

$queue = app("queue");

Expand Down
54 changes: 31 additions & 23 deletions src/Database/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,31 +877,39 @@ private function aggregate($aggregate, $column): mixed
*/
private function bind(PDOStatement $pdo_statement, array $bindings = []): void
{
foreach ($bindings as $key => $value) {
if (is_null($value) || strtolower((string) $value) === 'null') {
$key_binding = ':' . $key;
$pdo_statement->bindValue($key_binding, $value, PDO::PARAM_NULL);
unset($bindings[$key]);
// Detect if the SQL uses positional or named placeholders
$sql = $pdo_statement->queryString;
$uses_named = strpos($sql, ':') !== false;

if ($uses_named) {
// Named placeholders
foreach ($bindings as $key => $value) {
$param = PDO::PARAM_STR;
if (is_null($value) || strtolower((string) $value) === 'null') {
$param = PDO::PARAM_NULL;
} elseif (is_int($value)) {
$param = PDO::PARAM_INT;
} elseif (is_resource($value)) {
$param = PDO::PARAM_LOB;
}
$key_binding = is_string($key) ? ":$key" : $key + 1;
$pdo_statement->bindValue($key_binding, $value, $param);
}
}

foreach ($bindings as $key => $value) {
$param = PDO::PARAM_STR;

if (is_int($value)) {
$value = (int) $value;
$param = PDO::PARAM_INT;
} elseif (is_float($value)) {
$value = (float) $value;
} elseif (is_double($value)) {
$value = (float) $value;
} elseif (is_resource($value)) {
$param = PDO::PARAM_LOB;
} else {
// Positional placeholders
$i = 1;
foreach ($bindings as $value) {
$param = PDO::PARAM_STR;
if (is_null($value) || strtolower((string) $value) === 'null') {
$param = PDO::PARAM_NULL;
} elseif (is_int($value)) {
$param = PDO::PARAM_INT;
} elseif (is_resource($value)) {
$param = PDO::PARAM_LOB;
}
$pdo_statement->bindValue($i, $value, $param);
$i++;
}

// Bind by value with native pdo statement object
$key_binding = is_string($key) ? ":" . $key : $key + 1;
$pdo_statement->bindValue($key_binding, $value, $param);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Event/EventQueueTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function __construct(
private EventListener|EventShouldQueue $event,
private mixed $payload = null,
) {
parent::__construct();
}

/**
Expand Down
24 changes: 15 additions & 9 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ public function hostname(): string
return $_SERVER['HTTP_HOST'];
}

/**
* Get the domain of the server.
*
* @return string
*/
public function domain(): string
{
$part = explode(':', $this->hostname() ?? '');

return $part[0] ?? 'unknown';
}

/**
* Get uri send by client.
*
Expand Down Expand Up @@ -356,15 +368,13 @@ public function file(string $key): UploadedFile|Collection|null
$collect = [];

foreach ($files['name'] as $key => $name) {
$collect[] = new UploadedFile(
[
$collect[] = new UploadedFile([
'name' => $name,
'type' => $files['type'][$key],
'size' => $files['size'][$key],
'error' => $files['error'][$key],
'tmp_name' => $files['tmp_name'][$key],
]
);
]);
}

return new Collection($collect);
Expand Down Expand Up @@ -417,11 +427,7 @@ public function isAjax(): bool

$content_type = $this->getHeader("content-type");

if ($content_type && str_contains($content_type, "application/json")) {
return true;
}

return false;
return $content_type && str_contains($content_type, "application/json");
}

public function wantsJson(): bool
Expand Down
2 changes: 0 additions & 2 deletions src/Mail/MailQueueTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function __construct(
array $data,
Envelop $envelop
) {
parent::__construct();

$this->bags = [
"view" => $view,
"data" => $data,
Expand Down
2 changes: 0 additions & 2 deletions src/Notifier/NotifierQueueTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public function __construct(
Model $context,
Notifier $notifier,
) {
parent::__construct();

$this->bags = [
"notifier" => $notifier,
"context" => $context,
Expand Down
Loading
Loading