1. Go to this page and download the library: Download ryanwhitman/php-values 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/ */
ryanwhitman / php-values example snippets
public function createUser(string $email)
{
// perform sanitation and validation on email before using
}
use RyanWhitman\PhpValues\Email;
public function createUser(Email $email)
{
// email has already been sanitized and validated and is ready for use
}
namespace App\Values;
use RyanWhitman\PhpValues\Value;
use RyanWhitman\PhpValues\Concerns\Stringable;
class Email extends Value
{
use Stringable;
protected function transform(string $email): string
{
return filter_var($email, FILTER_SANITIZE_EMAIL);
}
protected function validate(string $email): bool
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
}
protected function transform(string $email): string
{
return filter_var($email, FILTER_SANITIZE_EMAIL);
}
protected function validate(string $email): bool
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
namespace App\Values;
use RyanWhitman\PhpValues\SquishedString;
use RyanWhitman\PhpValues\Value;
class Name extends Value
{
protected array $baseValues = [
SquishedString::class,
];
// ...
}
Email::from('[email protected]'); // instance of Email
Email::from('non-email'); // throws InvalidValueException