zzortell/zz-validation-extra-bundle

Provides a set of extras validation constraints.

v1.0.2 2015-01-12 17:48 UTC

This package is not auto-updated.

Last update: 2024-12-21 18:52:29 UTC


README

Get more validation constraints !

Installation

Step 1: Download the bundle using composer

Add the bundle by running:

composer require zzortell/zz-validation-extra-bundle

Step 2: Enable the bundle

<?php
// app/AppKernel.php

class AppKernel extends Kernel
{
	public function registerBundles()
	{
		$bundles = array(
			// ...
            new Zz\ValidationExtraBundle\ZzValidationExtraBundle(),
			// ...
		);
	}
}

Step 3: Enjoy !

Usage

The Color constraint

Use the Color constraint like any validation constraint of the symfony/Validator component. For example, with annotations:

<?php

use Zz\ValidationExtraBundle\Validator\Constraints as Extras;

class MyClass
{
	/**
	 * Simple usage:
	 * @Extras\Color
	 */
	protected $color = '#222a6e';
	
	/**
	 * All options with theirs default values:
	 * @Extras\Color(formats="All", message="The color supplied (%color%) is invalid (for formats: %formats%).", requireHash=true)
	 */
	protected $color = '#222a6e';
	
	/**
	 * Complex usage:
	 * @Extras\Color({"hex", "cssname"}, requireHash=false)
	 */
	protected $color = '#222a6e';
}

Properties:

  • formats: is the default option. It can be a string or an array of strings. Values: "All" (string only), "Hex", "Name" ("HtmlName"+CssName""), "HtmlName", CssName"".
  • message: Available variables: %color%, %formats%.
  • requireHash: for hex colors. Values: null (doesn't worry) or boolean.

You can also use the following constraints, inheriting of Color:

  • HexColor
  • NameColor
  • CssNameColor
  • HtmlNameColor

For these constraints, message is the default option.

Don't hesitate to have a look on Validator/Constraints.

Notice

If you don't want to get future features and just use colors constraints, require only 1.0.* versions. Every future features will increment the minor number.

Todo

In the 1.0 branch:

  • Use services' tag system instead of keeping in memory the formats in Validator/Constraints/ColorValidator.php
  • Add the support of rgb, rgba, hsl, hsla formats
  • Add a webSafe property

In the 1.1 branch:

  • Add a color format convertor ?

Contributing

If you have any idea for improving the bundle or if you find a bug, please post an issue. If you want to help me, especially for correcting my english, please don't hesitate.

Credits

This bundle his inspired by the ollietb's HexColor constraint and his validator.

  • Rémi Blaise (Zzortell) as the author.
  • Ollie Harridge (olliet) for original HexColor constraint.

License

This bundle is under the MIT license. See the complete license in the bundle:

Resources/meta/LICENSE

A part of this bundle comes from ollieLtd/OhColorPickerTypeBundle. Please see this notice:

Resources/meta/NOTICE.md