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 'POST_EDIT': // logic to determine if the user can EDIT // return true or false break; case 'POST_VIEW': // logic to determine if the user can VIEW // return true or false break; } return false; } }