for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Boris Guéry <[email protected]>
*/
namespace Bgy\OAuth2\GrantType;
use Bgy\OAuth2\ResourceOwner;
use Bgy\OAuth2\Utils\Ensure;
final class GrantDecision
{
const ALLOWED = 'allowed';
const DENIED = 'denied';
private $decision;
* @var ResourceOwner
private $resourceOwner;
* @var GrantError
private $error;
private function __construct() {}
public static function denied(GrantError $error)
$d = new self();
$d->decision = self::DENIED;
$d->error = $error;
return $d;
}
public static function allowed(ResourceOwner $resourceOwner = null)
$d->decision = self::ALLOWED;
$d->resourceOwner = $resourceOwner;
$d->error = GrantError::none();
public function getResourceOwner()
return $this->resourceOwner;
public function getError()
return $this->error;
public function isAllowed()
return $this->decision === self::ALLOWED;
public function isDenied()
return $this->decision === self::DENIED;
public function __toString()
return $this->decision;
public function equals(GrantDecision $decision)
return $this->decision === $decision->decision;