About the Drupal VM Generator Symfony application Twig Generates minimal, use-case speci c con guration les http://bit.ly/announcing-drupal-vm-generator
Drupal VM Generator Example 2 d r u p a l v m c o n f i g : g e n e r a t e \ - - m a c h i n e - n a m e = " d r u p a l b r i s t o l " \ - - h o s t n a m e = " d r u p a l b r i s t o l . l " \ - - i p - a d d r e s s = " 1 9 2 . 1 6 8 . 8 8 . 8 8 " \ - - c p u s = " 1 " - - m e m o r y = " 5 1 2 " \ - - w e b s e r v e r = " n g i n x " - - d r u p a l - v e r s i o n = " 8 " \ - - d a t a b a s e - n a m e = " d r u p a l " - - d a t a b a s e - u s e r = " d r u p a l " \ - - d a t a b a s e - p a s s w o r d = " d r u p a l " - - b u i l d - m a k e f i l e = f a l s e \ . . .
The Console component eases the creation of beautiful and testable command line interfaces. The Console component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs. http://symfony.com/doc/current/components/console/introduction.html
bin/drupalcamp.php r e q u i r e _ _ D I R _ _ . ' / . . / v e n d o r / a u t o l o a d . p h p ' ; u s e S y m f o n y \ C o m p o n e n t \ C o n s o l e \ A p p l i c a t i o n ; $ a p p l i c a t i o n = n e w A p p l i c a t i o n ( ) ; $ a p p l i c a t i o n - > r u n ( ) ;
bin/drupalcamp.php (cont) r e q u i r e _ _ D I R _ _ . ' / . . / v e n d o r / a u t o l o a d . p h p ' ; u s e S y m f o n y \ C o m p o n e n t \ C o n s o l e \ A p p l i c a t i o n ; $ a p p l i c a t i o n = n e w A p p l i c a t i o n ( ) ; $ a p p l i c a t i o n - > r u n ( ' D r u p a l C a m p s ' , ' 1 . 0 ' ) ;
src/GoCommand.php u s e S y m f o n y \ C o m p o n e n t \ C o n s o l e \ C o m m a n d \ C o m m a n d ; c l a s s G o C o m m a n d e x t e n d s C o m m a n d { p u b l i c f u n c t i o n c o n f i g u r e ( ) { $ t h i s - > s e t N a m e ( ' g o ' ) - > s e t D e s c r i p t i o n ( ' G o t o a D r u p a l C a m p . ' ) ; } }
src/GoCommand.php (cont) u s e S y m f o n y \ C o m p o n e n t \ C o n s o l e \ I n p u t \ I n p u t I n t e r f a c e ; u s e S y m f o n y \ C o m p o n e n t \ C o n s o l e \ O u t p u t \ O u t p u t I n t e r f a c e ; . . . p u b l i c f u n c t i o n e x e c u t e ( I n p u t I n t e r f a c e $ i n p u t , O u t p u t I n t e r f a c e $ o u t p u t ) { / / E x e c u t e t h e c o m m a n d . }
bin/drupalcamp.php $ a p p l i c a t i o n = n e w A p p l i c a t i o n ( ) ; $ a p p l i c a t i o n - > a d d ( n e w G o C o m m a n d ( ) ) ; $ a p p l i c a t i o n - > r u n ( ) ;
bin/drupalcamp.php $ a p p l i c a t i o n = n e w A p p l i c a t i o n ( ) ; $ a p p l i c a t i o n - > a d d C o m m a n d s ( [ n e w G o C o m m a n d ( ) , ] ) ; $ a p p l i c a t i o n - > r u n ( ) ;
src/GoCommand.php u s e S y m f o n y \ C o m p o n e n t \ C o n s o l e \ I n p u t \ I n p u t A r g u m e n t ; . . . p u b l i c f u n c t i o n c o n f i g u r e ( ) { $ t h i s - > s e t N a m e ( ' g o ' ) - > s e t D e s c r i p t i o n ( ' G o t o a D r u p a l C a m p ' ) - > a d d A r g u m e n t ( ' n a m e ' , I n p u t A r g u m e n t : : O P T I O N A L , ' W h i c h D r u p a l C a m p ? ' ) - > a d d O p t i o n ( ' p a s t ' , n u l l , I n p u t O p t i o n : : V A L U E _ N O N E ) ; }
src/GoCommand.php (cont) p u b l i c f u n c t i o n e x e c u t e ( I n p u t I n t e r f a c e $ i n p u t , O u t p u t I n t e r f a c e $ o u t p u t ) { $ t e x t = $ i n p u t - > g e t A r g u m e n t ( ' n a m e ' ) ; $ p a s t = $ i n p u t - > g e t O p t i o n ( ' p a s t ' ) ; . . . }
OutputInterface $ o u t p u t - > w r i t e ( " < i n f o > $ t e x t < / i n f o > " ) ; $ o u t p u t - > w r i t e ( " < e r r o r > $ t e x t < / e r r o r > " ) ; $ o u t p u t - > w r i t e ( " < d e b u g > $ t e x t < / d e b u g > " ) ;
SymfonyStyle p u b l i c f u n c t i o n e x e c u t e ( I n p u t I n t e r f a c e $ i n p u t , O u t p u t I n t e r f a c e $ o u t p u t ) { $ i o = n e w S y m f o n y S t y l e ( $ i n p u t , $ o u t p u t ) ; $ i o - > t a b l e ( [ ' T i t l e ' , ' S p e a k e r ' ] , [ [ ' D r u p a l V M , M e e t S y m f o n y C o n s o l e ' , ' O l i v e r D a v i e s ' ] , [ ' D r u p a l 8 a n d t h e S y m f o n y E v e n t D i s p a t c h e r ' , ' E r i c S m i t h ' ] , [ ' B u i l d i n g w i t h A P I s ' , ' N i g e l D u n n ' ] , ] ) ; }
src/GoCommand.php p u b l i c f u n c t i o n i n t e r a c t ( I n p u t I n t e r f a c e $ i n p u t , O u t p u t I n t e r f a c e $ o u t p u t ) { $ i o = n e w S y m f o n y S t y l e ( $ i n p u t , $ o u t p u t ) ; i f ( ! $ i n p u t - > g e t A r g u m e n t ( ' n a m e ' ) ) { $ i n p u t - > s e t A r g u m e n t ( ' n a m e ' , $ i o - > a s k ( ' W h i c h D r u p a l C a m p ? ' ) ) ; } }
src/GoCommand.php p u b l i c f u n c t i o n e x e c u t e ( I n p u t I n t e r f a c e $ i n p u t , O u t p u t I n t e r f a c e $ o u t p u t ) { $ i o = n e w S y m f o n y S t y l e ( $ i n p u t , $ o u t p u t ) ; $ i o - > s u c c e s s ( $ i n p u t - > g e t A r g u m e n t ( ' n a m e ' ) ) ; }
Dependency Injection Instantiate dependencies in single place or DI container Add as arguments when adding commands Add as arguments to the constructor and assign to properties Make sure to call the __construct() method within the parent class.
src/Console/Application.php u s e G u z z l e H t t p \ C l i e n t ; . . . $ c l i e n t = n e w C l i e n t ( ) ; $ a p p l i c a t i o n - > a d d ( n e w N e w C o m m a n d ( $ c l i e n t ) ) ;
src/Command/NewCommand.php u s e G u z z l e H t t p \ C l i e n t I n t e r f a c e ; u s e S y m f o n y \ C o m p o n e n t \ C o n s o l e \ C o m m a n d ; f i n a l c l a s s N e w C o m m a n d e x t e n d s C o m m a n d { p r i v a t e $ c l i e n t ; p u b l i c f u n c t i o n _ _ c o n s t r u c t ( C l i e n t I n t e r f a c e $ c l i e n t ) { p a r e n t : : _ _ c o n s t r u c t ( ) ; $ t h i s - > c l i e n t = $ c l i e n t ; } }
Generating phar les # c o m p o s e r . j s o n " s c r i p t s " : { " b u i l d " : [ " b o x b u i l d " , " s h a s u m d r u p a l v m . p h a r | a w k ' { p r i n t $ 1 } ' > d r u p a l v m . p h a r . v e r s i o n " ] } $ c o m p o s e r r u n - s c r i p t b u i l d