PHP code example of joipolloi / json-validation-bundle
1. Go to this page and download the library: Download joipolloi/json-validation-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joipolloi / json-validation-bundle example snippets
use JoiPolloi\Bundle\JsonValidationBundle\Annotation\ValidateJson
class MyController
{
/**
* @ValidateJson("@MyBundle/Resources/schema/action-schema.json")
*/
public function myAction()
{
// ...
}
}
$bundles = array(
// ...
new JoiPolloi\Bundle\JsonValidationBundle\JsonValidationBundle(),
// ...
);
/**
* @ValidateJson("@MyBundle/Resources/schema/action-schema.json")
*/
public function myAction(Request $request, $validJson)
{
// $request->attributes->get('validJson') === $validJson
}
/**
* @ValidateJson("@MyBundle/Resources/schema/action-schema.json")
*/
public function myAction(array $validJson)
{
$form = $this->createForm(MyFormType::class);
$form->submit($validJson);
if ($form->isValid()) {
// ...
}
}
public function myAction($validJson)
{
// ...
$form->submit((array)$validJson);
}
/**
* @ValidateJson("@MyBundle/Resources/schema/action-schema.json", methods={"POST"})
*/
public function myAction(Request $request, $validJson = null)
{
if ($request->isMethod('POST')) {
// $validJson !== null
}
}
/**
* @ValidateJson("@MyBundle/Resources/schema/action-schema.json", emptyIsValid=true)
*/
public function myAction($validJson = null)
{
// ...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.