Skip to content

Commit 5f91ecc

Browse files
committed
Drop support for symfony/validato
1 parent aa43f27 commit 5f91ecc

File tree

4 files changed

+1
-142
lines changed

4 files changed

+1
-142
lines changed

README.md

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -297,81 +297,6 @@ Please note: The `CakeValidationFactory` should be injected via constructor.
297297

298298
**Read more:** <https://odan.github.io/2020/10/18/slim4-cakephp-validation.html>
299299

300-
### Symfony Validator
301-
302-
**Installation**
303-
304-
```
305-
composer require symfony/validator
306-
```
307-
308-
**Usage**
309-
310-
```php
311-
<?php
312-
313-
use Selective\Validation\Converter\SymfonyValidationConverter;
314-
use Selective\Validation\Exception\ValidationException;
315-
use Selective\Validation\Regex\ValidationRegex;
316-
use Symfony\Component\Validator\Constraints as Assert;
317-
use Symfony\Component\Validator\Validation;
318-
319-
// Note: This is just an example. Don't use the $request object within the domain layer.
320-
$formData = (array)$request->getParsedBody();
321-
322-
// ...
323-
324-
// Create a Symfony validator instance
325-
$validator = Validation::createValidator();
326-
327-
// Add rules
328-
$constraint = new Assert\Collection(
329-
[
330-
'first_name' => new Assert\NotBlank(['message' => 'Input required']),
331-
'last_name' => new Assert\NotBlank(['message' => 'Input required']),
332-
'mobile' => new Assert\Optional(
333-
[
334-
new Assert\Regex(
335-
[
336-
'pattern' => ValidationRegex::PHONE_NUMBER,
337-
'message' => 'Invalid',
338-
]
339-
),
340-
]
341-
),
342-
'comment' => new Assert\Optional(
343-
[
344-
new Assert\Length(['max' => 255, 'maxMessage' => 'Too long']),
345-
]
346-
),
347-
'email' => new Assert\Optional(
348-
[
349-
new Assert\Email(
350-
[
351-
'message' => 'Invalid',
352-
]
353-
),
354-
]
355-
)
356-
]
357-
);
358-
359-
$constraint->missingFieldsMessage = 'Input required';
360-
$violations = $validator->validate($formData, $constraint);
361-
362-
// Convert symfony violations to ValidationResult
363-
$validationResult = SymfonyValidationConverter::createValidationResult($violations);
364-
365-
// Optional: Do more complex validation and append it to the validation result
366-
if ($this->existsUsername($formData['username'])) {
367-
$validationResult->addError('username', 'Username is already taken');
368-
}
369-
370-
if ($validationResult->fails()) {
371-
throw new ValidationException('Please check your input', $validationResult);
372-
}
373-
```
374-
375300
## Transformer
376301

377302
If you want to implement a custom response data structure,

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
"phpunit/phpunit": "^8 || ^9",
2727
"relay/relay": "^2.0",
2828
"slim/psr7": "^1",
29-
"squizlabs/php_codesniffer": "^3.5",
30-
"symfony/validator": "^5.1"
29+
"squizlabs/php_codesniffer": "^3.5"
3130
},
3231
"scripts": {
3332
"check": [

src/Converter/SymfonyValidationConverter.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/Converter/SymfonyValidationConverterTest.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)