├── .gitignore
├── README.md
├── bin
└── readme.php
├── composer.json
├── composer.lock
└── templates
├── knp_frontend.xml
└── knp_symfony.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor/
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PhpStorm Live Templates (+ other settings)
2 |
3 | This repository includes [live templates](http://knpuniversity.com/screencast/phpstorm/live-templates)
4 | for PhpStorm (and may contain other settings in the future).
5 |
6 | **Share your Favorite Settings!** This isn't meant to be a readonly repository. Have
7 | something you love about your PhpStorm setup? Create a pull request and share it.
8 |
9 | [See the Live Templates](#live-templates)
10 |
11 | ## Installation
12 |
13 | 1. Go to *PhpStorm Preferences | Tools | Settings Repository*
14 |
15 | 2. Add Read-only Source https://github.com/knpuniversity/phpstorm-settings
16 |
17 | 3. Restart PhpStorm
18 |
19 | You can see and manage all the snippets under the *Preferences | Editor | Live Templates*
20 |
21 | ## Live Templates
22 |
23 | ### Frontend Templates
24 |
25 | #### lorem
26 |
27 | ```php
28 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
29 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
30 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
31 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
32 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
33 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
34 | ```
35 |
36 | ### Symfony Templates
37 |
38 | #### formhandle
39 |
40 | Adds controller form-handling code
41 |
42 | ```php
43 | $form = $this->createForm($CLASSNAME$::class);
44 |
45 | $form->handleRequest($request);
46 | if ($form->isSubmitted() && $form->isValid()) {
47 | // todo - do some work, like saving stuff
48 |
49 | $this->addFlash('success', '$SUCCESSMESSAGE$');
50 |
51 | return $this->redirectToRoute('$ROUTENAME$', []);
52 | }
53 | ```
54 |
55 | #### formrow
56 |
57 | ```php
58 | {{ form_row(form.$FIELD$) }}
59 | ```
60 |
61 | #### formrowfull
62 |
63 | Renders widget/label/errors
64 |
65 | ```php
66 |
67 | {{ form_label(form.$FIELD$) }}
68 | {{ form_widget(form.$FIELD$) }}
69 | {{ form_errors(form.$FIELD$) }}
70 |
71 | ```
72 |
73 | #### repofind
74 |
75 | Queries from a doctrine repository in a controller
76 |
77 | ```php
78 | $this->getDoctrine()
79 | ->getRepository('$REPO$')->$METHOD$($ARG$);
80 | ```
81 |
82 | #### rendertwig
83 |
84 | Renders a Twig template from a controller
85 |
86 | ```php
87 | return $this->render('$TEMPLATE$', [
88 | $END$
89 | ]);
90 |
91 | ```
92 |
93 | #### 404unless
94 |
95 | 404 if statement for your controller
96 |
97 | ```php
98 | if ($CONDITION$) {
99 | throw $this->createNotFoundException($MESSAGE$);
100 | }
101 | ```
102 |
103 | #### include
104 |
105 | ```php
106 | {{ include('$TEMPLATE$') }}
107 | ```
108 |
109 | #### method
110 |
111 | ```php
112 | @Method("$METHOD$")
113 | ```
114 |
115 | #### path
116 |
117 | ```php
118 | {{ path('$ROUTE$', { $END$ }) }}
119 | ```
120 |
121 | #### render
122 |
123 | ```php
124 | {{ render(controller('$CONTROLLER$', { $END$ })) }}
125 | ```
126 |
127 | #### route
128 |
129 | ```php
130 | @Route("/$PATH$", name="$NAME$")
131 | ```
132 |
133 | #### action
134 |
135 | Creates a controller action.
136 |
137 | ```php
138 | /**
139 | * @Route("/$PATH$", name="$ROUTE_NAME$")
140 | */
141 | public function $NAME$Action()
142 | {
143 | $END$
144 | }
145 | ```
146 |
147 | #### service
148 |
149 | Creates a YML service
150 |
151 | ```php
152 | $NAME$:
153 | class: $CLASS$
154 | arguments:
155 | - '$ARG1$'
156 | ```
157 |
158 | #### tags
159 |
160 | Yaml service tags
161 |
162 | ```php
163 | tags:
164 | - { name: $TAGNAME$ }
165 | ```
166 |
167 | #### createquery
168 |
169 | Query objects in repositories with DQL
170 |
171 | ```php
172 | $this->getEntityManager()
173 | ->createQuery('SELECT $ALIAS$
174 | FROM $ENTITY$ $ALIAS$
175 | WHERE $ALIAS$.$PROPERTY$ = :$PARAMETER$')
176 | ->setParameter('$PARAMETER$', $ARGUMENT$)
177 | ->execute();
178 | ```
179 |
180 | #### getem
181 |
182 | ```php
183 | $em = $this->getDoctrine()->getManager();
184 | ```
185 |
186 | #### getrepo
187 |
188 | ```php
189 | $em->getRepository('$ENTITY$');
190 | ```
191 |
192 | #### doctrinecolumn
193 |
194 | Adds a property with @ORM annotations
195 |
196 | ```php
197 | /**
198 | * @ORM\Column(type="$TYPE$")
199 | */
200 | private $$$PROPERTYNAME$;
201 | ```
202 |
203 | #### asset
204 |
205 | ```php
206 | {{ asset('$PATH$') }}
207 | ```
208 |
209 | #### asseticjs
210 |
211 | ```php
212 | {% javascripts
213 | '$PATH$'$END$
214 | %}
215 |
216 | {% endjavascripts %}
217 | ```
218 |
219 | #### asseticcss
220 |
221 | ```php
222 | {% stylesheets
223 | '$PATH$'$END$
224 | filter='cssrewrite'
225 | %}
226 |
227 | {% endstylesheets %}
228 | ```
229 |
230 | #### xmlservices
231 |
232 | Generates an XML services file
233 |
234 | ```php
235 |
236 |
237 |
240 |
241 |
242 |
243 |
244 |
245 | ```
246 |
247 | #### yamlroute
248 |
249 | YAML route
250 |
251 | ```php
252 | $NAME$:
253 | path: /$PATH$
254 | defaults: { _controller: $CONTROLLER$ }
255 | ```
256 |
257 | #### querybuilder
258 |
259 | Query objects in repositories using query builder
260 |
261 | ```php
262 | $this->createQueryBuilder('$ALIAS$')
263 | ->where('$ALIAS$.$PROPERTY$ = :$PARAMETER$')
264 | ->setParameter('$PARAMETER$', $ARGUMENT$)
265 | ->getQuery();
266 | ```
267 |
268 | #### trans
269 |
270 | Allows fast entering of translated messages
271 |
272 | ```php
273 | {{ '$MESSAGE$'|trans }}
274 | ```
275 |
276 | #### servix
277 |
278 | Creates a XML service
279 |
280 | ```php
281 |
282 |
283 |
284 | ```
285 |
286 | ## Credits
287 |
288 | First, a thanks to [nicwortel](https://github.com/nicwortel) for this https://github.com/nicwortel/phpstorm-ide-config
289 | repository, which contains some nice settings (including stuff that we don't have
290 | here). He also did a really nice job with his README, and I've borrowed parts of it
291 | shamelessly.
292 |
293 | A number of people have contributed to this repository. Additionally, some templates
294 | were adapted from https://github.com/raulfraile/sublime-symfony2.
295 |
--------------------------------------------------------------------------------
/bin/readme.php:
--------------------------------------------------------------------------------
1 | in(__DIR__.'/../templates')
9 | ->name('*.xml');
10 |
11 | $md = '';
12 | foreach ($finder as $templateFile) {
13 | $xml = file_get_contents($templateFile);
14 |
15 | $element = simplexml_load_string($xml);
16 | $name = (string) $element->attributes()->group;
17 | // remove any knp_ prefix
18 | $name = str_replace('knp_', '', $name);
19 | $name = str_replace('_', ' ', $name);
20 | $name = ucwords($name);
21 |
22 | $md .= sprintf("### %s Templates\n\n", $name);
23 |
24 | foreach ($element->template as $templateElement) {
25 | $template = (string)$templateElement->attributes()->value;
26 | $name = (string)$templateElement->attributes()->name;
27 | $description = (string)$templateElement->attributes()->description;
28 |
29 | $md .= sprintf("#### %s\n\n", $name);
30 | if ($description) {
31 | $md .= $description."\n\n";
32 | }
33 | $md .= sprintf("```php\n%s\n```\n\n", $template);
34 | }
35 |
36 | }
37 |
38 | echo $md."\n";
39 |
40 |
41 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "knpuniversity/phpstorm-settings",
3 | "require": {
4 | "symfony/finder": "^2.7"
5 | },
6 | "authors": [
7 | {
8 | "name": "Ryan Weaver",
9 | "email": "ryan@knpuniversity.com"
10 | }
11 | ]
12 | }
13 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 | "This file is @generated automatically"
6 | ],
7 | "hash": "2d36e47d7322a8c52a177ce0125291c9",
8 | "packages": [
9 | {
10 | "name": "symfony/finder",
11 | "version": "v2.7.3",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/symfony/Finder.git",
15 | "reference": "ae0f363277485094edc04c9f3cbe595b183b78e4"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/symfony/Finder/zipball/ae0f363277485094edc04c9f3cbe595b183b78e4",
20 | "reference": "ae0f363277485094edc04c9f3cbe595b183b78e4",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "php": ">=5.3.9"
25 | },
26 | "require-dev": {
27 | "symfony/phpunit-bridge": "~2.7"
28 | },
29 | "type": "library",
30 | "extra": {
31 | "branch-alias": {
32 | "dev-master": "2.7-dev"
33 | }
34 | },
35 | "autoload": {
36 | "psr-4": {
37 | "Symfony\\Component\\Finder\\": ""
38 | }
39 | },
40 | "notification-url": "https://packagist.org/downloads/",
41 | "license": [
42 | "MIT"
43 | ],
44 | "authors": [
45 | {
46 | "name": "Fabien Potencier",
47 | "email": "fabien@symfony.com"
48 | },
49 | {
50 | "name": "Symfony Community",
51 | "homepage": "https://symfony.com/contributors"
52 | }
53 | ],
54 | "description": "Symfony Finder Component",
55 | "homepage": "https://symfony.com",
56 | "time": "2015-07-09 16:07:40"
57 | }
58 | ],
59 | "packages-dev": [],
60 | "aliases": [],
61 | "minimum-stability": "stable",
62 | "stability-flags": [],
63 | "prefer-stable": false,
64 | "prefer-lowest": false,
65 | "platform": [],
66 | "platform-dev": []
67 | }
68 |
--------------------------------------------------------------------------------
/templates/knp_frontend.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/templates/knp_symfony.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
--------------------------------------------------------------------------------