Browse Source

php/spiral: cleanup (#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
Aleksei Gagarin 4 months ago
parent
commit
1c894c9d0d

+ 1 - 0
frameworks/PHP/spiral/.env

@@ -1,4 +1,5 @@
 # Debug mode disabled view cache and enabled higher verbosity.
 # Debug mode disabled view cache and enabled higher verbosity.
+APP_ENV=prod
 DEBUG=false
 DEBUG=false
 DB_DSN=mysql:host=tfb-database:3306;charset=utf8;dbname=hello_world;user=benchmarkdbuser;password=benchmarkdbpass
 DB_DSN=mysql:host=tfb-database:3306;charset=utf8;dbname=hello_world;user=benchmarkdbuser;password=benchmarkdbpass
 
 

+ 2 - 0
frameworks/PHP/spiral/.rr.yaml

@@ -4,6 +4,8 @@ rpc:
   listen: tcp://127.0.0.1:6001
   listen: tcp://127.0.0.1:6001
 
 
 server:
 server:
+  on_init:
+    command: "php app.php cycle"
   command: "php app.php"
   command: "php app.php"
   relay: pipes
   relay: pipes
 
 

+ 11 - 2
frameworks/PHP/spiral/app.php

@@ -3,16 +3,25 @@
 declare(strict_types=1);
 declare(strict_types=1);
 
 
 use App\App;
 use App\App;
+use Spiral\Core\Container;
+use Spiral\Core\Options;
 
 
 \mb_internal_encoding('UTF-8');
 \mb_internal_encoding('UTF-8');
-\error_reporting(E_ALL | E_STRICT ^ E_DEPRECATED);
+\error_reporting(E_ALL ^ E_DEPRECATED);
 \ini_set('display_errors', 'stderr');
 \ini_set('display_errors', 'stderr');
 
 
 // Register Composer's auto loader.
 // Register Composer's auto loader.
 require __DIR__ . '/vendor/autoload.php';
 require __DIR__ . '/vendor/autoload.php';
 
 
 // Initialize shared container, bindings, directories and etc.
 // Initialize shared container, bindings, directories and etc.
-$app = App::create(directories: ['root' => __DIR__])->run();
+$options = new Options();
+$options->validateArguments = false;
+$options->allowSingletonsRebinding = true;
+$container = new Container(options: $options);
+$app = App::create(
+    directories: ['root' => __DIR__],
+    container: $container,
+)->run();
 
 
 if ($app === null) {
 if ($app === null) {
     exit(255);
     exit(255);

+ 52 - 0
frameworks/PHP/spiral/app/config/cycle.php

@@ -0,0 +1,52 @@
+<?php
+
+declare(strict_types=1);
+
+use Cycle\ORM\SchemaInterface;
+
+/** @see \Spiral\Cycle\Config\CycleConfig */
+return [
+    'schema' => [
+        /**
+         * true (Default) - Schema will be stored in a cache after compilation.
+         * It won't be changed after entity modification. Use `php app.php cycle` to update schema.
+         *
+         * false - Schema won't be stored in a cache after compilation.
+         * It will be automatically changed after entity modification. (Development mode)
+         */
+        'cache' => true,
+
+        /**
+         * The CycleORM provides the ability to manage default settings for
+         * every schema with not defined segments
+         */
+        'defaults' => [
+            SchemaInterface::MAPPER => \Cycle\ORM\Mapper\Mapper::class,
+            SchemaInterface::REPOSITORY => \Cycle\ORM\Select\Repository::class,
+            SchemaInterface::SCOPE => null,
+            SchemaInterface::TYPECAST_HANDLER => [
+                \Cycle\ORM\Parser\Typecast::class
+            ],
+        ],
+
+        'collections' => [
+            'default' => 'array',
+            'factories' => [
+                'array' => new \Cycle\ORM\Collection\ArrayCollectionFactory(),
+                // 'doctrine' => new \Cycle\ORM\Collection\DoctrineCollectionFactory(),
+                // 'illuminate' => new \Cycle\ORM\Collection\IlluminateCollectionFactory(),
+            ],
+        ],
+
+        /**
+         * Schema generators (Optional)
+         * null (default) - Will be used schema generators defined in bootloaders
+         */
+        'generators' => null,
+    ],
+
+    /**
+     * Prepare all internal ORM services (mappers, repositories, typecasters...)
+     */
+    'warmup' => \env('RR_MODE') !== null,
+];

+ 0 - 9
frameworks/PHP/spiral/app/src/App.php

@@ -31,14 +31,7 @@ class App extends Kernel
      */
      */
     protected const LOAD = [
     protected const LOAD = [
         // Core Services
         // Core Services
-        Bootloader\DebugBootloader::class,
         Bootloader\SnapshotsBootloader::class,
         Bootloader\SnapshotsBootloader::class,
-
-        // Security and validation
-        Bootloader\Security\EncrypterBootloader::class,
-        Bootloader\Security\FiltersBootloader::class,
-        Bootloader\Security\GuardBootloader::class,
-
         RoadRunnerBridge\HttpBootloader::class,
         RoadRunnerBridge\HttpBootloader::class,
 
 
         // HTTP extensions
         // HTTP extensions
@@ -59,8 +52,6 @@ class App extends Kernel
         // Template engine
         // Template engine
         Stempler\StemplerBootloader::class,
         Stempler\StemplerBootloader::class,
 
 
-        Scaffolder\ScaffolderBootloader::class,
-
         // Framework commands
         // Framework commands
         Bootloader\CommandBootloader::class,
         Bootloader\CommandBootloader::class,
         RoadRunnerBridge\CommandBootloader::class,
         RoadRunnerBridge\CommandBootloader::class,

+ 0 - 8
frameworks/PHP/spiral/composer.json

@@ -16,14 +16,6 @@
     "spiral/roadrunner-bridge": "^3.0",
     "spiral/roadrunner-bridge": "^3.0",
     "spiral/roadrunner-cli": "^2.4"
     "spiral/roadrunner-cli": "^2.4"
   },
   },
-  "scripts": {
-    "post-create-project-cmd": [
-      "php -r \"copy('.env.sample', '.env');\"",
-      "php app.php encrypt:key -m .env",
-      "php app.php configure -vv",
-      "rr get-binary --quiet"
-    ]
-  },
   "autoload": {
   "autoload": {
     "psr-4": {
     "psr-4": {
       "App\\": "app/src/"
       "App\\": "app/src/"

+ 3 - 3
frameworks/PHP/spiral/spiral.dockerfile

@@ -1,4 +1,4 @@
-FROM php:8.3-cli
+FROM php:8.4-cli
 
 
 RUN apt-get update -yqq > /dev/null && apt-get install -yqq git unzip > /dev/null
 RUN apt-get update -yqq > /dev/null && apt-get install -yqq git unzip > /dev/null
 COPY --from=composer/composer:latest-bin --link /composer /usr/local/bin/composer
 COPY --from=composer/composer:latest-bin --link /composer /usr/local/bin/composer
@@ -9,7 +9,7 @@ RUN docker-php-ext-install \
     sockets > /dev/null
     sockets > /dev/null
 
 
 # RoadRunner >= 2024.x.x requires protobuf extensions to be installed
 # RoadRunner >= 2024.x.x requires protobuf extensions to be installed
-ARG PROTOBUF_VERSION="4.26.1"
+ARG PROTOBUF_VERSION="4.30.1"
 RUN pecl channel-update pecl.php.net
 RUN pecl channel-update pecl.php.net
 RUN MAKEFLAGS="-j $(nproc)" pecl install protobuf-${PROTOBUF_VERSION} > /dev/null
 RUN MAKEFLAGS="-j $(nproc)" pecl install protobuf-${PROTOBUF_VERSION} > /dev/null
 
 
@@ -22,7 +22,7 @@ RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --q
 
 
 # pre-configure
 # pre-configure
 RUN ./vendor/bin/rr get-binary > /dev/null 2>&1
 RUN ./vendor/bin/rr get-binary > /dev/null 2>&1
-RUN php app.php configure > /dev/null 2>&1
+RUN php app.php configure
 
 
 EXPOSE 8080
 EXPOSE 8080