From 328a019a782be9e9c70193671c7eb6999d8c0e35 Mon Sep 17 00:00:00 2001 From: zairig imad Date: Sun, 16 Sep 2018 11:46:58 +0200 Subject: [PATCH 1/5] Add New IsJson Validator Documentation --- reference/constraints.rst | 1 + reference/constraints/Json.rst | 100 ++++++++++++++++++++++++++++++ reference/constraints/map.rst.inc | 1 + 3 files changed, 102 insertions(+) create mode 100644 reference/constraints/Json.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index b64c8fbdbaa..d81a4eefd37 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -19,6 +19,7 @@ Validation Constraints Reference constraints/Regex constraints/Ip constraints/Uuid + constraints/Json constraints/EqualTo constraints/NotEqualTo diff --git a/reference/constraints/Json.rst b/reference/constraints/Json.rst new file mode 100644 index 00000000000..561b8efeb7b --- /dev/null +++ b/reference/constraints/Json.rst @@ -0,0 +1,100 @@ +Json +======= + +Validates that a value is a ``json``. Specifically, this checks to see if +the value is a valid ``json`` or not. + ++----------------+-----------------------------------------------------------------------+ +| Applies to | :ref:`property or method ` | ++----------------+-----------------------------------------------------------------------+ +| Options | - `message`_ | +| | - `payload`_ | ++----------------+-----------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Json` | ++----------------+-----------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\JsonValidator` | ++----------------+-----------------------------------------------------------------------+ + +Basic Usage +----------- + +The ``Json`` constraint can be applied to a property or a "getter" method, +but is most commonly useful in the latter case. For example, suppose that +you want to guarantee that some ``jsonString`` property is a valid ``json``. + +.. configuration-block:: + + .. code-block:: php-annotations + + // src/Entity/Book.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Book + { + /** + * @Assert\Json( + * message = "You've entered an invalid Json." + * ) + */ + protected $chapters; + } + + .. code-block:: yaml + + # config/validator/validation.yaml + App\Entity\Book: + properties: + chapters: + - Json: + message: You've entered an invalid Json. + + .. code-block:: xml + + + + + + + + + @@ -82,7 +81,7 @@ you want to guarantee that some ``jsonString`` property is a valid ``json``. public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('chapters', new Assert\Json(array( - 'message' => 'You've entered an invalid Json.', + 'message' => 'You\'ve entered an invalid Json.', ))); } } @@ -93,8 +92,8 @@ Options message ~~~~~~~ -**type**: ``string`` **default**: ``This value should be a valid json.`` +**type**: ``string`` **default**: ``This value should b valid JSON.`` -This message is shown if the underlying data is not a valid json. +This message is shown if the underlying data is not a valid JSON. .. include:: /reference/constraints/_payload-option.rst.inc From 98f8f77172ea3c675ea47a2758b729840b792631 Mon Sep 17 00:00:00 2001 From: Zairig Imad Date: Mon, 18 Feb 2019 15:55:44 +0100 Subject: [PATCH 3/5] Update Json.rst --- reference/constraints/Json.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/constraints/Json.rst b/reference/constraints/Json.rst index 6fa63f25cad..1ead1110d22 100644 --- a/reference/constraints/Json.rst +++ b/reference/constraints/Json.rst @@ -92,7 +92,7 @@ Options message ~~~~~~~ -**type**: ``string`` **default**: ``This value should b valid JSON.`` +**type**: ``string`` **default**: ``This value should be valid JSON.`` This message is shown if the underlying data is not a valid JSON. From 32222f1de798823fe7ed0aa27f88baa32049879f Mon Sep 17 00:00:00 2001 From: Zairig Imad Date: Sun, 3 Mar 2019 22:55:59 +0100 Subject: [PATCH 4/5] Update Json.rst --- reference/constraints/Json.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/constraints/Json.rst b/reference/constraints/Json.rst index 1ead1110d22..5a3e830e712 100644 --- a/reference/constraints/Json.rst +++ b/reference/constraints/Json.rst @@ -37,7 +37,7 @@ you want to guarantee that some ``jsonString`` property is valid JSON. * message = "You've entered an invalid Json." * ) */ - protected $chapters; + public $chapters; } .. code-block:: yaml @@ -76,7 +76,7 @@ you want to guarantee that some ``jsonString`` property is valid JSON. class Book { - protected $chapters; + public $chapters; public static function loadValidatorMetadata(ClassMetadata $metadata) { From 1250544e78667b2f9529a714264701789ee62db3 Mon Sep 17 00:00:00 2001 From: Zairig Imad Date: Sun, 3 Mar 2019 23:11:06 +0100 Subject: [PATCH 5/5] Update Json.rst --- reference/constraints/Json.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/constraints/Json.rst b/reference/constraints/Json.rst index 5a3e830e712..4b722ca1064 100644 --- a/reference/constraints/Json.rst +++ b/reference/constraints/Json.rst @@ -37,7 +37,7 @@ you want to guarantee that some ``jsonString`` property is valid JSON. * message = "You've entered an invalid Json." * ) */ - public $chapters; + private $chapters; } .. code-block:: yaml @@ -76,7 +76,7 @@ you want to guarantee that some ``jsonString`` property is valid JSON. class Book { - public $chapters; + private $chapters; public static function loadValidatorMetadata(ClassMetadata $metadata) {