@@ -250,6 +250,59 @@ representation of the object.
250
250
parsers will likely not recognize the ``php/object `` tag and non-PHP
251
251
implementations certainly won't - use with discretion!
252
252
253
+ Syntax Validation
254
+ ~~~~~~~~~~~~~~~~~
255
+
256
+ The syntax of YAML contents can be validated through the CLI using the
257
+ :class: `Symfony\\ Component\\ Yaml\\ Command\\ LintCommand ` command.
258
+
259
+ Create a script containing a console application:
260
+
261
+ .. code-block :: php
262
+
263
+ // lint.php
264
+
265
+ use Symfony\Component\Console\Application;
266
+ use Symfony\Component\Yaml\Command\LintCommand;
267
+
268
+ (new Application('yaml/lint'))
269
+ ->add(new LintCommand())
270
+ ->getApplication()
271
+ ->setDefaultCommand('lint:yaml', true)
272
+ ->run();
273
+
274
+ Then, execute the script for validating contents:
275
+
276
+ .. code-block :: bash
277
+
278
+ # validates a single file
279
+ $ php lint.php path/to/file.yml
280
+
281
+ # or all the files in a directory
282
+ $ php lint.php path/to/directory
283
+
284
+ # or contents passed to STDIN
285
+ $ cat path/to/file.yml | php lint.php
286
+
287
+ The result will be written on STDOUT, default in TXT format:
288
+
289
+ .. code-block :: bash
290
+
291
+ [OK] All 1 YAML files contain valid syntax.
292
+
293
+ For a JSON output, use the ``format `` option:
294
+
295
+ .. code-block :: bash
296
+
297
+ $ php lint.php path/to/file.yml --format json
298
+
299
+ [
300
+ {
301
+ " file" : " path/to/file.yml" ,
302
+ " valid" : true
303
+ }
304
+ ]
305
+
253
306
Learn More
254
307
----------
255
308
0 commit comments