Symfony Cheat Sheet
Symfony Cheat Sheet
doctrine:query:sql <sql> Run a SQL query make:functional-test Create a new functional test class
Debug commands doctrine:query:dql <dql> Run a DQL query make:message Create a new message & handler
Command Description doctrine:fixtures:load Load data fixtures to the DB make:migration Create a new migration class
debug:autowiring List all autowireable services make:registration-form Create a new registration form
debug:config <bundle> Dump bundle configuration Doctrine Migrations commands make:reset-password Create password reset
debug:container List all public services Command Description make:security:form-login Generate a login form
debug:container <service> Get information about a service Generate an empty migration make:serializer:encoder Create a new serializer encoder
doc:migrations:generate
class
debug:container --env-vars Display container env vars make:serializer:normalizer Create a new serializer normalizer
Generate a migration to sync DB
debug:container --tags List tagged public services doc:migrations:diff make:stimulus-controller Create a new Stimulus controller
scheme with mapping files
debug:container --tag=<t> List services with a specific tag make:subscriber Create a new event subscriber
doc:migrations:migrate Migrate DB to the latest version
debug:dotenv Display parsed dotenv values make:twig-component Create a new Twig component
doc:migrations:migrate Migrate DB to the (first/
debug:dotenv <search> Display matching dotenv values <alias> latest/prev/current/next) version make:twig-extension Create a new Twig extension
debug:event-dispatcher List all registered event listeners doc:migrations:migrate make:unit-test Create a new unit test class
Migrate DB to a specific version
<FQCN>
Display detailed information about make:user Create a new user class
debug:firewall <name>
a firewall doc:migrations:up-to-date Check if the schema is up-to-date
make:validator Create a new validator
debug:form Display form type information
make:voter Create a new security voter
debug:messenger List dispatchable messages Other commands
debug:router List all registered routes Command Description
Bash console autocompletion
debug:router <name> Get information about a route assets:install Install bundle assets
bin/console completion bash | sudo tee
debug:translation <loc> Display messages for locale cache:clear Clear the cache
/etc/bash_completion.d/console
router:match <path> Show matching route(s) for a path cache:warmup Warm up an empty cache
© Nic Wortel, Software Consultant & Trainer - Last updated on August 23, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Form types Date and time form types String validation constraints
Type Description Constraint Description
See https://symfony.com/doc/current/reference/forms/types.html.
DateType A date field String is between <min> and
Length(<min>, <max>)
Type Description <max> characters long
DateIntervalType A date interval field
TextType A text (single line text) field Email String is a valid email address
DateTimeType A date and time field
TextareaType A multi-line text field Url String is a valid URL
TimeType A time field
EmailType An email field Hostname String is a valid hostname
BirthdayType A date field for birthdays
IntegerType A number field for integers Ip String is a valid IP address
WeekType Select a year and week
A money field, with a specifiable UserPassword String is the user's password
MoneyType
currency String is not found in any data
Validation constraints NotCompromisedPassword
breaches
NumberType A number field
PasswordType A password field See https://symfony.com/doc/current/reference/constraints.html. PasswordStrength Password has a enough entropy
PercentType A number field for percentages Usage: String does not contain spoofing
NoSuspiciousCharacters
characters
SearchType A search field
use Symfony\Component\Validator\Constraints as Uuid String is a valid UUID
UrlType A URL field Assert;
CssColor String is a valid CSS color
RangeType A range input field (slider)
class User
TelType A tel (phone number) input field {
#[Assert\NotBlank]
Financial / Number constraints
CheckboxType A single checkbox field Constraint Description
private string $name;
FileType A file upload field } Bic Valid Business Identifier Code
RadioType A radio button field CardScheme Valid credit card number
HiddenType A hidden field
Basic validation constraints
Currency Valid 3-letter ISO 4217 currency
Constraint Description
Luhn Passes the Luhn algorithm
Choice form types Value is not null, not an empty
NotBlank
string, not 0, etc. Iban Valid IBAN
Type Description
NotNull Value is not strictly equal to null Isbn Valid ISBN
Field for selecting one or more
ChoiceType options (rendered as dropdown, Type(<type>) Value is of a specific type
radio buttons, or checkboxes) [Not]EqualTo (Not) equal to another value Twig functions
EnumType Choose from PHP enum cases [Not]IdenticalTo (Not) identical to another value Function Description
EntityType Choose from a Doctrine entity LessThan[OrEqual] Less than (or equal to) asset(path) Get the public path of an asset
CountryType Choose a country GreaterThan[OrEqual] Greater than (or equal to) is_granted(role,
Check if access is allowed
[object])
LanguageType Choose a language Positive[OrZero] Positive (or zero)
path(route, [params]) Return relative URL for a route
LocaleType Choose a locale Negative[OrZero] Negative (or zero)
url(route, [params]) Return absolute URL for a route
TimezoneType Choose a timezone Between a minimum and
Range absolute_url(path) Return absolute URL for a path
CurrencyType Choose a currency maximum value
© Nic Wortel, Software Consultant & Trainer - Last updated on August 23, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Form related Twig functions Symfony CLI installation Local Proxy
Function Description Command Description
wget https://get.symfony.com/cli/installer -O - |
form(form, options) Render a complete form bash symfony proxy:start Run a local proxy server
form_start(form) Render the opening <form> tag symfony
Attach a domain to the local
form_end(form) Render the closing </form> tag
Symfony CLI basic commands proxy:domain:attach
proxy
<domain>
Command Description
form_row(form) Render a form row symfony
symfony Check requirements for running proxy:domain:detach Detach domains from the proxy
form_widget(form) Render a form widget check:requirements Symfony <domain>
symfony version Display the Symfony CLI version symfony proxy:status Get the status of the proxy
Symfony Attributes symfony help Display all available commands symfony proxy:stop Stop the local proxy server
Attribute Description
Display help for a specific
symfony help <command>
Register class as a console command
#[AsCommand]
command PHP version switching & wrappers
#[AsController] Register class as a controller Command Description
Creating a new Symfony project
Register class as a message symfony local:php:list List locally available PHP versions
#[AsMessageHandler] Command Description
handler Refresh the list of locally available
symfony new <directory> Create a new Symfony project symfony local:php:refresh
#[AsEventListener] Register class as an event listener PHP versions
Specify the skeleton version echo 8.2 > .php-version Set project PHP version to 8.2
#[Route] Define a route for a method symfony new --version=<v>
(lts/stable/next/previous)
#[IsGranted] Require a role to access symfony php -v Display the selected PHP version
symfony new --webapp Create a new Symfony web
<directory> application Run a command with the selected
symfony php <command>
PHP version
Symfony Flex commands symfony new --demo <dir>
Install the Symfony demo
application symfony composer Run a Composer command with
Command Description <command> the selected PHP version
composer symfony:dump-env Compile .env files to Run a Symfony console command
<env> .env.local.php Symfony Local Web Server symfony console <command>
with the selected PHP version
composer symfony:recipes List available recipes Command Description
symfony:recipes:install (Re)install recipes for packages symfony server:start Run a local web server
symfony:recipes:update Update installed recipes symfony server:start -d Run the server in the background
symfony server:status Display local web server status
Open the local project in a
symfony open:local
browser
symfony server:log Display local web server logs
symfony server:stop Stop the local web server
Create a local Certificate
symfony server:ca:install
Authority for serving HTTPS
© Nic Wortel, Software Consultant & Trainer - Last updated on August 23, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets