Skip to content

Commit 1c894c9

Browse files
authored
php/spiral: cleanup (TechEmpower#9682)
* Spiral: Add cycle orm config * Disable unused modules * Update PHP to 8.4 * Build ORM schema before workers start * Show `app configure` log * Use ORM warmup in roadrunner only
1 parent 2875eaf commit 1c894c9

File tree

7 files changed

+69
-22
lines changed

7 files changed

+69
-22
lines changed

frameworks/PHP/spiral/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Debug mode disabled view cache and enabled higher verbosity.
2+
APP_ENV=prod
23
DEBUG=false
34
DB_DSN=mysql:host=tfb-database:3306;charset=utf8;dbname=hello_world;user=benchmarkdbuser;password=benchmarkdbpass
45

frameworks/PHP/spiral/.rr.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ rpc:
44
listen: tcp://127.0.0.1:6001
55

66
server:
7+
on_init:
8+
command: "php app.php cycle"
79
command: "php app.php"
810
relay: pipes
911

frameworks/PHP/spiral/app.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
declare(strict_types=1);
44

55
use App\App;
6+
use Spiral\Core\Container;
7+
use Spiral\Core\Options;
68

79
\mb_internal_encoding('UTF-8');
8-
\error_reporting(E_ALL | E_STRICT ^ E_DEPRECATED);
10+
\error_reporting(E_ALL ^ E_DEPRECATED);
911
\ini_set('display_errors', 'stderr');
1012

1113
// Register Composer's auto loader.
1214
require __DIR__ . '/vendor/autoload.php';
1315

1416
// Initialize shared container, bindings, directories and etc.
15-
$app = App::create(directories: ['root' => __DIR__])->run();
17+
$options = new Options();
18+
$options->validateArguments = false;
19+
$options->allowSingletonsRebinding = true;
20+
$container = new Container(options: $options);
21+
$app = App::create(
22+
directories: ['root' => __DIR__],
23+
container: $container,
24+
)->run();
1625

1726
if ($app === null) {
1827
exit(255);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Cycle\ORM\SchemaInterface;
6+
7+
/** @see \Spiral\Cycle\Config\CycleConfig */
8+
return [
9+
'schema' => [
10+
/**
11+
* true (Default) - Schema will be stored in a cache after compilation.
12+
* It won't be changed after entity modification. Use `php app.php cycle` to update schema.
13+
*
14+
* false - Schema won't be stored in a cache after compilation.
15+
* It will be automatically changed after entity modification. (Development mode)
16+
*/
17+
'cache' => true,
18+
19+
/**
20+
* The CycleORM provides the ability to manage default settings for
21+
* every schema with not defined segments
22+
*/
23+
'defaults' => [
24+
SchemaInterface::MAPPER => \Cycle\ORM\Mapper\Mapper::class,
25+
SchemaInterface::REPOSITORY => \Cycle\ORM\Select\Repository::class,
26+
SchemaInterface::SCOPE => null,
27+
SchemaInterface::TYPECAST_HANDLER => [
28+
\Cycle\ORM\Parser\Typecast::class
29+
],
30+
],
31+
32+
'collections' => [
33+
'default' => 'array',
34+
'factories' => [
35+
'array' => new \Cycle\ORM\Collection\ArrayCollectionFactory(),
36+
// 'doctrine' => new \Cycle\ORM\Collection\DoctrineCollectionFactory(),
37+
// 'illuminate' => new \Cycle\ORM\Collection\IlluminateCollectionFactory(),
38+
],
39+
],
40+
41+
/**
42+
* Schema generators (Optional)
43+
* null (default) - Will be used schema generators defined in bootloaders
44+
*/
45+
'generators' => null,
46+
],
47+
48+
/**
49+
* Prepare all internal ORM services (mappers, repositories, typecasters...)
50+
*/
51+
'warmup' => \env('RR_MODE') !== null,
52+
];

frameworks/PHP/spiral/app/src/App.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ class App extends Kernel
3131
*/
3232
protected const LOAD = [
3333
// Core Services
34-
Bootloader\DebugBootloader::class,
3534
Bootloader\SnapshotsBootloader::class,
36-
37-
// Security and validation
38-
Bootloader\Security\EncrypterBootloader::class,
39-
Bootloader\Security\FiltersBootloader::class,
40-
Bootloader\Security\GuardBootloader::class,
41-
4235
RoadRunnerBridge\HttpBootloader::class,
4336

4437
// HTTP extensions
@@ -59,8 +52,6 @@ class App extends Kernel
5952
// Template engine
6053
Stempler\StemplerBootloader::class,
6154

62-
Scaffolder\ScaffolderBootloader::class,
63-
6455
// Framework commands
6556
Bootloader\CommandBootloader::class,
6657
RoadRunnerBridge\CommandBootloader::class,

frameworks/PHP/spiral/composer.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616
"spiral/roadrunner-bridge": "^3.0",
1717
"spiral/roadrunner-cli": "^2.4"
1818
},
19-
"scripts": {
20-
"post-create-project-cmd": [
21-
"php -r \"copy('.env.sample', '.env');\"",
22-
"php app.php encrypt:key -m .env",
23-
"php app.php configure -vv",
24-
"rr get-binary --quiet"
25-
]
26-
},
2719
"autoload": {
2820
"psr-4": {
2921
"App\\": "app/src/"

frameworks/PHP/spiral/spiral.dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.3-cli
1+
FROM php:8.4-cli
22

33
RUN apt-get update -yqq > /dev/null && apt-get install -yqq git unzip > /dev/null
44
COPY --from=composer/composer:latest-bin --link /composer /usr/local/bin/composer
@@ -9,7 +9,7 @@ RUN docker-php-ext-install \
99
sockets > /dev/null
1010

1111
# RoadRunner >= 2024.x.x requires protobuf extensions to be installed
12-
ARG PROTOBUF_VERSION="4.26.1"
12+
ARG PROTOBUF_VERSION="4.30.1"
1313
RUN pecl channel-update pecl.php.net
1414
RUN MAKEFLAGS="-j $(nproc)" pecl install protobuf-${PROTOBUF_VERSION} > /dev/null
1515

@@ -22,7 +22,7 @@ RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --q
2222

2323
# pre-configure
2424
RUN ./vendor/bin/rr get-binary > /dev/null 2>&1
25-
RUN php app.php configure > /dev/null 2>&1
25+
RUN php app.php configure
2626

2727
EXPOSE 8080
2828

0 commit comments

Comments
 (0)