1. Go to this page and download the library: Download knplabs/rad-security 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/ */
namespace App\Model;
use Knp\Rad\Security\OwnerInterface;
class User implements OwnerInterface
{
}
namespace App\Model;
use Knp\Rad\Security\OwnableInterface;
use App\Model\User;
class Book implements OwnableInterface
{
/** @var App\Model\User */
protected $writtenBy;
public function __construct(User $writtenBy)
{
$this->writtenBy = $writtenBy;
}
public function getOwner()
{
return $this->writtenBy;
}
}
$zola = new \App\Model\User(); // He is the current authenticated user
$hugo = new \App\Model\User();
$germinal = new \App\Model\Book($zola);
$miserables = new \App\Model\Book($hugo);
$authorizationChecker = $container->get(/* ... */);
$authorizationChecker->isGranted(array('IS_OWNER'), $germinal); // true
$authorizationChecker->isGranted(array('IS_OWNER'), $miserables); // false
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.