PHPackages                             matthiasnoback/symfony-service-definition-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. matthiasnoback/symfony-service-definition-validator

ActiveLibrary

matthiasnoback/symfony-service-definition-validator
===================================================

Library for validating service definitions created with the Symfony Dependency Injection Component

v1.2.10(4y ago)89358.5k—7.9%16[1 issues](https://github.com/matthiasnoback/symfony-service-definition-validator/issues)[1 PRs](https://github.com/matthiasnoback/symfony-service-definition-validator/pulls)6MITPHPPHP ^7.4

Since Aug 28Pushed 3y ago7 watchersCompare

[ Source](https://github.com/matthiasnoback/symfony-service-definition-validator)[ Packagist](https://packagist.org/packages/matthiasnoback/symfony-service-definition-validator)[ Docs](http://github.com/matthiasnoback/symfony-service-definition-validator)[ RSS](/packages/matthiasnoback-symfony-service-definition-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (23)Used By (6)

Symfony Service Definition Validator
====================================

[](#symfony-service-definition-validator)

By Matthias Noback

[![Build Status](https://camo.githubusercontent.com/7c394f69874a4a01f7c43167795d661b5a8b788d8c0462e0e1d24dbaea8214c6/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6d617474686961736e6f6261636b2f73796d666f6e792d736572766963652d646566696e6974696f6e2d76616c696461746f722e706e67)](http://travis-ci.org/matthiasnoback/symfony-service-definition-validator)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/f8e6a4ee88f0a9a6e2fb28b652c2d1e755ec5b28903bfc47c8272a62597c52e7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d617474686961736e6f6261636b2f73796d666f6e792d736572766963652d646566696e6974696f6e2d76616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f733d63303466623461333466613564346332376631653465663064383739346330376233633430653931)](https://scrutinizer-ci.com/g/matthiasnoback/symfony-service-definition-validator/)[![Latest Stable Version](https://camo.githubusercontent.com/4d3089a641cdd11e6d97aea14441fc294382cb4efe7f7a5e6a1d24855a75d264/68747470733a2f2f706f7365722e707567782e6f72672f6d617474686961736e6f6261636b2f73796d666f6e792d736572766963652d646566696e6974696f6e2d76616c696461746f722f762f737461626c652e706e67)](https://packagist.org/packages/matthiasnoback/symfony-service-definition-validator)

Installation
------------

[](#installation)

Using Composer:

```
php composer.phar require matthiasnoback/symfony-service-definition-validator

```

Problems the validator can spot
-------------------------------

[](#problems-the-validator-can-spot)

Using the service definition validator in this library, the following service definition problems can be recognized:

- Non-existing classes
- Non-existing factory methods
- Method calls to non-existing methods
- Missing required arguments for constructors
- Non-public constructor methods
- Non-static factory methods
- Missing required arguments for method calls
- Type-hint mismatches for constructor arguments (array or class/interface)
- Type-hint mismatches for method call arguments (array or class/interface)
- Syntax errors in arguments that are [expressions](http://symfony.com/doc/current/book/service_container.html#using-the-expression-language)
- Expressions that cause errors when being evaluated

This will prevent lots of run-time problems, and will warn you about inconsistencies in your service definitions early on.

### Reporting false-negatives

[](#reporting-false-negatives)

I've tested the validator with the latest Symfony Standard Edition which has (of course) only valid service definitions. Please let me know if the validator fails inside your project when it should not have failed. When you report an issue, please attach a copy of the error message and the relevant lines in `app/cache/dev/appDevDebugProjectContainer.xml`.

Usage
-----

[](#usage)

If you have an existing Symfony application and you want to ensure that the service definitions are always valid the easiest way is to add the compiler pass to your bundle as described [here](https://github.com/matthiasnoback/symfony-service-definition-validator#compiler-pass). That will validate your service definitions every time the bundle is compiled, which happens every single request if the cache is turned off (the default in debug mode).

If you want to validate the service definitions in phpunit for a Symfony project follow the steps [here](https://github.com/matthiasnoback/symfony-service-definition-validator#running-the-validator-in-phpunit).

### Service validator factory

[](#service-validator-factory)

You can use the stand-alone validator for single definitions:

```
