Core/src/Iam/Iam.php
public function setPolicy($policy, array $options = [])
    {
        if ($policy instanceof PolicyBuilder) {
            $policy = $policy->result();
        }

        if (!is_array($policy)) {
            throw new \InvalidArgumentException('Given policy data must be an array or an instance of PolicyBuilder.');
        }

        $request = [];
        if ($this->options['parent']) {
            $parent = $this->options['parent'];
            $request[$parent] = $policy;
        } else {
            $request = $policy;
        }

        return $this->policy = $this->connection->setPolicy([
            'resource' => $this->resource
        ] + $request + $options + $this->options['args']);
    }
public function setPolicy($policy, array $options = [])
    {
        if ($policy instanceof PolicyBuilder) {
            $policy = $policy->result();
        }

        if (!is_array($policy)) {
            throw new \InvalidArgumentException('Given policy data must be an array or an instance of PolicyBuilder.');
        }

        $request = [];
        if ($this->options['parent']) {
            $parent = $this->options['parent'];
            $request[$parent] = $policy;
        } else {
            $request = $policy;
        }

        return $this->policy = $this->connection->setPolicy([
            'resource' => $this->resource
        ] + $request + $options + $this->options['args']);
    }
public function setPolicy ( $ policy , array $ options = [ ] ) { if ( $ policy instanceof PolicyBuilder ) { $ policy = $ policy -> result ( ) ; } if ( ! is_array ( $ policy ) ) { throw new \ InvalidArgumentException ( 'Given policy data must be an array or an instance of PolicyBuilder.' ) ; } $ request = [ ] ; if ( $ this -> options [ 'parent' ] ) { $ parent = $ this -> options [ 'parent' ] ; $ request [ $ parent ] = $ policy ; } else { $ request = $ policy ; } return $ this -> policy = $ this -> connection -> setPolicy ( [ 'resource' => $ this -> resource ] + $ request + $ options + $ this -> options [ 'args' ] ) ; }
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);
```

@param  array|PolicyBuilder $policy The new policy, as an array or an
instance of {@see Google\Cloud\Core\Iam\PolicyBuilder}.
@param  array $options Configuration Options
@return array An array of policy data
@throws \InvalidArgumentException If the given policy is not an array or PolicyBuilder.
Set the IAM policy for this resource .