Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Symfony CLI

Tom
October 28, 2014

The Symfony CLI

The Symfony2 full stack framework ships with a powerful command line interface that provides many useful tools to enhance your productivity as a developer. This talk provides an overview of selected commands to show how they can save time when developing applications in Symfony2.

Tom

October 28, 2014
Tweet

More Decks by Tom

Other Decks in Programming

Transcript

  1. ABOUT ME Developing Symfony apps since 2.0 Lead Developer of

    Co-Founder of Attended Symfony Live 2012 in Paris crscertus.com.au rostercloud.com
  2. THE CONSOLE ITSELF $ a p p / c o

    n s o l e S y m f o n y v e r s i o n 2 . 5 . 3 - a p p / d e v / d e b u g U s a g e : [ o p t i o n s ] c o m m a n d [ a r g u m e n t s ] O p t i o n s : - - h e l p - h D i s p l a y t h i s h e l p m e s s a g e . - - q u i e t - q D o n o t o u t p u t a n y m e s s a g e . - - v e r b o s e - v | v v | v v v I n c r e a s e t h e v e r b o s i t y o f m e s s a g e s : 1 f o r n o r m a l o u t p u t , 2 f o - - v e r s i o n - V D i s p l a y t h i s a p p l i c a t i o n v e r s i o n . - - a n s i F o r c e A N S I o u t p u t . - - n o - a n s i D i s a b l e A N S I o u t p u t . - - n o - i n t e r a c t i o n - n D o n o t a s k a n y i n t e r a c t i v e q u e s t i o n . - - s h e l l - s L a u n c h t h e s h e l l . - - p r o c e s s - i s o l a t i o n L a u n c h c o m m a n d s f r o m s h e l l a s a s e p a r a t e p r o c e s s . - - e n v - e T h e E n v i r o n m e n t n a m e . - - n o - d e b u g S w i t c h e s o f f d e b u g m o d e . A v a i l a b l e c o m m a n d s : h e l p D i s p l a y s h e l p f o r a c o m m a n d l i s t L i s t s c o m m a n d s a s s e t i c a s s e t i c : d u m p D u m p s a l l a s s e t s t o t h e f i l e s y s t e m a s s e t s a s s e t s : i n s t a l l I n s t a l l s b u n d l e s w e b a s s e t s u n d e r a p u b l i c w e b d i r c a c h e c a c h e : c l e a r C l e a r s t h e c a c h e c a c h e : w a r m u p W a r m s u p a n e m p t y c a c h e c o n f i g This will list every command registered in your application $ a p p / c o n s o l e | g r e p t w i g t w i g t w i g : d e b u g S h o w s a l i s t o f t w i g f u n c t i o n s , f i l t e r s , g l o b a l s a t w i g : l i n t L i n t s a t e m p l a t e a n d o u t p u t s e n c o u n t e r e d e r r o r s Combine it with grep
  3. SHORTCUT SYNTAX $ a p p / c o n

    s o l e d : s : v The above is equivalent to: $ a p p / c o n s o l e d o c t r i n e : s c h e m a : v a l i d a t e If the shortcut is ambiguous the console helps you out
  4. COMMANDS ARE SELF DOCUMENTING $ a p p / c

    o n s o l e h e l p t w i g : l i n t
  5. OTHER GENERAL NOTES Always be aware of what environment you

    need to run your command in Don't use interactive mode without a good reason. It will bite you
  6. THE COMMANDS NOW THAT WE KNOW HOW TO USE THE

    CONSOLE LETS EXPLORE THE COMMANDS
  7. ASSETIC Dumps all your assets (CSS/JS) and applies all configured

    filters $ a p p / c o n s o l e a s s e t i c : d u m p Scans your files for changes and reprocesses any modified files. Combine this with the following configuration for a huge speedup in dev $ a p p / c o n s o l e a s s e t i c : d u m p - - w a t c h # c o n f i g . y m l a s s e t i c : u s e _ c o n t r o l l e r : f a l s e
  8. ASSETS:INSTALL $ a p p / c o n s

    o l e a s s e t s : i n s t a l l Copy Resources/public from every bundle to the web directory Symfony 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 run this command again " e x t r a " : { " s y m f o n y - a s s e t s - i n s t a l l " : " s y m l i n k " }
  9. CACHE:CLEAR $ a p p / c o n s

    o l e c a c h e : c l e a r 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 has its own cache
  10. CONFIG:DUMP-REFERENCE $ a p p / c o n s

    o l e c o n f i g : d u m p - r e f e r e n c e First run this without any arguments to see all registered bundles $ a p p / c o n s o l e c o n f i g : d u m p - r e f e r e n c e t w i g Then supply a bundle name or alias to view all configuration options and defaults
  11. CONFIG:DEBUG $ a p p / c o n s

    o l e c o n f i g : d e b u g Very similar to config:dump-reference except that it shows your actual configuration $ a p p / c o n s o l e c o n f i g : d e b u g t w i g Like the last command you can then view the configuration for a bundle
  12. CONTAINER:DEBUG $ a p p / c o n s

    o l e c o n t a i n e r : d e b u g I use this heaps with grep $ a p p / c o n s o l e c o n t a i n e r : d e b u g | g r e p f o r m Also useful: $ a p p / c o n s o l e c o n t a i n e r : d e b u g - - t a g = f o r m . t y p e
  13. GENERATE:BUNDLE $ a p p / c o n s

    o l e g e n e r a t e : b u n d l e This is the first thing I do when starting a new project
  14. DOCTRINE:GENERATE:ENTITY $ a p p / c o n s

    o l e d o c t r i n e : g e n e r a t e : e n t i t y Fantastic for quickly stubbing out entities on the command line Demo!
  15. DOCTRINE:GENERATE:CRUD $ a p p / c o n s

    o l e d o c t r i n e : g e n e r a t e : c r u d Creates a form type, controller and templates Another massive timesaver
  16. DOCTRINE:GENERATE:ENTITIES $ a p p / c o n s

    o l e d o c t r i n e : g e n e r a t e : e n t i t i e s Creates entity class from your mapping The secret trick is it safely updates existing entities too!
  17. OTHER HANDY DOCTRINE COMMANDS d o c t r i

    n e : d a t a b a s e : c r e a t e C r e a t e s t h e c o n f i g u r e d d a t a b a s e s d o c t r i n e : d a t a b a s e : d r o p D r o p s t h e c o n f i g u r e d d a t a b a s e s d o c t r i n e : m a p p i n g : c o n v e r t C o n v e r t m a p p i n g i n f o r m a t i o n b e t w e e n s u p p o r t e d f o r m a t d o c t r i n e : m a p p i n g : i m p o r t I m p o r t s m a p p i n g i n f o r m a t i o n f r o m a n e x i s t i n g d a t a b a s d o c t r i n e : m a p p i n g : i n f o S h o w s b a s i c i n f o r m a t i o n a b o u t a l l m a p p e d e n t i t i e s d o c t r i n e : q u e r y : d q l E x e c u t e s a r b i t r a r y D Q L d i r e c t l y f r o m t h e c o m m a n d l i n d o c t r i n e : q u e r y : s q l E x e c u t e s a r b i t r a r y S Q L d i r e c t l y f r o m t h e c o m m a n d l i n d o c t r i n e : s c h e m a : c r e a t e E x e c u t e s ( o r d u m p s ) t h e S Q L n e e d e d t o g e n e r a t e t h e d d o c t r i n e : s c h e m a : d r o p E x e c u t e s ( o r d u m p s ) t h e S Q L n e e d e d t o d r o p t h e c u r r e d o c t r i n e : s c h e m a : u p d a t e E x e c u t e s ( o r d u m p s ) t h e S Q L n e e d e d t o u p d a t e t h e d a t d o c t r i n e : s c h e m a : v a l i d a t e V a l i d a t e s t h e d o c t r i n e m a p p i n g f i l e s
  18. SECURITY:CHECK $ a p p / c o n s

    o l e s e c u r i t y : c h e c k Sends your composer.lock file to the to see if any dependencies have know security issues SensioLabs Security Checker Work this in to your CI environment!
  19. SERVER:RUN $ a p p / c o n s

    o l e s e r v e r : r u n Spin up a webserver on Single threaded, so serving assets takes a while PHP 5.4+ It should go without saying but don't use this in production! localhost:8000