Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Sulu skeleton to Symfony 6.4 #238

Merged
merged 6 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions .env
@@ -1,5 +1,5 @@
# In all environments, the following files are loaded if they exist,
# the later taking precedence over the former:
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
Expand All @@ -9,22 +9,29 @@
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=prod
APP_SECRET='s$cretf0rt3st'
APP_SECRET='$ecretf0rt3st'
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###

###> symfony/lock ###
# Choose one of the stores below
# postgresql+advisory://db_user:db_password@localhost/db_name
LOCK_DSN=semaphore
# flock using the filesystem and is so supported by most operation systems, for Unix based systems you may want to use semaphore
alexander-schranz marked this conversation as resolved.
Show resolved Hide resolved
LOCK_DSN=flock
Prokyonn marked this conversation as resolved.
Show resolved Hide resolved
###< symfony/lock ###

###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###

###> doctrine/phpcr-bundle ###
###< doctrine/phpcr-bundle ###

Expand All @@ -33,15 +40,12 @@ LOCK_DSN=semaphore
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8"
DATABASE_URL="mysql://root:ChangeMe@127.0.0.1:3306/su_myapp?serverVersion=8.0.27&charset=utf8mb4"
DATABASE_URL="mysql://root:ChangeMe@127.0.0.1:3306/su_myapp?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###

###> sulu/sulu ###
# Email address that will receive system notifications and might be used as universal fallback value by bundles
SULU_ADMIN_EMAIL=example@localhost
###< sulu/sulu ###

###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###
2 changes: 1 addition & 1 deletion .env.test
@@ -1,6 +1,6 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='s$cretf0rt3st'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
8 changes: 6 additions & 2 deletions .php-cs-fixer.dist.php
Expand Up @@ -4,7 +4,7 @@

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->ignoreVCSIgnored(true)
->exclude('var')
->notName('bundles.php');

return (new PhpCsFixer\Config())
Expand Down Expand Up @@ -40,9 +40,13 @@
'single_line_throw' => false,
'visibility_required' => ['elements' => ['property', 'method', 'const']],
'phpdoc_to_comment' => [
'ignored_tags' => ['todo', 'var'],
'ignored_tags' => ['todo', 'var', 'see', 'phpstan-ignore-next-line'],
],
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters']],
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'nullable_type_declaration_for_default_null_value' => true,
'fully_qualified_strict_types' => false,
'no_null_property_initialization' => false,
'nullable_type_declaration' => false,
])
->setFinder($finder);
6 changes: 5 additions & 1 deletion bin/console.php
Expand Up @@ -14,8 +14,12 @@
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!\is_dir(\dirname(__DIR__) . '/vendor')) {
throw new \LogicException('Dependencies are missing. Try running "composer install".');
}

if (!\is_file(\dirname(__DIR__) . '/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
throw new \LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once \dirname(__DIR__) . '/vendor/autoload_runtime.php';
Expand Down
12 changes: 9 additions & 3 deletions bin/phpunit
@@ -1,14 +1,20 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

if (!\ini_get('date.timezone')) {
\ini_set('date.timezone', 'UTC');
}

if (\is_file(\dirname(__DIR__) . '/vendor/phpunit/phpunit/phpunit')) {
\define('PHPUNIT_COMPOSER_INSTALL', \dirname(__DIR__) . '/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
if (\PHP_VERSION_ID >= 80000) {
require \dirname(__DIR__) . '/vendor/phpunit/phpunit/phpunit';
} else {
\define('PHPUNIT_COMPOSER_INSTALL', \dirname(__DIR__) . '/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
}
} else {
if (!\is_file(\dirname(__DIR__) . '/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
Expand Down
9 changes: 7 additions & 2 deletions docker-compose.override.yml → compose.override.yaml
Expand Up @@ -3,8 +3,13 @@ version: '3'
services:
###> symfony/mailer ###
mailer:
image: schickling/mailcatcher
ports: [1025, 1080]
image: axllent/mailpit
ports:
- "1025"
- "8025"
environment:
MP_SMTP_AUTH_ACCEPT_ANY: 1
MP_SMTP_AUTH_ALLOW_INSECURE: 1
###< symfony/mailer ###

###> doctrine/doctrine-bundle ###
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml → compose.yaml
Expand Up @@ -11,12 +11,12 @@ services:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-ChangeMe}
MYSQL_ROOT_HOST: '%'
volumes:
- db-data:/var/lib/mysql
- database-data:/var/lib/mysql
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
# - ./docker/db/data:/var/lib/mysql:rw
###< doctrine/doctrine-bundle ###

volumes:
###> doctrine/doctrine-bundle ###
db-data:
database-data:
###< doctrine/doctrine-bundle ###
43 changes: 23 additions & 20 deletions composer.json
Expand Up @@ -27,7 +27,7 @@
"chat": "https://sulu.io/services-and-support#chat"
},
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"dantleech/phpcr-migrations-bundle": "^1.3",
Expand All @@ -36,21 +36,21 @@
"friendsofsymfony/http-cache-bundle": "^2.17",
"handcraftedinthealps/zendsearch": "^2.1",
"jackalope/jackalope-doctrine-dbal": "^1.10",
"scheb/2fa-bundle": "^6.1",
"scheb/2fa-email": "^6.1",
"scheb/2fa-trusted-device": "^6.1",
"scheb/2fa-bundle": "^7.2",
"scheb/2fa-email": "^7.2",
"scheb/2fa-trusted-device": "^7.2",
"stof/doctrine-extensions-bundle": "^1.8",
"sulu/sulu": "~2.6.0@dev",
"symfony/config": "^6.3",
"symfony/dotenv": "^6.3",
"symfony/config": "^6.4",
"symfony/dotenv": "^6.4",
"symfony/flex": "^1.17 || ^2.0",
"symfony/framework-bundle": "^6.3",
"symfony/mailer": "^6.3",
"symfony/monolog-bridge": "^6.3",
"symfony/framework-bundle": "^6.4",
"symfony/mailer": "^6.4",
"symfony/monolog-bridge": "^6.4",
"symfony/monolog-bundle": "^3.4",
"symfony/runtime": "^6.3",
"symfony/security-bundle": "^6.3",
"symfony/twig-bundle": "^6.3"
"symfony/runtime": "^6.4",
"symfony/security-bundle": "^6.4",
"symfony/twig-bundle": "^6.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.41",
Expand All @@ -66,15 +66,18 @@
"phpunit/phpunit": "^9.6",
"rector/rector": "^1.0",
"sulu/sulu-rector": "^1.0",
"symfony/browser-kit": "^6.3",
"symfony/css-selector": "^6.3",
"symfony/debug-bundle": "^6.3",
"symfony/error-handler": "^6.3",
"symfony/phpunit-bridge": "^6.3",
"symfony/browser-kit": "^6.4",
"symfony/css-selector": "^6.4",
"symfony/debug-bundle": "^6.4",
"symfony/error-handler": "^6.4",
"symfony/phpunit-bridge": "^6.4",
"symfony/thanks": "^1.2",
"symfony/web-profiler-bundle": "^6.3",
"symfony/web-profiler-bundle": "^6.4",
"thecodingmachine/phpstan-strict-rules": "^1.0"
},
"conflict": {
"symfony/symfony": "*"
},
"autoload": {
"psr-4": {
"App\\": "src/"
Expand Down Expand Up @@ -113,7 +116,7 @@
],
"post-root-package-install": [
"@php -r \"file_put_contents('.env.local', 'APP_ENV=dev' . PHP_EOL);\"",
"@php -r \"file_put_contents('.env', str_replace('APP_SECRET=\\'s\\$cretf0rt3st\\'', 'APP_SECRET=' . bin2hex(random_bytes(16)), file_get_contents('.env')));\""
"@php -r \"file_put_contents('.env', str_replace('APP_SECRET=\\'\\$ecretf0rt3st\\'', 'APP_SECRET=' . bin2hex(random_bytes(16)), file_get_contents('.env')));\""
],
"post-create-project-cmd": [
"@php -r \"file_put_contents('.gitignore', str_replace(['composer.lock' . PHP_EOL, 'symfony.lock' . PHP_EOL, 'package-lock.json' . PHP_EOL, 'yarn.lock' . PHP_EOL, 'bun.lockb' . PHP_EOL, 'pnpm-lock.yaml' . PHP_EOL], '', file_get_contents('.gitignore')));\"",
Expand Down Expand Up @@ -187,7 +190,7 @@
"extra": {
"symfony": {
"allow-contrib": true,
"require": "6.3.*"
"require": "6.4.*"
}
}
}
11 changes: 10 additions & 1 deletion config/packages/doctrine.yaml
Expand Up @@ -5,17 +5,25 @@ doctrine:
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '8.0.27'

profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
validate_xml_mapping: false # required for gedmo/doctrine-extensions to be false
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
controller_resolver:
auto_mapping: false

when@test:
doctrine:
Expand All @@ -27,6 +35,7 @@ when@prod: &prod
doctrine:
orm:
auto_generate_proxy_classes: false
proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
Expand Down
5 changes: 3 additions & 2 deletions config/packages/framework.yaml
Expand Up @@ -2,15 +2,16 @@
framework:
secret: '%env(APP_SECRET)%'
#csrf_protection: true
#http_method_override: false
annotations: true # required for rest routing loader to be true
http_method_override: true # enable also in the index.php
handle_all_throwables: true

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
handler_id: null
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
name: SULUSESSID # This avoids conflicts with other applications running on the same domain

#esi: true
Expand Down
21 changes: 0 additions & 21 deletions config/packages/nyholm_psr7.yaml

This file was deleted.

22 changes: 2 additions & 20 deletions config/packages/security.yaml
@@ -1,19 +1,14 @@
security:
enable_authenticator_manager: true

access_decision_manager:
strategy: unanimous
allow_if_all_abstain: true

# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
password_hashers:
Sulu\Bundle\SecurityBundle\Entity\User: bcrypt

Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers:
sulu:
id: sulu_security.user_provider

# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
Expand Down Expand Up @@ -78,16 +73,6 @@ security:
# # https://symfony.com/doc/current/security/impersonating_user.html
# # switch_user: true

sulu_security:
checker:
enabled: true
password_policy:
enabled: true
# Sulu uses the simple password_policy pattern ".{8,}" by default
# You can change it to a more complex pattern with the following lines:
#pattern: '(?=^.{8,}$)(?=.*\d)(?=.*[^a-zA-Z0-9]+)(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$'
#info_translation_key: app.password_information

when@test:
security:
password_hashers:
Expand All @@ -96,7 +81,7 @@ when@test:
# are not important, waste resources and increase test times. The following
# reduces the work factor to the lowest possible values.
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
algorithm: bcrypt
algorithm: auto
cost: 4 # Lowest possible value for bcrypt
time_cost: 3 # Lowest possible value for argon
memory_cost: 10 # Lowest possible value for argon
Expand All @@ -112,6 +97,3 @@ when@test:
admin:
http_basic:
provider: sulu

sulu_test:
enable_test_user_provider: true
8 changes: 0 additions & 8 deletions config/packages/stof_doctrine_extensions.yaml
Expand Up @@ -2,11 +2,3 @@
# See the official DoctrineExtensions documentation for more details: https://github.com/doctrine-extensions/DoctrineExtensions/tree/main/doc
stof_doctrine_extensions:
default_locale: '%default_locale%'

when@prod: &prod
stof_doctrine_extensions:
# fix issue with gedmo/extensions 1.8.0 and stof/doctrine-extensions-bundle: 3.12.0
# @see https://github.com/stof/StofDoctrineExtensionsBundle/issues/457
metadata_cache_pool: doctrine.system_cache_pool

when@stage: *prod
9 changes: 9 additions & 0 deletions config/packages/sulu_security.yaml
@@ -0,0 +1,9 @@
sulu_security:
checker:
enabled: true
password_policy:
enabled: true
# Sulu uses the simple password_policy pattern ".{8,}" by default
# You can change it to a more complex pattern with the following lines:
#pattern: '(?=^.{8,}$)(?=.*\d)(?=.*[^a-zA-Z0-9]+)(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$'
#info_translation_key: app.password_information