Symfony Core Flashcards
Command to get the list of all services that we can access?
project_dir$: ./bin/console debug:autowiring
How to install a bundle?
composer require author/nameofBundle
Configuring Symfony
Symfony applications are configured with the files stored in the config/. The routes.yaml file defines the routing configuration; the services.yaml file configures the services of the service container; the bundles.php file enables/ disables packages in your application.
You’ll be working most in the config/packages/ directory. This directory stores the configuration of every package installed in your application.
parameters (example: env(APP_TIMEZONE): ‘ ‘) inside services.yaml will be called from
docker\app.env example: APP_TIMEZONE=Asia/Singapore
Show the full list of all the services in the container. service id is on the left.
project_dir$: ./bin/console debug:container –show-private
our current configs
./bin/console debug:config framework
src\Kernel.php
configureContainer for loading configs
If want to see all the env variables that are currently set and Symfony version +System info details
./bin/console about
MakerBundle makes our life easier by generating code
composer require maker –dev
Type casting: Advanced environment variables example:
app. connection.port: ‘%env(int:DATABASE_PORT)%’
bool: , int:, float: and string: casting.
app. secrets: ‘%env(json:file:SECRETS_FILE)%’
Symfony debugging tools
install: compose require debug –dev
search debug on https://symfony.sh and view debug-pack which contains only composer.json file.
start Symfony server and install API Platform
symfony serve -d
composer require api
then go to locahost:8000/api to see API platform
create entity: ./bing//console make:entity
migration:
- composer require migrations
- ./bin/console/ make:migration
To list all routers
./bin/console debug:router
Service tags are a way to tell Symfony or other third-party bundles that your service should be registered in some special way.
Example: # config/services.yaml services: App\Twig\AppExtension: tags: ['twig.extension']
service container
Your application is full of useful objects: a “Mailer” object might help you send emails while another object might help you save things to the database. Almost everything that your app “does” is actually done by one of these objects. And each time you install a new bundle, you get access to even more!
In Symfony, these useful objects are called services and each service lives inside a very special object called the service container. The container allows you to centralize the way objects are constructed. It makes your life easier, promotes a strong architecture and is super fast!