Get more validation constraints !, (*1)
Installation
Step 1: Download the bundle using composer, (*2)
Add the bundle by running:, (*3)
``` bash
composer require zzortell/zz-validation-extra-bundle, (*4)
**Step 2: Enable the bundle**
``` php
<?php
// app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Zz\ValidationExtraBundle\ZzValidationExtraBundle(),
// ...
);
}
}
Step 3: Enjoy !, (*5)
Usage
The Color
constraint
Use the Color
constraint like any validation constraint of the symfony/Validator component.
For example, with annotations:
``` php
<?php, (*6)
use Zz\ValidationExtraBundle\Validator\Constraints as Extras;, (*7)
class MyClass
{
/**
* Simple usage:
* @Extras\Color
*/
protected $color = '#222a6e';, (*8)
/**
* 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';
}
```, (*9)
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., (*10)
You can also use the following constraints, inheriting of Color
:
- HexColor
- NameColor
- CssNameColor
- HtmlNameColor
, (*11)
For these constraints, message
is the default option., (*12)
Don't hesitate to have a look on Validator/Constraints
., (*13)
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., (*14)
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, (*15)
In the 1.1
branch:
- Add a color format convertor ?, (*16)
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., (*17)
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., (*18)
License
This bundle is under the MIT license. See the complete license in the bundle:, (*19)
Resources/meta/LICENSE
A part of this bundle comes from ollieLtd/OhColorPickerTypeBundle. Please see this notice:, (*20)
Resources/meta/NOTICE.md