Download the PHP package rimote/rimote-validation-bundle without Composer

On this page you can find all versions of the php package rimote/rimote-validation-bundle. 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 rimote-validation-bundle

RimoteValidationBundle

Extends and simplifies Symfony's Validator by providing a flat array with error messages.

Installation

Install using composer:

composer require rimote/rimote-validation-bundle

Edit /app/AppKernel.php and add the following bundle in the AppKernel::registerBundles() method inside the $bundles array:

new Rimote\ValidationBundle\RimoteValidationBundle()

How does it work?

Whenever you want to validate a Doctrine Entity in your Symfony codebase, instead of using Symfony's Validator component directly, you can use the RimoteValidationBundle's Validator instead.

The RimoteValidationBundle works nearly the same as Symfony's native Validator. Meaning you write your constraints straight into your Entity at the property level and then use the validator's validate() method to check if all property values are in the right format.

The difference is the format of the exception that will be thrown in case of validation errors. This will contain a getErrors() public method you can use to retrieve a flat key/value array of error messages. The keys will correspond with the Entity properties they relate to, the values will be the error messages as defined in your Entity.

Usage

First fetch an instance of the Rimote validator via the service container. Inside a container aware Controller, this can be accomplished like this:

$validator = $this->get('rimote.validator');

Now you can simply pass an instance of an Entity that needs to be validated to the validator's validate() method:

$validator->validate($cat);

If all is good this returns true. Otherwise an exception will be thrown, of the type Rimote\ValidationBundle\Validator\Exception\ErrorMessagesException. This exception has a public method called getErrors(), which produces a flat array with error messages, like so:

array(2) {
    'property_1' =>
    string(30) "This value should not be null."
    'property_2' =>
    string(30) "This value should not be null."
}

In the context of a REST API, this array of error messages can be returned as a JSON response with HTTP code 500. For a detailed example of such an implementation, see below.

Example

In this example we have an Doctrine Entity called Cat, which has three properties that shouldn't be blank: name, fur_type and gender:

Here's how we can validate this inside our CatsController::createAction (which uses the FOSRestBundle to set the POST body to an instance of Cat):

So what problem is actually solved?

Just consider the standard output from Symfony's Validator validate() method, using our above example, to make the practical use of the RimoteValidationBundle clear:

object(Symfony\Component\Validator\ConstraintViolationList)[545]
  private 'violations' => 
    array (size=2)
      0 => 
        object(Symfony\Component\Validator\ConstraintViolation)[546]
          private 'message' => string 'This value should not be null.' (length=30)
          private 'messageTemplate' => string 'This value should not be null.' (length=30)
          private 'parameters' => 
            array (size=1)
              ...
          private 'plural' => null
          private 'root' => 
            object(AppBundle\Entity\Cat)[451]
              ...
          private 'propertyPath' => string 'fur_type' (length=8)
          private 'invalidValue' => null
          private 'constraint' => 
            object(Symfony\Component\Validator\Constraints\NotNull)[455]
              ...
          private 'code' => string 'ad32d13f-c3d4-423b-909a-857b961eb720' (length=36)
          private 'cause' => null
      1 => 
        object(Symfony\Component\Validator\ConstraintViolation)[548]
          private 'message' => string 'This value should not be null.' (length=30)
          private 'messageTemplate' => string 'This value should not be null.' (length=30)
          private 'parameters' => 
            array (size=1)
              ...
          private 'plural' => null
          private 'root' => 
            object(AppBundle\Entity\Cat)[451]
              ...
          private 'propertyPath' => string 'gender' (length=6)
          private 'invalidValue' => null
          private 'constraint' => 
            object(Symfony\Component\Validator\Constraints\NotNull)[469]
              ...
          private 'code' => string 'ad32d13f-c3d4-423b-909a-857b961eb720' (length=36)
          private 'cause' => null

This instance of ConstraintViolationList can be preferable to a flat array of error messages. However, if such an array is required, it's necessary to iterate over the ConstraintViolationList, and use several getters such as getPropertyPath() and getMessage() to retrieve the information needed.

Naturally if you need to do this more than once you'd want a generic service to do this for you. In that case save yourself the hassle and use RimoteValidationBundle ;-).


All versions of rimote-validation-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
symfony/validator Version ~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 rimote/rimote-validation-bundle contains the following files

Loading the files please wait ....