PHP code example of danilovl / select-autocompleter-bundle
1. Go to this page and download the library: Download danilovl/select-autocompleter-bundle 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/ */
danilovl / select-autocompleter-bundle example snippets
declare(strict_types=1);
namespace App\Security\Voter;
use Danilovl\SelectAutocompleterBundle\Constant\VoterSupportConstant;
use Danilovl\SelectAutocompleterBundle\Interfaces\AutocompleterInterface;
use LogicException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Bundle\SecurityBundle\Security;
class CustomAutocompleterVoter extends Voter
{
private const SUPPORTS = [
VoterSupportConstant::GET_RESULT
];
private Security $security;
public function __construct(Security $security)
{
$this->security = $security;
}
protected function supports(string $attribute, mixed $subject): bool
{
if (!in_array($attribute, self::SUPPORTS, true)) {
return false;
}
if (!$subject instanceof AutocompleterInterface) {
return false;
}
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
if ($attribute !== VoterSupportConstant::GET_DATA) {
throw new LogicException('This code should not be reached!');
}
// custom logic
return true;
}
}
declare(strict_types=1);
namespace App\Autocompleter;
use Danilovl\SelectAutocompleterBundle\Model\Autocompleter\AutocompleterQuery;
use Danilovl\SelectAutocompleterBundle\Model\SelectDataFormat\Item;
use Danilovl\SelectAutocompleterBundle\Resolver\Config\AutocompleterConfigResolver;
use Danilovl\SelectAutocompleterBundle\Service\OrmAutocompleter;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
class CustomShopAutocompleter extends OrmAutocompleter
{
private ShopRepository $shopRepository;
public function __construct(
ManagerRegistry $registry,
AutocompleterConfigResolver $resolver,
ShopRepository $shopRepository
) {
parent::__construct($registry, $resolver);
$this->shopRepository = $shopRepository;
}
public function isGranted(): int
{
return VoterInterface::ACCESS_ABSTAIN;
}
}