Download the PHP package matthiasnoback/symfony-service-definition-validator without Composer

On this page you can find all versions of the php package matthiasnoback/symfony-service-definition-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package symfony-service-definition-validator

Symfony Service Definition Validator

By Matthias Noback

Build Status Scrutinizer Quality Score Latest Stable Version

Installation

Using Composer:

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

Problems the validator can spot

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

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

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

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. 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.

Service validator factory

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

To process multiple definitions at once, wrap the validator inside a batch validator:

The resulting error list will contain errors about problematic service definitions.

Compiler pass

To check for the validity of all your service definitions at compile time, add the ValidateServiceDefinitionsPass compiler pass to the ContainerBuilder instance:

This compiler pass will throw an exception. The message of this exception will contain a list of invalid service definitions.

Running the validator in PHPUnit

In Symfony, adding the compiler pass will validate your services each time the page is loaded in your browser or when you use a command. But what if you want to run the validator on demand using PHPUnit? To do this, first set up the compiler pass as explained above and then create a new PHPUnit test with this inside:

This simple functional test just boots up the symfony kernel using the "test" environment. If you look back to the code you added to set up the compiler pass you'll see that we enabled the validator for the "test" environment too. So this simple PHPUnit test will validate the services each time it is run.

In fact, if you already have functional tests you don't need this test, since the kernel will be booted (and therefore the services will be validated) in the other functional tests. The example test above is only needed if you don't already have any Symfony functional tests of your application.

Configure the validator

Both ValidateServiceDefinitionsPass and ServiceDefinitionValidatorFactory accept a Configuration object. It allows you to configure whether or not expression arguments should be evaluated. Since evaluating expressions can cause all kinds of runtime errors, it is off by default, but you can easily turn it on:

Fixing invalid service definitions in third-party bundles

When the validator finds a problem with one of the service definitions that is your own, you can of course fix the problem yourself, but when the invalid service definition is defined in some other bundle, you can still fix problems by dynamically modifying the service definition. First you need to create a compiler pass:

After you have selected the invalid service definition, you can modify it in any way you like. For a list of everything you can do with Definition objects, see http://symfony.com/doc/master/components/dependency_injection/definitions.html.

Don't forget to register the compiler pass in your bundle class:


All versions of symfony-service-definition-validator with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4
symfony/dependency-injection Version ~2.0|~3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package matthiasnoback/symfony-service-definition-validator contains the following files

Loading the files please wait ....