Skip to content

Commit 3bc9eef

Browse files
committed
Update readme
1 parent 11657d5 commit 3bc9eef

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ composer require cakephp/validation
244244
<?php
245245

246246
use Cake\Validation\Validator;
247-
use Selective\Validation\Exception\ValidationException;
248-
use Selective\Validation\Factory\CakeValidatorFactory;
247+
use Selective\Validation\Converter\CakeValidationConverter;
249248

250249
// Note: This is just an example. Don't use the $request object within the domain layer.
251250
$formData = (array)$request->getParsedBody();
@@ -260,7 +259,8 @@ $validator
260259
->requirePresence('comment')
261260
->notEmpty('comment', 'You need to give a comment.');
262261

263-
$validationResult = CakeValidatorFactory::createValidationResult($validator->validate($formData));
262+
// Convert Cake validator errors to ValidationResult
263+
$validationResult = CakeValidationConverter::createValidationResult($validator->validate($formData));
264264

265265
// Optional: Do more complex validation and append it to the validation result
266266
if ($this->existsUsername($formData['username'])) {
@@ -286,11 +286,10 @@ composer require symfony/validator
286286
<?php
287287

288288
use Cake\Validation\Validator;
289+
use Selective\Validation\Converter\SymfonyValidationConverter;
289290
use Selective\Validation\Exception\ValidationException;
290291
use Selective\Validation\Regex\ValidationRegex;
291-
use Selective\Validation\Factory\SymfonyValidatorFactory;
292292
use Symfony\Component\Validator\Constraints as Assert;
293-
use Symfony\Component\Validator\ConstraintViolation;
294293
use Symfony\Component\Validator\Validation;
295294

296295
// Note: This is just an example. Don't use the $request object within the domain layer.
@@ -334,8 +333,8 @@ $constraint = new Assert\Collection(
334333
$constraint->missingFieldsMessage = 'Input required';
335334
$violations = $validator->validate($formData, $constraint);
336335

337-
// Convert violations to ValidationResult
338-
$validationResult = SymfonyValidatorFactory::createValidationResult($violations);
336+
// Convert symfony violations to ValidationResult
337+
$validationResult = SymfonyValidationConverter::createValidationResult($violations);
339338

340339
// Optional: Do more complex validation and append it to the validation result
341340
if ($this->existsUsername($formData['username'])) {

0 commit comments

Comments
 (0)