1. Go to this page and download the library: Download spareparts/overseer 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/ */
spareparts / overseer example snippets
`
$assembly = new VotingAssembly(
$subjectName = 'article',
$actionName = 'read',
$strategy = StrategyEnum::FIRST_VOTE_DECIDES(),
$voters = [
new RoleVoter(VotingDecisionEnum::ALLOWED(), 'admin'),
new ClosureVoter(function (DummyArticle $article, IdentityContext $context) {
// allow the owner to edit
if ($subject->ownerId === $context->getId()) {
return new SingleVoterResult(VotingDecisionEnum::ALLOWED());
}
return null;
}),
new ClosureVoter(function (DummyArticle $article) {
// deny access if the article is banned
if ($subject->isBanned()) {
return new SingleVoterResult(VotingDecisionEnum::ALLOWED());
}
return null;
}),
new RoleVoter(VotingDecisionEnum::ALLOWED(), 'user'),
]
);
$authorizationManager = new GenericVotingManager([
// our article edit assembly
$assembly,
// other assemblies...
// ...
]);
$context = new IdentityContext($userId, $userRoles);
$authorized = $authorizationManager->vote('edit', $article, $context);
if ($authorized->getDecision() === VotingDecisionEnum::ALLOWED()) {
// we can edit!
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.