Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Iam.
IAM Manager
This class is not meant to be used directly. It should be accessed
through other objects which support IAM.
Policies can be created using thePolicyBuilderto help ensure their validity.
Example:
// IAM policies are obtained via resources which implement IAM.
// In this example, we'll use PubSub topics to demonstrate
// how IAM policies are managed.
use Google\Cloud\Spanner\SpannerClient;
$spanner = new SpannerClient();
$instance = $spanner->instance('my-new-instance');
$iam = $instance->iam();
Namespace
Google \ Cloud \ Core \ Iam
Methods
__construct
Parameters
Name
Description
connection
IamConnectionInterface
resource
string
options
array
Configuration Options
↳ parent
string|null
The parent request parameter for the policy. If set, policy data will be sent asrequest.{$parent}. Otherwise, policy will be sent in request root.Defaults topolicy.
↳ args
array
Arbitrary data to be sent with the request.
policy
Get the existing IAM policy for this resource.
If a policy has already been retrieved from the API, it will be returned.
To fetch a fresh copy of the policy, useIam::reload().
Example:
$policy = $iam->policy();
Parameter
Name
Description
options
int
['requestedPolicyVersion'] Specify the policy version to
request from the server. Please seepolicy versioningfor more information.
Returns
Type
Description
array
An array of policy data
setPolicy
Set the IAM policy for this resource.
Bindings with invalid roles, or non-existent members will raise a server
error.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Iam (1.64.2)\n\nVersion latestkeyboard_arrow_down\n\n- [1.64.2 (latest)](/php/docs/reference/cloud-core/latest/Iam.Iam)\n- [1.64.1](/php/docs/reference/cloud-core/1.64.1/Iam.Iam)\n- [1.63.0](/php/docs/reference/cloud-core/1.63.0/Iam.Iam)\n- [1.62.3](/php/docs/reference/cloud-core/1.62.3/Iam.Iam)\n- [1.61.0](/php/docs/reference/cloud-core/1.61.0/Iam.Iam)\n- [1.60.1](/php/docs/reference/cloud-core/1.60.1/Iam.Iam)\n- [1.59.1](/php/docs/reference/cloud-core/1.59.1/Iam.Iam)\n- [1.58.2](/php/docs/reference/cloud-core/1.58.2/Iam.Iam)\n- [1.53.0](/php/docs/reference/cloud-core/1.53.0/Iam.Iam)\n- [1.52.11](/php/docs/reference/cloud-core/1.52.11/Iam.Iam)\n- [1.51.2](/php/docs/reference/cloud-core/1.51.2/Iam.Iam)\n- [1.50.0](/php/docs/reference/cloud-core/1.50.0/Iam.Iam)\n- [1.49.3](/php/docs/reference/cloud-core/1.49.3/Iam.Iam)\n- [1.48.1](/php/docs/reference/cloud-core/1.48.1/Iam.Iam) \nReference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Iam.\n\nIAM Manager\n\nThis class is not meant to be used directly. It should be accessed\nthrough other objects which support IAM.\n\nPolicies can be created using the [PolicyBuilder](/php/docs/reference/cloud-core/latest/Iam.PolicyBuilder)\nto help ensure their validity.\n\nExample: \n\n // IAM policies are obtained via resources which implement IAM.\n // In this example, we'll use PubSub topics to demonstrate\n // how IAM policies are managed.\n\n use Google\\Cloud\\Spanner\\SpannerClient;\n\n $spanner = new SpannerClient();\n $instance = $spanner-\u003einstance('my-new-instance');\n\n $iam = $instance-\u003eiam();\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Core \\\\ Iam\n\nMethods\n-------\n\n### __construct\n\n### policy\n\nGet the existing IAM policy for this resource.\n\nIf a policy has already been retrieved from the API, it will be returned.\nTo fetch a fresh copy of the policy, use\n[Iam::reload()](/php/docs/reference/cloud-core/latest/Iam.Iam#_Google_Cloud_Core_Iam_Iam__reload__).\n\nExample: \n\n $policy = $iam-\u003epolicy();\n\n### setPolicy\n\nSet the IAM policy for this resource.\n\nBindings with invalid roles, or non-existent members will raise a server\nerror.\n\nExample: \n\n $oldPolicy = $iam-\u003epolicy();\n $oldPolicy['bindings'][0]['members'] = 'user:test@example.com';\n\n $policy = $iam-\u003esetPolicy($oldPolicy);\n\n### testPermissions\n\nTest if the current user has the given permissions on this resource.\n\nInvalid permissions will raise a BadRequestException.\n\nExample: \n\n $allowedPermissions = $iam-\u003etestPermissions([\n 'pubsub.topics.publish',\n 'pubsub.topics.attachSubscription'\n ]);\n\n### reload\n\nRefresh the IAM policy for this resource.\n\nExample: \n\n $policy = $iam-\u003ereload();"]]