Symfony
gobelins
composer require symfony/validator doctrine/annotations
class NotBlank extends Constraint
{
const IS_BLANK_ERROR = 'c1051bb4-d103-4f74-8988-acbcafc7fdc3';
protected static $errorNames = [
self::IS_BLANK_ERROR => 'IS_BLANK_ERROR',
];
public $message = 'This value should not be blank.';
public $allowNull = false;
}
Ci-dessus un exemple de contrainte native. Il est possible de la modifier, notament pour customiser le message d'erreur de la contrainte.
// src/Entity/Author.php
namespace App\Entity;
// ...
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\NotBlank
*/
private $name;
}
// src/Entity/Author.php
namespace App\Entity;
// ...
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Choice(
* choices = { "fiction", "non-fiction" },
* message = "Choose a valid genre."
* )
*/
private $genre;
// ...
}
# config/validator/validation.yaml
App\Entity\Author:
properties:
name:
- NotBlank: ~
// ...
use App\Entity\Author;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
// ...
public function author(ValidatorInterface $validator)
{
$author = new Author();
$errors = $validator->validate($author);
if (count($errors) > 0) {
$errorsString = (string) $errors;
return new Response($errorsString);
}
return new Response('The author is valid! Yes!');
}
Permissions Garantir la vie privée des utilisateurs Transparence Restriction des données Restriction d'accès Permissions normales Non dangereuses
Mar 2, 2021Programmation multi thread Les instructions exécutées dans un programme sont dans 1 thread Généralement, les instructions s'éxecutent de manière séquentielle On peut éxecuter plusieurs instructions parallèlement dans un multi thread Exécution synchrone Instructions éxecutées séquentiellement Exécution asynchrone
Mar 1, 2021Définition Ensemble de propriétés / attributs pour modéliser un objet // Exemple de classe très simple et son instanciation class Etudiant(val name: String) val etu = Etudiant("Valentin") println(etu.name) // Valentin Héritage open class Person(open val nom: String)
Feb 19, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up