1. Go to this page and download the library: Download switon/validation 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/ */
switon / validation example snippets
use Switon\Core\Attribute\Autowired;
use Switon\Validating\Attribute\ArrayOf;
use Switon\Validating\Attribute\Email;
use Switon\Validating\Attribute\Length;
use Switon\Validating\Attribute\Required;
use Switon\Validating\ValidatorInterface;
class UserService
{
#[Autowired] protected ValidatorInterface $validator;
public function register(array $input): array
{
return $this->validator->validateValues($input, [
'tags' => [new ArrayOf('string', minItems: 1)],
'username' => [new Required(), new Length(4, 16)],
'email' => [new Required(), new Email()],
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.