1. Go to this page and download the library: Download brzez/access-policy-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/ */
brzez / access-policy-bundle example snippets
// Will run canChangeStatus($something) on the policy
$this->can('change-status', $something);
// Will return negated canChangeStatus($something)
$this->cannot('change-status', $something);
use Brzez\AccessPolicyBundle\Service\AccessPolicyInterface;
class SomeEntityPolicy implements AccessPolicyInterface
{
public function canView(SomeEntity $entity)
{
// access logic here
return false;
}
}
use Brzez\AccessPolicyBundle\Traits\AccessCheckerTrait;
class DefaultController extends Controller
{
use AccessCheckerTrait;
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
// get $someObject from somewhere
...
if($this->cannot('view', $someObject)){
throw new AccessDeniedException('...');
}
// render view
...
}
}
php
is_a($object, $policy->getPoliciedClass());
php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new Brzez\AccessPolicyBundle\BrzezAccessPolicyBundle(),
//...
);
return $bundles;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.