1. Go to this page and download the library: Download hylianshield/validator 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/ */
use HylianShield\Validator\ValidatorInterface;
use Acme\User\UserManagerInterface;
$userValidator = new class($userManager) implements ValidatorInterface {
/**
* @var UserManagerInterface
*/
protected $userManager;
/**
* Initialize a new user validator.
*
* @param UserManagerInterface $userManager
*/*
public function __construct(UserManagerInterface $userManager)
{
$this->userManager = $userManager;
}
/**
* Get the identifier for the validator.
*
* @return string
*/
public function getIdentifier(): string
{
return 'user';
}
/**
* Validate the given subject.
*
* @param mixed $subject
* @return bool
*/
public function validate($subject): bool
{
return $this->userManager->contains($subject);
}
};
use HylianShield\Validator\Collection\MatchAllCollection;
use Acme\User\Role\RoleValidator;
use Acme\User\Role\AdminRole;
$adminValidator = new MatchAllCollection();
$adminValidator->addValidator($userValidator);
$adminValidator->addValidator(
new RoleValidator(AdminRole::IDENTIFIER)
);
$adminValidator->validate($nonexistentUser); // false
$adminValidator->validate($normalUser); // false
$adminValidator->validate($adminUser); // true
echo $adminValidator->getIdentifier(); // all(<user>, <role:admin>)
use HylianShield\Validator\Invoker;
$filtered = array_filter($input, new Invoker($validator));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.