<?php
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
*/
namespace App\Voter;
use App\Entity\WorkSheet;
use App\Entity\WorksheetKlasifikasi;
use Kematjaya\SecurityAnnotationBundle\Voter\BaseVoter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
/**
* Description of WorkSheetVoter
*
* @author programmer
*/
class WorkSheetVoter extends BaseVoter
{
const KMJ_ACCESS_ADD = 'add_worksheet';
const VIEW_ATTRIBUTE = 'view_attribute_worksheet';
protected function arrayAccess(): array
{
return array_merge([self::KMJ_ACCESS_ADD, self::VIEW_ATTRIBUTE], parent::arrayAccess());
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if (!$subject instanceof WorkSheet) {
return false;
}
if (self::KMJ_ACCESS_ADD === $attribute) {
try {
$subject->getValueClass();
} catch (\Exception $ex) {
return false;
}
}
if (self::VIEW_ATTRIBUTE === $attribute) {
return $subject instanceof WorksheetKlasifikasi;
}
return true;
}
}