Skip to content

Commit 95da125

Browse files
committed
phalcon v5.8 adjustments
1 parent 1a66e9d commit 95da125

39 files changed

+999
-975
lines changed

.docker/nginx/templates/vhost.conf.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ server {
55
}
66

77
server {
8-
listen 443 ssl http2;
8+
listen 443 ssl;
9+
http2 on;
910
server_name ${VHOST_NAME};
1011
root /var/www/public;
1112
index index.php index.html index.htm;

.docker/php/Dockerfile

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
FROM php:8.1-fpm
1+
FROM php:8.2-fpm-bullseye
22

3-
RUN apt-get update && apt-get install -y --no-install-recommends \
4-
libzip-dev \
5-
zip \
6-
unzip \
7-
libssl-dev \
8-
git \
9-
libicu-dev \
10-
&& rm -rf /var/lib/apt/lists/*
3+
RUN apt-get update \
4+
&& apt-get install -y --no-install-recommends \
5+
apt-transport-https \
6+
git curl \
7+
libtool libicu-dev libonig-dev libpng-dev libxml2-dev libxslt1-dev libzip-dev libyaml-dev libssl-dev \
8+
zip unzip
9+
10+
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
11+
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-extensions yaml
1112

1213
ENV APCU_VERSION=5.1.22
14+
ENV PHALCON_VERSION=5.8.0
15+
1316
RUN set -xe \
14-
&& pecl install apcu-${APCU_VERSION} xdebug \
15-
&& docker-php-ext-enable xdebug apcu \
17+
&& pecl channel-update pecl.php.net \
18+
&& pecl install apcu-${APCU_VERSION} xdebug-3.3.1 phalcon-${PHALCON_VERSION} \
19+
&& docker-php-ext-enable xdebug apcu phalcon \
1620
&& docker-php-ext-install -j$(nproc) \
1721
zip \
1822
calendar \
@@ -21,22 +25,7 @@ RUN set -xe \
2125
opcache \
2226
&& pecl clear-cache
2327

24-
ENV PHALCON_VERSION=5.1.3 \
25-
PSR_VERSION=1.1.0
26-
RUN set -xe \
27-
&& curl -LO https://github.com/jbboehr/php-psr/archive/refs/tags/v${PSR_VERSION}.tar.gz \
28-
&& tar xzf ${PWD}/v${PSR_VERSION}.tar.gz \
29-
&& curl -LO https://github.com/phalcon/cphalcon/archive/v${PHALCON_VERSION}.tar.gz \
30-
&& tar xzf ${PWD}/v${PHALCON_VERSION}.tar.gz \
31-
&& docker-php-ext-install -j $(getconf _NPROCESSORS_ONLN) \
32-
${PWD}/php-psr-${PSR_VERSION} \
33-
${PWD}/cphalcon-${PHALCON_VERSION}/build/phalcon \
34-
&& rm -r \
35-
${PWD}/v${PSR_VERSION}.tar.gz \
36-
${PWD}/php-psr-${PSR_VERSION} \
37-
${PWD}/v${PHALCON_VERSION}.tar.gz \
38-
${PWD}/cphalcon-${PHALCON_VERSION} \
39-
&& php -m
28+
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
4029

4130
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
4231

.docker/php/cert/cacert.pem

Lines changed: 758 additions & 821 deletions
Large diffs are not rendered by default.

.nginx.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
APPLICATION_ENV=development
22
VHOST_NAME=phalcon5.test
3-
VHOST_FASTCGI_PASS=app-service
3+
VHOST_FASTCGI_PASS=p5-app
44
VHOST_FASTCGI_PORT=9000
55
NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx/sites-enabled

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://choosealicense.com/licenses/mit/)
1+
![GitHub License](https://img.shields.io/github/license/someson/phalcon5-docker)
22
[![Made in Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://supportukrainenow.org/)
33
[![Russian Warship Go Fuck Yourself](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/RussianWarship.svg)](https://stand-with-ukraine.pp.ua)
44

@@ -16,7 +16,7 @@ $ docker-compose up -d --build
1616
```
1717

1818
```sh
19-
$ docker-compose exec app-service composer install
19+
$ docker-compose exec p5-app composer install
2020
```
2121

2222
# CLI
@@ -32,7 +32,7 @@ $ docker-compose exec [service-name] php ./scripts/cli.php [handler] [action] [p
3232
```
3333
Example:
3434
```bash
35-
$ docker-compose exec app-service php ./scripts/cli.php main main -v -r -s
35+
$ docker-compose exec p5-app php ./scripts/cli.php main main -v -r -s
3636
```
3737
- ```-s``` = single instance allowed
3838
- ```-v``` = verbose info
@@ -51,12 +51,20 @@ where docker host for Windows or Linux:
5151
Result:
5252

5353
```bash
54-
$ docker-compose exec app-service php -dxdebug.mode=debug -dxdebug.client_host=host.docker.internal -dxdebug.client_port=9003 -dxdebug.start_with_request=yes ./scripts/cli.php main main -v -s -r
54+
$ docker-compose exec p5-app php -dxdebug.mode=debug -dxdebug.client_host=host.docker.internal -dxdebug.client_port=9003 -dxdebug.start_with_request=yes ./scripts/cli.php main main -v -s -r
5555
```
5656
with started listenings for PHP debug connections, certainly.
5757

5858
# Tests
5959

6060
```bash
61-
$ docker-compose exec app-service vendor/bin/codecept run
61+
$ docker-compose exec p5-app vendor/bin/codecept run
62+
```
63+
64+
# Troubleshooting
65+
66+
## Docker
67+
if `... did not complete successfully: exit code: 100`
68+
```bash
69+
$ docker image prune -f
6270
```

docker-compose.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
version: "3.8"
21
services:
32

43
# nginx
5-
nginx-service:
4+
p5-web:
65
build:
76
context: .docker/nginx
87
dockerfile: Dockerfile
9-
container_name: p5-webserver
8+
container_name: p5-web
109
ports:
1110
- "80:80"
1211
- "443:443"
@@ -23,13 +22,13 @@ services:
2322
env_file:
2423
- .nginx.env
2524
depends_on:
26-
- app-service
27-
- mariadb-service
25+
- p5-app
26+
- p5-db
2827
networks:
2928
- backend
3029

3130
# php
32-
app-service:
31+
p5-app:
3332
build:
3433
context: .docker
3534
dockerfile: php/Dockerfile
@@ -43,19 +42,22 @@ services:
4342
volumes:
4443
- ./src:/var/www
4544
- ~/composer:/root/.composer
45+
depends_on:
46+
- p5-db
4647
networks:
4748
- backend
4849

4950
# database (mariadb)
50-
mariadb-service:
51+
p5-db:
5152
image: mariadb:latest
52-
container_name: p5-mariadb
53+
container_name: p5-db
5354
ports:
5455
- "3307:3306"
5556
volumes:
5657
- ./.docker/mysql/cnf:/etc/mysql/conf.d
5758
- ./.docker/mysql/database:/var/lib/mysql
5859
- ./.docker/mysql/dump.sql:/docker-entrypoint-initdb.d/dump.sql
60+
command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
5961
restart: always
6062
env_file:
6163
- .sql.env

src/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ APP_DEBUG=1
66
CONFIG_ADAPTER=php
77
CONFIG_MAIN=Main.php
88

9-
MYSQL_HOST=mariadb-service
9+
MYSQL_HOST=p5-db
1010
MYSQL_USERNAME=phalcon5
1111
MYSQL_PASSWORD=secret
1212
MYSQL_DATABASE=phalcon5
1313
MYSQL_CHARSET=utf8
1414
MYSQL_PORT=3306
1515
MYSQL_LOG=
1616

17-
CLI_MYSQL_HOST=mariadb-service
17+
CLI_MYSQL_HOST=p5-db
1818
CLI_MYSQL_USERNAME=root
1919
CLI_MYSQL_PASSWORD=root
2020
CLI_MYSQL_DATABASE=phalcon5_cli

src/app/CliApplication.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public function getProviders(): array
4444

4545
public function handle(?array $arguments = null): void
4646
{
47-
/** @var Manager $eventaManager */
48-
$eventaManager = $this->getDI()->getShared('eventsManager');
47+
/** @var Manager $eventManager */
48+
$eventManager = $this->getDI()->getShared('eventsManager');
4949

5050
/** @var Config $config */
5151
$config = $this->getDI()->getShared('config');
5252

53-
$eventaManager->attach('console', new TaskListener($config->path('cli')));
54-
$this->setEventsManager($eventaManager);
53+
$eventManager->attach('console', new TaskListener($config->path('cli')));
54+
$this->setEventsManager($eventManager);
5555

5656
parent::handle($arguments);
5757
}

src/app/Micro.php

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
<?php
22

3+
use App\Shared\ExceptionDto;
4+
use App\Shared\Micro;
5+
use App\Shared\Simple;
6+
use App\Shared\Volt;
7+
use Phalcon\Config\Adapter\Php;
8+
use Phalcon\Config\Config;
9+
use Phalcon\Config\Exception as ConfigException;
10+
use Phalcon\Di\FactoryDefault;
11+
use Phalcon\Http\Message\ResponseStatusCodeInterface;
12+
313
try {
4-
$di = new \Phalcon\Di\FactoryDefault();
5-
$app = new \Phalcon\Mvc\Micro($di);
14+
$di = new FactoryDefault();
15+
$app = new Micro($di);
616

717
defined('CURRENT_APP') || define('CURRENT_APP', $_SERVER['SERVER_NAME'] ?? env('APP_DOMAIN'));
818

919
$file = sprintf('%s/Config/Main.php', APP_DIR);
1020
if (! file_exists($file)) {
11-
throw new \Phalcon\Config\Exception('Configuration not defined');
21+
throw new ConfigException('Configuration not defined');
1222
}
13-
14-
$defaultConfig = new \Phalcon\Config\Adapter\Php($file);
23+
$defaultConfig = new Php($file);
1524
$site = $defaultConfig->get('app', []);
16-
$config = new \Phalcon\Config\Config([
25+
$config = new Config([
1726
'debug' => $defaultConfig->get('debug', true),
1827
'viewsDir' => SHARED_DIR . '/Views/',
1928
'cacheDir' => CACHE_DIR . '/volt/',
2029
]);
2130

31+
$voltCacheDir = $config->get('cacheDir');
32+
if (! is_writable($voltCacheDir) && ! mkdir($voltCacheDir, 0777, true) && ! is_dir($voltCacheDir)) {
33+
throw new \RuntimeException(sprintf('Directory [%s] was not created', $voltCacheDir));
34+
}
35+
2236
$di->setShared('view', function() use ($config, $site) {
23-
$view = new Phalcon\Mvc\View\Simple();
37+
$view = new Simple();
2438
$view->setViewsDir($config->get('viewsDir'));
2539
$view->registerEngines([
2640
'.volt' => function($view) use ($config) {
27-
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $this);
41+
$volt = new Volt($view, $this);
2842
$volt->setOptions([
2943
'path' => $config->get('cacheDir'),
3044
'separator' => '_',
@@ -37,28 +51,43 @@
3751
return $view;
3852
});
3953

40-
$output = static function(\Phalcon\Mvc\Micro $app, $e) {
41-
$code = \Phalcon\Http\Message\ResponseStatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR;
42-
if ($e instanceof \DomainException) {
43-
$code = \Phalcon\Http\Message\ResponseStatusCodeInterface::STATUS_FORBIDDEN;
54+
/**
55+
* @param Micro $app
56+
* @param array<int, \Throwable> $exceptions
57+
* @return string
58+
*/
59+
$output = static function(Micro $app, array $exceptions) {
60+
$code = ResponseStatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR;
61+
if ($exceptions[0] instanceof \DomainException) {
62+
$code = ResponseStatusCodeInterface::STATUS_FORBIDDEN;
4463
}
4564
$message = $app->response->getReasonPhrase();
4665
$app->response->setStatusCode($code, $message)->sendHeaders();
4766

48-
/** @var \Phalcon\Mvc\View\Simple $view */
67+
$storage = new \SplObjectStorage();
68+
foreach ($exceptions as $exception) {
69+
$storage->attach(new ExceptionDto($exception::class, $exception->getMessage()));
70+
}
71+
/** @var Simple $view */
4972
$view = $app->view;
5073
return $view->render('error', [
5174
'errCode' => $code,
52-
'exceptionData' => new \Phalcon\Support\Collection([
53-
'class' => $e::class,
54-
'message' => $e->getMessage(),
55-
]),
75+
'exceptionData' => $storage,
5676
]);
5777
};
5878

59-
$app->error(function() use ($output, $app, $e) { echo $output($app, $e); });
60-
$app->notFound(function() use ($output, $app, $e) { echo $output($app, $e); });
61-
$app->handle($_SERVER['REQUEST_URI']);
79+
/** @var \Throwable $e from the catch block where this file is included */
80+
$app->error(function(\Throwable $appException) use ($output, $app, $e) {
81+
$exceptions = $appException->getMessage() === $e->getMessage() ? [$e] : [$appException, $e];
82+
echo $output($app, $exceptions);
83+
});
84+
$app->notFound(function() use ($output, $app, $e) { echo $output($app, [$e]); });
85+
86+
try {
87+
$app->handle($_SERVER['REQUEST_URI']);
88+
} catch(\Throwable) {
89+
// nothing to do
90+
}
6291

6392
} catch (\Throwable $e) {
6493
echo $e->getMessage(), PHP_EOL;

src/app/Modules/Cli/Listeners/ErrorListener.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
namespace App\Modules\Cli\Listeners;
44

5+
use App\Shared\ExceptionDto;
56
use Library\Cli\Dispatcher;
67
use Phalcon\Cli\Task;
78
use Phalcon\Cli\Dispatcher\Exception as DispatchException;
89
use Phalcon\Dispatcher\Exception as BaseException;
910
use Phalcon\Events\Event;
10-
use Phalcon\Support\Collection;
1111

1212
class ErrorListener
1313
{
14+
/**
15+
* @throws BaseException
16+
*/
1417
public function beforeException(Event $event, Dispatcher $dispatcher, \Throwable $exception): bool
1518
{
16-
$dispatcher->getUserOptions()->set('exceptionData', new Collection([
17-
'class' => \get_class($exception),
18-
'message' => $exception->getMessage(),
19-
]));
19+
$e = new \SplObjectStorage();
20+
$e->attach(new ExceptionDto(\get_class($exception), $exception->getMessage()));
21+
$dispatcher->getUserOptions()->set('exceptionData', $e);
2022

2123
if ($exception instanceof DispatchException) {
2224
$action = match ($exception->getCode()) {

0 commit comments

Comments
 (0)