3 minute read
Best practices for setting up new projects.
You can skip to the bottom to get all the commands directly..
Let’s start with building a new minimalistic symfony project, using
composer create-project symfony/skeleton authentication
The advantage of using the skeleton setup is that you, as a developer, can have full control off what components you do and do not use. Your knowledge of bundles will also increase as you need to add more bundles.
If you run into trouble, you will need composer require symfony/var-dumper —dev.
Doctrine all the way, so composer require symfony/orm-pack. As annotations are a performance hog, configure yaml for doctrine entities and store the yml config files in config/doctrine:
config/packages/doctrine.yml doctrine: ... orm: ... mappings: App: is_bundle: false type: yml dir: '%kernel.project_dir%/config/doctrine' prefix: 'App\Entity' alias: App
And no doctrine without DoctrineMigrations
Serialization is used to convert entities from one format to another and has proven its necessity in almost every one of our projects. Install serializer by composer require symfony/serializer, add serializer config in framework.yml and create config/serialization to store yml config files:
config/packages/framework.yml serializer: enabled: true mapping: paths: ['%kernel.project_dir%/config/serialization/']
For every one of your entities, configure how it should be serialialized. E.g. for a user entity:
config/serialization/User.yml App\Entity\User: attributes: id: groups: [ 'public' ] identifier: groups: [ 'public' ] roles: groups: [ 'public' ]
Oh.. and don’t forget to setup some PHPUnit Tests
mkdir project_name && cd project_name composer create-project symfony/skeleton . composer require symfony/orm-pack composer require symfony/var-dumper --dev composer require symfony/serializer