initial commit
This commit is contained in:
43
vendor/symfony/maker-bundle/templates/security/Voter.tpl.php
vendored
Normal file
43
vendor/symfony/maker-bundle/templates/security/Voter.tpl.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?= "<?php\n" ?>
|
||||
|
||||
namespace <?= $class_data->getNamespace(); ?>;
|
||||
|
||||
<?= $class_data->getUseStatements(); ?>
|
||||
|
||||
<?= $class_data->getClassDeclaration() ?>
|
||||
|
||||
{
|
||||
public const EDIT = 'POST_EDIT';
|
||||
public const VIEW = 'POST_VIEW';
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
{
|
||||
// replace with your own logic
|
||||
// https://symfony.com/doc/current/security/voters.html
|
||||
return in_array($attribute, [self::EDIT, self::VIEW])
|
||||
&& $subject instanceof \App\Entity\<?= str_replace('Voter', null, $class_data->getClassName()) ?>;
|
||||
}
|
||||
|
||||
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
|
||||
{
|
||||
$user = $token->getUser();
|
||||
// if the user is anonymous, do not grant access
|
||||
if (!$user instanceof UserInterface) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ... (check conditions and return true to grant permission) ...
|
||||
switch ($attribute) {
|
||||
case self::EDIT:
|
||||
// logic to determine if the user can EDIT
|
||||
// return true or false
|
||||
break;
|
||||
case self::VIEW:
|
||||
// logic to determine if the user can VIEW
|
||||
// return true or false
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user