You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting from the Symfony 3.x branch, the number of minor versions is limited to five per branch
(X.0, X.1, X.2, X.3 and X.4).
The last minor version of a branch (e.g. 4.4, 5.4) is considered a long-term support version
and the other ones are considered standard versions:
Backward compatibility promise
Deprecations best practices
trigger_deprecation
@ deprecated
Framework overloading
Release management and roadmap schedule
Framework interoperability and PSRs
Naming conventions
Controllers
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController
Naming conventions
The base AbstractController class
The request
The response
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
The cookies
$request->cookies
The session
use Symfony\Component\HttpFoundation\Session\SessionInterface;
$builder->get('tags')
->addModelTransformer(newCallbackTransformer(
function ($tagsAsArray) {
// transform the array to a stringreturn implode(', ', $tagsAsArray);
},
function ($tagsAsString) {
// transform the string back to an arrayreturn explode(', ', $tagsAsString);
}
))
Form events
useSymfony\Component\Form\FormEvent;
useSymfony\Component\Form\FormEvents;
$listener = function (FormEvent$event) {
// ...
};
$form = $formFactory->createBuilder()
// ... add form fields
->addEventListener(FormEvents::PRE_SUBMIT, $listener);
During FormEvents::PRE_SET_DATA, Form::setData() is locked and will throw an exception if used.
If you wish to modify data, you should use FormEvent::setData() instead.
Form type extensions
useSymfony\Component\Form\AbstractTypeExtension;
Data Validation
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/*
* Uses a __toString method on the $errors variable which is a
* ConstraintViolationList object. This gives us a nice string
* for debugging.
*/
$errorsString = (string) $errors;
/**
* @Assert\Choice(
* choices = { "fiction", "non-fiction" },
* message = "Choose a valid genre."
* )
*/
private $genre;
/**
* @Assert\NotBlank(message="author.name.not_blank")
*/
public $name;
...
# translations/validators.en.yaml
author.name.not_blank: Please enter an author name.
PHP object validation
Built-in validation constraints
Validation scopes
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* @Assert\GroupSequence({"User", "Strict"})
*/
class
Custom callback validators
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
// ...
}
//or to static validate
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\Callback({"Acme\Validator", "validate"})
*/
class Author
{
}
App\Handler\Two:
tags: ['app.handler']
App\HandlerCollection:
# inject all services tagged with app.handler as first argument
arguments:
- !tagged_iterator app.handler
public function __construct(iterable $handlers)
priotiry
App\Handler\One:
tags:
- { name: 'app.handler', priority: 20 }
# or -----
public static function getDefaultPriority(): int
{
return 3;
}
App\HandlerCollection:
# inject all services tagged with app.handler as first argument
arguments:
- !tagged_iterator { tag: app.handler, default_priority_method: getPriority }
key
services:
App\Handler\One:
tags:
- { name: 'app.handler', key: 'handler_one' }
App\Handler\Two:
tags:
- { name: 'app.handler', key: 'handler_two' }
App\HandlerCollection:
arguments: [!tagged_iterator { tag: 'app.handler', index_by: 'key' }]
namespace App\Handler;
class HandlerCollection
{
public function __construct(iterable $handlers)
{
$handlers = iterator_to_array($handlers);
$handlerTwo = $handlers['handler_two'];
}
}
# or ----
namespace App\Handler;
class One
{
// ...
public static function getDefaultIndexName(): string
{
return 'handler_one';
}
}
App\HandlerCollection:
# use getIndex() instead of getDefaultIndexName()
arguments: [!tagged_iterator { tag: 'app.handler', default_index_method: 'getIndex' }]
Semantic configuration
Factories
Compiler passes
Services autowiring
Security
Authentication
Authorization
Configuration
Providers
security.yaml
security:
providers:
# the name of your user provider can be anything
your_custom_user_provider:
id: App\Security\UserProvider
Cache types (browser, proxies and reverse-proxies)
Expiration (Expires, Cache-Control)
Validation (ETag, Last-Modified)
Client side caching
Server side caching
Edge Side Includes
Console
useSymfony\Component\Console\Command\Command
use Symfony\Component\Console\Input\InputInterface;
useSymfony\Component\Console\Output\OutputInterface;
Built-in commands
Custom commands
Configuration
Options and arguments
useSymfony\Component\Console\Input\InputArgument;
useSymfony\Component\Console\Command\Command;
useSymfony\Component\Console\Input\InputInterface;
useSymfony\Component\Console\Output\OutputInterface;
protectedfunctionconfigure()
{
$this
->setDescription('Creates a new user.')
->setHelp('This command allows you to create a user...')
->addArgument('password', $this->requirePassword ? InputArgument::REQUIRED : InputArgument::OPTIONAL, 'User password')
;
}
useSymfony\Component\Console\Input\InputOption;
$this
->addOption(
'iterations',
null,
InputOption::VALUE_REQUIRED,
'How many times should the message be printed?',
1
)
;
Input and Output objects
Built-in helpers
Formatter Helper
Process Helper
Progress Bar
Question Helper
Table
Debug Formatter Helper
Console events
Verbosity levels
# increase verbosity of message
php bin/console some-command -v
# also informative messae
php bin/console some-command -vv
# all messages
php bin/console some-command -vvv
Data Validation
Dependency Injection
services.yaml
priotiry
key
Security
security.yaml
example
HTTP Caching
PSR-6
Console
The text was updated successfully, but these errors were encountered: