elkuku / symfony-utils
Various Symfony Utilities
Requires
- php: >=8.1
Requires (Dev)
- doctrine/doctrine-bundle: ^3.0
- doctrine/orm: ^3.1
- php-cs-fixer/shim: ^3.88
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^13.0
- symfony/browser-kit: ^8.0
- symfony/console: ^8.0
- symfony/framework-bundle: ^8.0
- symfony/security-core: ^8.0
Suggests
- doctrine/doctrine-bundle: For UserAdminBaseCommand
- doctrine/orm: For UserAdminBaseCommand
- symfony/browser-kit: For ControllerBaseTest
- symfony/console: For UserAdminBaseCommand
- symfony/framework-bundle: For ControllerBaseTest
- symfony/security-core: For UserAdminBaseCommand
Provides
None
Conflicts
- doctrine/doctrine-bundle: <2.5 || >=4.0
- doctrine/orm: <2.11 || >=3.0 <3.1 || >=4.0
- symfony/browser-kit: <6.0 || >=9.0
- symfony/console: <6.0 || >=9.0
- symfony/framework-bundle: <6.0 || >=9.0
- symfony/security-core: <6.0 || >=9.0
Replaces
None
README
- Dev environment scripts for
bin/, installed by a Flex recipe (see below). UserAdminBaseCommand: an interactiveuser-adminconsole command. Extend it and implementgetRoles()andsetRole(). If your user entity has more required fields, overridefillNewUser()to ask for them when a user is created. Needssymfony/console,symfony/security-core,doctrine/ormanddoctrine/doctrine-bundle.ControllerBaseTest: a smoke test that requests every route of your controllers and checks the status codes. Needssymfony/framework-bundleandsymfony/browser-kit.
The package itself only requires PHP. The packages the two classes need are suggested, not required, so a project that only wants the scripts doesn't get Doctrine installed.
Dev environment scripts
The package ships shell scripts for setting up and running a Symfony project locally.
A Symfony Flex recipe copies them into the project's bin/ folder:
| Script | What it does |
|---|---|
bin/install |
composer install, starts the Docker Compose services, runs the Doctrine migrations, loads the fixtures on a fresh database, starts the Symfony server |
bin/start |
Starts the Docker Compose services and the Symfony server |
bin/stop |
Stops the Symfony server and the Docker Compose services |
bin/deploy |
Runs on the server: composer install --no-dev, dump-env prod, compiles the assets, runs the Doctrine migrations. Set PHP_BIN/COMPOSER_BIN to use other binaries, DEPLOY_GIT_DIR to write sha.txt |
bin/functions.sh |
Helpers used by the scripts above |
Each step is skipped when the project doesn't use it (no compose.yaml, no Doctrine migrations, no fixtures).
Before migrating, bin/install waits up to 30 seconds for the database, so the Docker database service doesn't need a healthcheck.
Fixtures are only loaded when no migration had been run before, because loading them purges the database.
Server-specific deploy settings
bin/deploy uses php and composer from the PATH. If the server needs other binaries (e.g. Plesk with several PHP versions), put them into bin/deploy.env in your project. The recipe never touches that file:
PHP_BIN=/opt/plesk/php/8.5/bin/php COMPOSER_BIN=/usr/lib/plesk-9.0/composer.phar
A deploy without a .git folder, e.g. by the Plesk Git extension, can't tell which commit it runs.
Set DEPLOY_GIT_DIR to the Git repository the code comes from, and bin/deploy writes the commit of its HEAD to sha.txt in the project folder.
For the Plesk Git extension, this is the bare repository of the site:
DEPLOY_GIT_DIR="$HOME/git/<project>.git"
If the repository can't be read, the deploy shows a warning and goes on. Add sha.txt to the project's .gitignore.
Requirements
The local scripts need the Symfony CLI, and Docker with Compose v2 (docker compose) if the project has a Compose file. bin/deploy only needs PHP and Composer, and Git for DEPLOY_GIT_DIR.
Installing the scripts
The recipe lives in a custom Flex endpoint, elkuku/recipes. Add it to your project's composer.json:
"extra": { "symfony": { "endpoint": [ "https://api.github.com/repos/elkuku/recipes/contents/index.json?ref=flex/main", "flex://defaults" ] } }
Then install the package, or, if it is already installed, install its recipe:
composer require elkuku/symfony-utils
# or
composer recipes:install elkuku/symfony-utils
Flex asks before overwriting scripts that already exist in bin/; add --force to replace them.
Development
composer install composer check # PHPStan, PHP CS Fixer, PHPUnit shellcheck -x -P SCRIPTDIR resources/bin/*
CI runs these on every push and pull request, and lints src/ with PHP 8.1, the lowest supported version.