Search
 
SCRIPT & CODE EXAMPLE
 

PHP

assert symfony

<?php

require_once '../vendor/autoload.php';

use SymfonyComponentValidatorConstraints as Assert;
use SymfonyComponentValidatorValidation;

$validator = Validation::createValidator();

$input = [
    //'name' => [],
];

$notNestedConstraint = new AssertCollection(
    [
        'first_name' => new AssertRequired(),
        'last_name' => new AssertRequired(),
    ],
);
$nestedConstraint = new AssertCollection(
    [
        'name' => $notNestedConstraint,
    ]
);

$items = [];
$constraint = (array_key_exists('name', $input)) ? $nestedConstraint: $notNestedConstraint

$violations = $validator->validate($input, $constraint);
foreach ($violations as $violation) {
    $items[] = [
        'path' => $violation->getPropertyPath(),
        'message' => $violation->getMessage(),
    ];
}

var_dump($items);
Comment

PREVIOUS NEXT
Code Example
Php :: magento Fatal error: Allowed memory size of 134217728 bytes exhausted 
Php :: Make livewire component 
Php :: laravel enable query log 
Php :: php vs python speed 
Php :: laravel call a static function 
Php :: how to separate admin and user login in laravel 
Php :: view blade not found in laravel 
Php :: laravel mail 
Php :: php session 
Php :: sass for php 
Php :: $session php 
Php :: laravel eloquent relationships 
Php :: laravel relationship 
Php :: if one condition 
Php :: laravel validation rule 
Php :: php get constant value 
Php :: php data types 
Php :: laravel + join 2 eloquent queries 
Php :: different between two dates 
Php :: laravel imap - Set message flags 
Php :: findOneBy 
Php :: seguridad de las api en laravel 
Php :: menyimpan get di laravel 
Php :: slim disable display error details 
Php :: Laravel storage goes to 404 page. (Symlink not working) 
Php :: custom end-point request php-salesforce-rest-api 
Php :: spatie/laravel-health 
Php :: auto complete order paid3 
Php :: pregmatch 
Php :: laravel gigapay update invoice 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =