# Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Iam (1.72.2)

1.72.2 (latest) 1.72.1 1.71.2 1.70.0 1.69.0 1.68.2 1.67.0 1.66.0 1.65.0 1.64.3 1.63.0 1.62.3 1.61.0 1.60.1 1.59.1 1.58.2 1.53.0 1.52.11 1.51.2 1.50.0 1.49.3 1.48.1 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 the [PolicyBuilder](https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iam.PolicyBuilder)
to 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(['projectId' => 'my-project']);
    $instance = $spanner->instance('my-new-instance');

    $iam = $instance->iam();

## Namespace

Google \\ Cloud \\ Core \\ Iam

## Methods

### __construct

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `connection` | `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iam.IamConnectionInterface` |
| `resource` | `string` |
| `options` | `array` Configuration Options |
| `↳ parent` | `string|null` The parent request parameter for the policy. If set, policy data will be sent as `request.{$parent}`. Otherwise, policy will be sent in request root. **Defaults to** `policy`. |
| `↳ 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, use
[Iam::reload()](https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iam.Iam#_Google_Cloud_Core_Iam_Iam__reload__).

Example:

    $policy = $iam->policy();

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `int` \['requestedPolicyVersion'\] Specify the policy version to request from the server. Please see [policy versioning](https://cloud.google.com/iam/docs/policies#versions) for 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.

Example:

    $oldPolicy = $iam->policy();
    $oldPolicy['bindings'][0]['members'] = 'user:test@example.com';

    $policy = $iam->setPolicy($oldPolicy);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `policy` | `array|https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iam.PolicyBuilder` The new policy, as an array or an instance of [PolicyBuilder](https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iam.PolicyBuilder). |
| `options` | `array` Configuration Options |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` | An array of policy data |

### testPermissions

Test if the current user has the given permissions on this resource.

Invalid permissions will raise a BadRequestException.

Example:

    $allowedPermissions = $iam->testPermissions([
        'pubsub.topics.publish',
        'pubsub.topics.attachSubscription'
    ]);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `permissions` | `array` A list of permissions to test |
| `options` | `array` Configuration Options |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` | A subset of $permissions, with only those allowed included. |

### reload

Refresh the IAM policy for this resource.

Example:

    $policy = $iam->reload();

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration Options |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` | An array of policy data |