The Symfony CLI
-
Upload
sarah-el-atm -
Category
Technology
-
view
98 -
download
4
Transcript of The Symfony CLI
![Page 1: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/1.jpg)
THE SYMFONY CLIDIGITAL POETS SOCIETY - SYMFONY2 MEETUP (MELBOURNE)
Tom Corrigan / @thetommygnr
![Page 2: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/2.jpg)
ABOUT MEDeveloping Symfony apps since 2.0Lead Developer of Co-Founder of Attended Symfony Live 2012 in Paris
crscertus.com.aurostercloud.com
![Page 3: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/3.jpg)
THE CONSOLE ITSELF$ app/consoleSymfony version 2.5.3 - app/dev/debug
Usage: [options] command [arguments]
Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for --version -V Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction -n Do not ask any interactive question. --shell -s Launch the shell. --process-isolation Launch commands from shell as a separate process. --env -e The Environment name. --no-debug Switches off debug mode.
Available commands: help Displays help for a command list Lists commandsassetic assetic:dump Dumps all assets to the filesystemassets assets:install Installs bundles web assets under a public web directorycache cache:clear Clears the cache cache:warmup Warms up an empty cacheconfig
This will list every command registered in your application$ app/console | grep twigtwig twig:debug Shows a list of twig functions, filters, globals and twig:lint Lints a template and outputs encountered errors
Combine it with grep
![Page 4: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/4.jpg)
SHORTCUT SYNTAX$ app/console d:s:v
The above is equivalent to:$ app/console doctrine:schema:validate
If the shortcut is ambiguous the console helps you out
![Page 5: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/5.jpg)
COMMANDS ARE SELF DOCUMENTING$ app/console help twig:lint
![Page 6: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/6.jpg)
OTHER GENERAL NOTESAlways be aware of what environment you need to run yourcommand inDon't use interactive mode without a good reason. It will biteyou
![Page 7: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/7.jpg)
THE COMMANDSNOW THAT WE KNOW HOW TO USE THE CONSOLE LETS
EXPLORE THE COMMANDS
![Page 8: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/8.jpg)
ASSETICDumps all your assets (CSS/JS) and applies all configured filters$ app/console assetic:dump
Scans your files for changes and reprocesses any modified files.
Combine this with the following configuration for a hugespeedup in dev
$ app/console assetic:dump --watch
#config.ymlassetic: use_controller: false
![Page 9: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/9.jpg)
ASSETS:INSTALL$ app/console assets:install
Copy Resources/public from every bundle to the webdirectorySymfony has a composer post install/update hook to do this for
you
Tip: put this in your composer.json and you'll never have to runthis command again
"extra": { "symfony-assets-install": "symlink"}
![Page 10: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/10.jpg)
CACHE:CLEAR$ app/console cache:clear
Clears the application cache for a given environment
This is the first thing I try whenever I encounter weirdness
Note the importance of specifying an environment. Each env hasits own cache
![Page 11: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/11.jpg)
CONFIG:DUMP-REFERENCE$ app/console config:dump-reference
First run this without any arguments to see all registered bundles
$ app/console config:dump-reference twig
Then supply a bundle name or alias to view all configurationoptions and defaults
![Page 12: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/12.jpg)
CONFIG:DEBUG$ app/console config:debug
Very similar to config:dump-reference except that it shows youractual configuration
$ app/console config:debug twig
Like the last command you can then view the configuration for abundle
![Page 13: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/13.jpg)
CONTAINER:DEBUG$ app/console container:debug
I use this heaps with grep$ app/console container:debug | grep form
Also useful:$ app/console container:debug --tag=form.type
![Page 14: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/14.jpg)
GENERATE:BUNDLE$ app/console generate:bundle
This is the first thing I do when starting a new project
![Page 15: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/15.jpg)
DOCTRINE:GENERATE:ENTITY$ app/console doctrine:generate:entity
Fantastic for quickly stubbing out entities on the command line
Demo!
![Page 16: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/16.jpg)
DOCTRINE:GENERATE:CRUD$ app/console doctrine:generate:crud
Creates a form type, controller and templates
Another massive timesaver
![Page 17: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/17.jpg)
DOCTRINE:GENERATE:ENTITIES$ app/console doctrine:generate:entities
Creates entity class from your mapping
The secret trick is it safely updates existing entities too!
![Page 18: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/18.jpg)
OTHER HANDY DOCTRINE COMMANDSdoctrine:database:create Creates the configured databasesdoctrine:database:drop Drops the configured databasesdoctrine:mapping:convert Convert mapping information between supported formats.doctrine:mapping:import Imports mapping information from an existing databasedoctrine:mapping:info Shows basic information about all mapped entitiesdoctrine:query:dql Executes arbitrary DQL directly from the command line.doctrine:query:sql Executes arbitrary SQL directly from the command line.doctrine:schema:create Executes (or dumps) the SQL needed to generate the database schemadoctrine:schema:drop Executes (or dumps) the SQL needed to drop the current database schemadoctrine:schema:update Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadatadoctrine:schema:validate Validates the doctrine mapping files
![Page 19: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/19.jpg)
SECURITY:CHECK$ app/console security:check
Sends your composer.lock file to the to see if any dependencies have know security issues
SensioLabs SecurityChecker
Work this in to your CI environment!
![Page 20: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/20.jpg)
SERVER:RUN$ app/console server:run
Spin up a webserver on Single threaded, so serving assets takes a whilePHP 5.4+It should go without saying but don't use this in production!
localhost:8000
![Page 21: The Symfony CLI](https://reader031.fdocuments.us/reader031/viewer/2022031918/55a4e3601a28ab07658b45eb/html5/thumbnails/21.jpg)
THANKS