Scalr\Acl\Acl::hasAccessTo PHP Method

hasAccessTo() public method

Check whether the user has either READ or WRITE access to the specified object
public hasAccessTo ( object $object, User | integer $user, Environment | integer $enviroment = null, boolean $modify = null ) : boolean
$object object The object to check
$user Scalr\Model\Entity\Account\User | integer Either the User Entity or its identifier
$enviroment Scalr\Model\Entity\Account\Environment | integer optional Either the Environment Entity or its identifier
$modify boolean optional Whether it should check MODIFY permission. By default it checks READ permission.
return boolean Returns TRUE if the user has access to the specified object
    public function hasAccessTo($object, $user, $enviroment = null, $modify = null)
    {
        $modify = $modify ?: false;
        if (is_int($user)) {
            $user = Entity\Account\User::findPk($user);
        }
        if ($enviroment !== null && is_int($enviroment)) {
            $enviroment = Entity\Account\Environment::findPk($enviroment);
            if (!$enviroment) {
                throw new \InvalidArgumentException(sprintf("Could not find the Environment by id: %d", func_get_arg(2)));
            }
        }
        if (!$user instanceof Entity\Account\User) {
            throw new \InvalidArgumentException(sprintf('Second argument should be instance of \\Scalr\\Model\\Entity\\Account\\User class.'));
        }
        if ($enviroment !== null && !$enviroment instanceof Entity\Account\Environment) {
            throw new \InvalidArgumentException(sprintf('Third argument should be instance of \\Scalr\\Model\\Entity\\Account\\Environment class.'));
        }
        if (!is_object($object)) {
            throw new \InvalidArgumentException(sprintf("The first argument must be an object."));
        }
        if ($object instanceof AccessPermissionsInterface) {
            return $object->hasAccessPermissions($user, $enviroment, $modify);
        }
        throw new NotYetImplementedException(sprintf("%s nothing knows about %s class", __METHOD__, get_class($object)));
    }