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)));
}