PHP code example of madlines / security-resolver-bundle
1. Go to this page and download the library: Download madlines/security-resolver-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/ */
madlines / security-resolver-bundle example snippets
public function registerBundles()
{
$bundles = [
// ...
new Madlines\SecurityResolverBundle\MadlinesSecurityResolverBundle(),
// ...
];
// ...
return $bundles;
}
class PostEditVoter
{
public function isGranted($user, $task)
{
// if (!($task instanceof PostEditTask)) {
if ($task !== 'post_edit') {
return null; // null means 'ignore'
// returning integer 0 means the same
}
if ($user->hasRole('ROLE_ADMIN')) {
return true; // agree
// returning integer 1 means the same
}
return false; // disagree
// returning integer -1 means the same
}
}
$isGranted = $this->get('madlines.security_resolver.access_resolver')->isGranted(
$this->getUser(),
'post_edit'
);
if (!$isGranted) {
throw new Symfony\Component\Security\Core\Exception\InsufficientAuthenticationException();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.