src/Voter/WorkSheetVoter.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  4.  * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
  5.  */
  6. namespace App\Voter;
  7. use App\Entity\WorkSheet;
  8. use App\Entity\WorksheetKlasifikasi;
  9. use Kematjaya\SecurityAnnotationBundle\Voter\BaseVoter;
  10. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  11. /**
  12.  * Description of WorkSheetVoter
  13.  *
  14.  * @author programmer
  15.  */
  16. class WorkSheetVoter extends BaseVoter 
  17. {
  18.     const KMJ_ACCESS_ADD 'add_worksheet';
  19.     const VIEW_ATTRIBUTE 'view_attribute_worksheet';
  20.     
  21.     protected function arrayAccess(): array 
  22.     {
  23.         return array_merge([self::KMJ_ACCESS_ADDself::VIEW_ATTRIBUTE], parent::arrayAccess());
  24.     }
  25.     
  26.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool 
  27.     {
  28.         if (!$subject instanceof WorkSheet) {
  29.             return false;
  30.         }
  31.         
  32.         if (self::KMJ_ACCESS_ADD === $attribute) {
  33.             try {
  34.                 $subject->getValueClass();
  35.             } catch (\Exception $ex) {
  36.                 return false;
  37.             }
  38.         }
  39.         
  40.         if (self::VIEW_ATTRIBUTE === $attribute) {
  41.             
  42.             return $subject instanceof WorksheetKlasifikasi;
  43.         }
  44.         
  45.         return true;
  46.     }
  47. }