├── .editorconfig ├── README.md ├── UltiSnips ├── php_classes.snippets ├── php_jms_serializer.snippets ├── php_methods.snippets ├── php_phpunit.snippets ├── php_s2_bundle.snippets ├── php_s2_command.snippets ├── php_s2_controller.snippets ├── php_s2_doctrine.snippets ├── php_s2_form.snippets ├── php_s2_twig.snippets ├── php_s2_validator.snippets └── yaml_s2.snippets └── doc ├── jms.md ├── php.md ├── phpunit.md └── symfony2.md /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | 7 | [*.snippets] 8 | indent_style = tab 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ultisnips-php # 2 | 3 | A vim bundle with snippets for *PHP* developers. 4 | It contains snippets for the following tools: 5 | - *PHP* - [snippets](doc/php.md) | [website][php-website] 6 | - *PHPUnit* - [snippets](doc/phpunit.md) | [website][phpunit-website] 7 | - *Symfony2* - [snippets](doc/symfony2.md) | [website][symfony2-website] 8 | - *JMSSerializerBundle* - [snippets](doc/jms.md) | [website][jms-website] 9 | 10 | Required bundles: 11 | - [ultisnips](https://github.com/SirVer/ultisnips) 12 | 13 | ## Installation 14 | 15 | ### Install with [vundle](https://github.com/gmarik/vundle) 16 | 17 | Add to vimrc: 18 | 19 | Plugin "algotech/ultisnips-php" 20 | 21 | And install it: 22 | 23 | :so ~/.vimrc 24 | :PluginInstall 25 | 26 | ### Install with [pathogen](https://github.com/tpope/vim-pathogen) 27 | 28 | cd ~/.vim/bundle 29 | git clone https://github.com/algotech/ultisnips-php.git 30 | 31 | [php-website]: http://php.net 32 | [phpunit-website]: https://phpunit.de 33 | [symfony2-website]: http://symfony.com 34 | [jms-website]: http://jmsyst.com/bundles/JMSSerializerBundle 35 | -------------------------------------------------------------------------------- /UltiSnips/php_classes.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet class "Class" b 4 | GraphNavigator::DIRECTION_DESERIALIZATION, 37 | 'format' => '${1:json}', 38 | 'type' => '${2}', 39 | ),${0} 40 | endsnippet 41 | 42 | snippet jmsdeserialize "JMSSerializerBundle / Handler subscriber / Deserialize method" b 43 | public function deserialize${1:Type}From${2:Json}( 44 | JsonDeserializationVisitor $visitor, 45 | array $obj, 46 | array $type, 47 | Context $context 48 | ) { 49 | return ${0} 50 | } 51 | endsnippet 52 | -------------------------------------------------------------------------------- /UltiSnips/php_methods.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet get "Method / Getter" b 4 | /** 5 | * Get ${1} 6 | * 7 | * @return ${2:mixed} 8 | */ 9 | public function get${1/\w+\s*/\u$0/}() 10 | { 11 | return $this->$1;${3} 12 | }${0} 13 | endsnippet 14 | 15 | snippet set "Method / Setter" b 16 | /** 17 | * Set ${1} 18 | * 19 | * @param ${2:mixed} $$1 20 | * @return ${3:mixed} 21 | */ 22 | public function set${1/\w+\s*/\u$0/}(${4:$2 }$$1) 23 | { 24 | $this->$1 = $$1;${5} 25 | 26 | return \$this; 27 | }${0} 28 | endsnippet 29 | 30 | snippet sta "Public static method" b 31 | public static function ${1:name}(${2:$param}) 32 | { 33 | ${VISUAL}${5:return null;} 34 | } 35 | $0 36 | endsnippet 37 | 38 | snippet pub "Public method" b 39 | public function ${1:name}(${2:$param}) 40 | { 41 | ${VISUAL}${5:return null;} 42 | } 43 | $0 44 | endsnippet 45 | 46 | snippet pro "Protected method" b 47 | protected function ${1:name}(${2:$param}) 48 | { 49 | ${VISUAL}${5:return null;} 50 | } 51 | $0 52 | endsnippet 53 | 54 | snippet pri "Private method" b 55 | private function ${1:name}(${2:$param}) 56 | { 57 | ${VISUAL}${5:return null;} 58 | } 59 | $0 60 | endsnippet 61 | -------------------------------------------------------------------------------- /UltiSnips/php_phpunit.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet putest "PHPUnit / Test Case" b 4 | getMockBuilder('${1}') 23 | ->setMethods(array(${2})) 24 | ->disableOriginalConstructor() 25 | ->getMock()${0} 26 | endsnippet 27 | 28 | snippet pumockpartial "PHPUnit / Mock Builder Partial" 29 | \$this 30 | ->getMockBuilder('${1}') 31 | ->setConstructorArgs(array(${2})) 32 | ->setMethods(array(${3})) 33 | ->getMock()${0} 34 | endsnippet 35 | 36 | snippet puexpects "PHPUnit / Expects" 37 | ->expects($this->${1:once}()) 38 | ->method('${2}') 39 | ->with(\$this->equalTo(${3})) 40 | ->will(\$this->${4:returnValue}(${5}))${0} 41 | endsnippet 42 | 43 | snippet puexpectsat "PHPUnit / Expects at" 44 | ->expects($this->at(${1:0})) 45 | ->method('${2}') 46 | ->with(\$this->equalTo(${3})) 47 | ->will(\$this->${4:returnValue}(${5}))${0} 48 | endsnippet 49 | -------------------------------------------------------------------------------- /UltiSnips/php_s2_bundle.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet sfbundle "Symfony2 / Bundle / Bundle class" b 4 | processConfiguration($configuration, $configs); 49 | ${0} 50 | $loader = new Loader\YamlFileLoader( 51 | $container, 52 | new FileLocator(__DIR__.'/../Resources/config') 53 | ); 54 | 55 | $loader->load('services.yml'); 56 | } 57 | } 58 | endsnippet 59 | 60 | snippet sfbundleconfig "Symfony2 / Bundle / Config class" b 61 | root('${1:bundle_namespace}'); 86 | ${0} 87 | return $treeBuilder; 88 | } 89 | } 90 | endsnippet 91 | -------------------------------------------------------------------------------- /UltiSnips/php_s2_command.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet sfcommandca "Symfony2 / Command / Command class (container aware)" b 4 | setName('${1:default:command}') 27 | ->setDescription('${2:Default description}') 28 | ; 29 | } 30 | 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | protected function execute(InputInterface \$input, OutputInterface \$output) 35 | { 36 | ${0} 37 | } 38 | } 39 | endsnippet 40 | 41 | snippet sfcommand "Symfony2 / Command / Command class" b 42 | setName('${1:default:command}') 65 | ->setDescription('${2:Default description}') 66 | ; 67 | } 68 | 69 | /** 70 | * {@inheritdoc} 71 | */ 72 | protected function execute(InputInterface \$input, OutputInterface \$output) 73 | { 74 | ${0} 75 | } 76 | } 77 | endsnippet 78 | -------------------------------------------------------------------------------- /UltiSnips/php_s2_controller.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet sfcontroller "Symfony2 / Controller / Controller class" b 4 | render('${3:Bundle:Folder:file.html.twig}', array(${4})); 23 | } 24 | } 25 | endsnippet 26 | 27 | snippet sfcontrollera "Symfony2 / Controller / Controller class (annotated)" b 28 | render('${3:Bundle:Folder:file.html.twig}', array(${4})); 61 | } 62 | endsnippet 63 | 64 | snippet sfactiona "Symfony2 / Controller / Action (annotated)" b 65 | /** 66 | * @Route("${1:/}"${2:, name="${3}"}) 67 | * @Template(${4}) 68 | */ 69 | public function ${5:index}Action(${6:Request $request}) 70 | { 71 | ${0} 72 | } 73 | endsnippet 74 | 75 | snippet sfrender "Symfony2 / Controller / Render" 76 | return \$this->render('${1:Bundle:Folder:file.html.twig}', array(${2})); 77 | endsnippet 78 | 79 | snippet sfforward "Symfony2 / Controller / Forward" 80 | \$this->forward( 81 | '${1:Bundle}:${2:Controller}:${3:action}', 82 | array(${4}) 83 | ); 84 | endsnippet 85 | 86 | snippet sfredirect "Symfony2 / Controller / Redirect" 87 | \$this->redirect( 88 | \$this->generateUrl( 89 | '${1:route}', 90 | array(${2}) 91 | )${3:, 92 | code} 93 | ); 94 | endsnippet 95 | -------------------------------------------------------------------------------- /UltiSnips/php_s2_doctrine.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet sfrepository "Symfony2 / Doctrine / Repository" b 4 | add(${0} 27 | ; 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function setDefaultOptions(OptionsResolverInterface \$resolver) 34 | { 35 | \$resolver->setDefaults(array( 36 | 'data_class' => ${2:null}, 37 | )); 38 | } 39 | 40 | /** 41 | * {@inheritdoc} 42 | */ 43 | public function getName() 44 | { 45 | return '${1:form_name}'; 46 | } 47 | } 48 | endsnippet 49 | 50 | snippet sfdatatransformer "Symfony2 / Form / Data Transformer" b 51 | GraphNavigator::DIRECTION_DESERIALIZATION, 48 | 'format' => 'json', 49 | 'type' => '', 50 | ), 51 | 52 | ``` 53 | 54 | `jmsdeserialize` 55 | 56 | ```php 57 | public function deserializeTypeFromJson( 58 | JsonDeserializationVisitor $visitor, 59 | array $obj, 60 | array $type, 61 | Context $context 62 | ) { 63 | return 64 | } 65 | ``` 66 | -------------------------------------------------------------------------------- /doc/php.md: -------------------------------------------------------------------------------- 1 | # PHP snippets for vim # 2 | 3 | - [Classes](#classes) 4 | - [Generic methods](#generic-methods) 5 | - [Getters and setters](#getters-and-setters) 6 | - [Back to main page](../README.md) 7 | 8 | ### Classes ### 9 | 10 | `class` 11 | 12 | ```php 13 | variable; 87 | } 88 | 89 | ``` 90 | 91 | `set` 92 | 93 | ```php 94 | /** 95 | * Set variable 96 | * 97 | * @param mixed $variable 98 | * @return mixed 99 | */ 100 | public function setVariable($variable) 101 | { 102 | $this->variable = $variable; 103 | 104 | return $this; 105 | } 106 | ``` 107 | -------------------------------------------------------------------------------- /doc/phpunit.md: -------------------------------------------------------------------------------- 1 | # PHPUnit snippets for vim # 2 | 3 | - [Classes](#classes) 4 | - [Mockings](#mockings) 5 | - [Expectations](#expectations) 6 | - [Back to main page](../README.md) 7 | 8 | All shortcuts start with the `pu` prefix and are both short and intuitive: 9 | 10 | ### Classes ### 11 | 12 | `putest` 13 | 14 | ```php 15 | getMockBuilder('Class') 38 | ->setMethods(array()) 39 | ->disableOriginalConstructor() 40 | ->getMock() 41 | ``` 42 | 43 | `pumockpartial` 44 | 45 | ```php 46 | $this 47 | ->getMockBuilder('Class') 48 | ->setConstructorArgs(array()) 49 | ->setMethods(array()) 50 | ->getMock() 51 | ``` 52 | 53 | ### Expectations ### 54 | 55 | `puexpects` 56 | 57 | ```php 58 | ->expects($this->once()) 59 | ->method('method') 60 | ->with($this->equalTo('something')) 61 | ->will($this->returnValue(null)) 62 | ``` 63 | 64 | `puexpectsat` 65 | 66 | ```php 67 | ->expects($this->at(0)) 68 | ->method('method') 69 | ->with($this->equalTo('something')) 70 | ->will($this->returnValue(null)) 71 | ``` 72 | -------------------------------------------------------------------------------- /doc/symfony2.md: -------------------------------------------------------------------------------- 1 | # Symfony2 snippets for vim # 2 | 3 | - [Bundle](#bundle) 4 | - [Command](#command) 5 | - [Controller](#controller) 6 | - [Doctrine](#doctrine) 7 | - [Form](#form) 8 | - [Twig](#twig) 9 | - [Validator](#validator) 10 | - [YML](#yml) 11 | - [Back to main page](../README.md) 12 | 13 | All shortcuts start with the `sf` prefix and are both short and intuitive: 14 | 15 | ### Bundle ### 16 | 17 | `sfbundle` 18 | 19 | ```php 20 | processConfiguration($configuration, $configs); 67 | 68 | $loader = new Loader\YamlFileLoader( 69 | $container, 70 | new FileLocator(__DIR__.'/../Resources/config') 71 | ); 72 | 73 | $loader->load('services.yml'); 74 | } 75 | } 76 | ``` 77 | 78 | `sfbundleconfig` 79 | 80 | ```php 81 | root('algotech_main'); 106 | 107 | return $treeBuilder; 108 | } 109 | } 110 | ``` 111 | 112 | ### Command ### 113 | 114 | `sfcommandca` 115 | 116 | ```php 117 | setName('default:command') 140 | ->setDescription('Default description') 141 | ; 142 | } 143 | 144 | /** 145 | * {@inheritdoc} 146 | */ 147 | protected function execute(InputInterface $input, OutputInterface $output) 148 | { 149 | 150 | } 151 | } 152 | ``` 153 | 154 | `sfcommand` 155 | 156 | ```php 157 | setName('default:command') 180 | ->setDescription('Default description') 181 | ; 182 | } 183 | 184 | /** 185 | * {@inheritdoc} 186 | */ 187 | protected function execute(InputInterface $input, OutputInterface $output) 188 | { 189 | 190 | } 191 | } 192 | ``` 193 | 194 | ### Controller ### 195 | 196 | `sfcontroller` 197 | 198 | ```php 199 | render('Bundle:Folder:file.html.twig', array()); 218 | } 219 | } 220 | ``` 221 | 222 | `sfcontrollera` 223 | 224 | ```php 225 | render('Bundle:Folder:file.html.twig', array()); 260 | } 261 | ``` 262 | 263 | `sfactiona` 264 | 265 | ```php 266 | /** 267 | * @Route("custom", name="default.custom") 268 | * @Template(custom) 269 | */ 270 | public function customAction(Request $request) 271 | { 272 | 273 | } 274 | ``` 275 | 276 | `sfrender` 277 | 278 | ```php 279 | return $this->render('Bundle:Folder:file.html.twig', array()); 280 | ``` 281 | 282 | `sfforward` 283 | 284 | ```php 285 | $this->forward( 286 | 'Bundle:Controller:action', 287 | array() 288 | ); 289 | ``` 290 | 291 | `sfredirect` 292 | 293 | ```php 294 | $this->redirect( 295 | $this->generateUrl( 296 | 'route', 297 | array() 298 | ) 299 | ); 300 | ``` 301 | 302 | ### Doctrine ### 303 | 304 | `sfrepository` 305 | 306 | ```php 307 | setDefaults(array( 480 | 'data_class' => null, 481 | )); 482 | } 483 | 484 | /** 485 | * {@inheritdoc} 486 | */ 487 | public function getName() 488 | { 489 | return 'custom'; 490 | } 491 | } 492 | ``` 493 | 494 | `sfdatatransformer` 495 | 496 | ```php 497 |