Google Cloud Resource Manager V3 Client - Class ProjectsClient (0.8.5)

Reference documentation and code samples for the Google Cloud Resource Manager V3 Client class ProjectsClient.

Service Description: Manages Google Cloud Projects.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Cloud \ ResourceManager \ V3 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

createProject

Request that a new project be created. The result is an Operation which can be used to track the creation process. This process usually takes a few seconds, but can sometimes take much longer. The tracking Operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::createProjectAsync() .

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\CreateProjectRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;
use Google\Cloud\ResourceManager\V3\CreateProjectRequest;
use Google\Cloud\ResourceManager\V3\Project;
use Google\Rpc\Status;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function create_project_sample(): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $project = new Project();
    $request = (new CreateProjectRequest())
        ->setProject($project);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $projectsClient->createProject($request);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Project $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

deleteProject

Marks the project identified by the specified name (for example, projects/415104041262) for deletion.

This method will only affect the project if it has a lifecycle state of ACTIVE.

This method changes the Project's lifecycle state from ACTIVE to DELETE_REQUESTED. The deletion starts at an unspecified time, at which point the Project is no longer accessible.

Until the deletion completes, you can check the lifecycle state checked by retrieving the project with GetProject, and the project remains visible to ListProjects. However, you cannot update the project.

After the deletion completes, the project is not retrievable by the GetProject, ListProjects, and SearchProjects methods.

This method behaves idempotently, such that deleting a DELETE_REQUESTED project will not cause an error, but also won't do anything.

The caller must have resourcemanager.projects.delete permissions for this project.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::deleteProjectAsync() .

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\DeleteProjectRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;
use Google\Cloud\ResourceManager\V3\DeleteProjectRequest;
use Google\Cloud\ResourceManager\V3\Project;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the Project (for example, `projects/415104041262`). Please see
 *                              {@see ProjectsClient::projectName()} for help formatting this field.
 */
function delete_project_sample(string $formattedName): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $request = (new DeleteProjectRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $projectsClient->deleteProject($request);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Project $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ProjectsClient::projectName('[PROJECT]');

    delete_project_sample($formattedName);
}

getIamPolicy

Returns the IAM access control policy for the specified project, in the format projects/{ProjectIdOrNumber} e.g. projects/123.

Permission is denied if the policy or the resource do not exist.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::getIamPolicyAsync() .

Parameters
Name Description
request Google\Cloud\Iam\V1\GetIamPolicyRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Iam\V1\Policy
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Iam\V1\GetIamPolicyRequest;
use Google\Cloud\Iam\V1\Policy;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;

/**
 * @param string $resource REQUIRED: The resource for which the policy is being requested.
 *                         See the operation documentation for the appropriate value for this field.
 */
function get_iam_policy_sample(string $resource): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $request = (new GetIamPolicyRequest())
        ->setResource($resource);

    // Call the API and handle any network failures.
    try {
        /** @var Policy $response */
        $response = $projectsClient->getIamPolicy($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $resource = '[RESOURCE]';

    get_iam_policy_sample($resource);
}

getProject

Retrieves the project identified by the specified name (for example, projects/415104041262).

The caller must have resourcemanager.projects.get permission for this project.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::getProjectAsync() .

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\GetProjectRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\ResourceManager\V3\Project
Example
use Google\ApiCore\ApiException;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;
use Google\Cloud\ResourceManager\V3\GetProjectRequest;
use Google\Cloud\ResourceManager\V3\Project;

/**
 * @param string $formattedName The name of the project (for example, `projects/415104041262`). Please see
 *                              {@see ProjectsClient::projectName()} for help formatting this field.
 */
function get_project_sample(string $formattedName): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $request = (new GetProjectRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Project $response */
        $response = $projectsClient->getProject($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ProjectsClient::projectName('[PROJECT]');

    get_project_sample($formattedName);
}

listProjects

Lists projects that are direct children of the specified folder or organization resource. list() provides a strongly consistent view of the projects underneath the specified parent resource. list() returns projects sorted based upon the (ascending) lexical ordering of their display_name. The caller must have resourcemanager.projects.list permission on the identified parent.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::listProjectsAsync() .

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\ListProjectsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;
use Google\Cloud\ResourceManager\V3\ListProjectsRequest;
use Google\Cloud\ResourceManager\V3\Project;

/**
 * @param string $parent The name of the parent resource whose projects are being listed.
 *                       Only children of this parent resource are listed; descendants are not
 *                       listed.
 *
 *                       If the parent is a folder, use the value `folders/{folder_id}`. If the
 *                       parent is an organization, use the value `organizations/{org_id}`.
 */
function list_projects_sample(string $parent): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $request = (new ListProjectsRequest())
        ->setParent($parent);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $projectsClient->listProjects($request);

        /** @var Project $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $parent = '[PARENT]';

    list_projects_sample($parent);
}

moveProject

Move a project to another place in your resource hierarchy, under a new resource parent.

Returns an operation which can be used to track the process of the project move workflow. Upon success, the Operation.response field will be populated with the moved project.

The caller must have resourcemanager.projects.move permission on the project, on the project's current and proposed new parent.

If project has no current parent, or it currently does not have an associated organization resource, you will also need the resourcemanager.projects.setIamPolicy permission in the project.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::moveProjectAsync() .

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\MoveProjectRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;
use Google\Cloud\ResourceManager\V3\MoveProjectRequest;
use Google\Cloud\ResourceManager\V3\Project;
use Google\Rpc\Status;

/**
 * @param string $formattedName     The name of the project to move. Please see
 *                                  {@see ProjectsClient::projectName()} for help formatting this field.
 * @param string $destinationParent The new parent to move the Project under.
 */
function move_project_sample(string $formattedName, string $destinationParent): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $request = (new MoveProjectRequest())
        ->setName($formattedName)
        ->setDestinationParent($destinationParent);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $projectsClient->moveProject($request);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Project $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ProjectsClient::projectName('[PROJECT]');
    $destinationParent = '[DESTINATION_PARENT]';

    move_project_sample($formattedName, $destinationParent);
}

searchProjects

Search for projects that the caller has both resourcemanager.projects.get permission on, and also satisfy the specified query.

This method returns projects in an unspecified order.

This method is eventually consistent with project mutations; this means that a newly created project may not appear in the results or recent updates to an existing project may not be reflected in the results. To retrieve the latest state of a project, use the GetProject method.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::searchProjectsAsync() .

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\SearchProjectsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;
use Google\Cloud\ResourceManager\V3\Project;
use Google\Cloud\ResourceManager\V3\SearchProjectsRequest;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function search_projects_sample(): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $request = new SearchProjectsRequest();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $projectsClient->searchProjects($request);

        /** @var Project $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

setIamPolicy

Sets the IAM access control policy for the specified project, in the format projects/{ProjectIdOrNumber} e.g. projects/123.

CAUTION: This method will replace the existing policy, and cannot be used to append additional IAM settings.

Note: Removing service accounts from policies or changing their roles can render services completely inoperable. It is important to understand how the service account is being used before removing or updating its roles.

The following constraints apply when using setIamPolicy():

  • Project does not support allUsers and allAuthenticatedUsers as members in a Binding of a Policy.

  • The owner role can be granted to a user, serviceAccount, or a group that is part of an organization. For example, group@myownpersonaldomain.com could be added as an owner to a project in the myownpersonaldomain.com organization, but not the examplepetstore.com organization.

  • Service accounts can be made owners of a project directly without any restrictions. However, to be added as an owner, a user must be invited using the Cloud Platform console and must accept the invitation.

  • A user cannot be granted the owner role using setIamPolicy(). The user must be granted the owner role using the Cloud Platform Console and must explicitly accept the invitation.

  • Invitations to grant the owner role cannot be sent using setIamPolicy(); they must be sent only using the Cloud Platform Console.

  • If the project is not part of an organization, there must be at least one owner who has accepted the Terms of Service (ToS) agreement in the policy. Calling setIamPolicy() to remove the last ToS-accepted owner from the policy will fail. This restriction also applies to legacy projects that no longer have owners who have accepted the ToS. Edits to IAM policies will be rejected until the lack of a ToS-accepting owner is rectified. If the project is part of an organization, you can remove all owners, potentially making the organization inaccessible.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::setIamPolicyAsync() .

Parameters
Name Description
request Google\Cloud\Iam\V1\SetIamPolicyRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Iam\V1\Policy
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Iam\V1\Policy;
use Google\Cloud\Iam\V1\SetIamPolicyRequest;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;

/**
 * @param string $resource REQUIRED: The resource for which the policy is being specified.
 *                         See the operation documentation for the appropriate value for this field.
 */
function set_iam_policy_sample(string $resource): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $policy = new Policy();
    $request = (new SetIamPolicyRequest())
        ->setResource($resource)
        ->setPolicy($policy);

    // Call the API and handle any network failures.
    try {
        /** @var Policy $response */
        $response = $projectsClient->setIamPolicy($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $resource = '[RESOURCE]';

    set_iam_policy_sample($resource);
}

testIamPermissions

Returns permissions that a caller has on the specified project, in the format projects/{ProjectIdOrNumber} e.g. projects/123..

The async variant is ProjectsClient::testIamPermissionsAsync() .

Parameters
Name Description
request Google\Cloud\Iam\V1\TestIamPermissionsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Iam\V1\TestIamPermissionsResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Iam\V1\TestIamPermissionsRequest;
use Google\Cloud\Iam\V1\TestIamPermissionsResponse;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;

/**
 * @param string $resource           REQUIRED: The resource for which the policy detail is being requested.
 *                                   See the operation documentation for the appropriate value for this field.
 * @param string $permissionsElement The set of permissions to check for the `resource`. Permissions with
 *                                   wildcards (such as '*' or 'storage.*') are not allowed. For more
 *                                   information see
 *                                   [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
 */
function test_iam_permissions_sample(string $resource, string $permissionsElement): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $permissions = [$permissionsElement,];
    $request = (new TestIamPermissionsRequest())
        ->setResource($resource)
        ->setPermissions($permissions);

    // Call the API and handle any network failures.
    try {
        /** @var TestIamPermissionsResponse $response */
        $response = $projectsClient->testIamPermissions($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $resource = '[RESOURCE]';
    $permissionsElement = '[PERMISSIONS]';

    test_iam_permissions_sample($resource, $permissionsElement);
}

undeleteProject

Restores the project identified by the specified name (for example, projects/415104041262).

You can only use this method for a project that has a lifecycle state of DELETE_REQUESTED. After deletion starts, the project cannot be restored.

The caller must have resourcemanager.projects.undelete permission for this project.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::undeleteProjectAsync() .

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\UndeleteProjectRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;
use Google\Cloud\ResourceManager\V3\Project;
use Google\Cloud\ResourceManager\V3\UndeleteProjectRequest;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the project (for example, `projects/415104041262`).
 *
 *                              Please see
 *                              {@see ProjectsClient::projectName()} for help formatting this field.
 */
function undelete_project_sample(string $formattedName): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $request = (new UndeleteProjectRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $projectsClient->undeleteProject($request);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Project $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ProjectsClient::projectName('[PROJECT]');

    undelete_project_sample($formattedName);
}

updateProject

Updates the display_name and labels of the project identified by the specified name (for example, projects/415104041262). Deleting all labels requires an update mask for labels field.

The caller must have resourcemanager.projects.update permission for this project.

The async variant is Google\Cloud\ResourceManager\V3\Client\ProjectsClient::updateProjectAsync() .

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\UpdateProjectRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\ResourceManager\V3\Client\ProjectsClient;
use Google\Cloud\ResourceManager\V3\Project;
use Google\Cloud\ResourceManager\V3\UpdateProjectRequest;
use Google\Rpc\Status;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_project_sample(): void
{
    // Create a client.
    $projectsClient = new ProjectsClient();

    // Prepare the request message.
    $project = new Project();
    $request = (new UpdateProjectRequest())
        ->setProject($project);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $projectsClient->updateProject($request);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Project $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

createProjectAsync

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\CreateProjectRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

deleteProjectAsync

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\DeleteProjectRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getIamPolicyAsync

Parameters
Name Description
request Google\Cloud\Iam\V1\GetIamPolicyRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getProjectAsync

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\GetProjectRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listProjectsAsync

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\ListProjectsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

moveProjectAsync

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\MoveProjectRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

searchProjectsAsync

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\SearchProjectsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

setIamPolicyAsync

Parameters
Name Description
request Google\Cloud\Iam\V1\SetIamPolicyRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

testIamPermissionsAsync

Parameters
Name Description
request Google\Cloud\Iam\V1\TestIamPermissionsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

undeleteProjectAsync

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\UndeleteProjectRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateProjectAsync

Parameters
Name Description
request Google\Cloud\ResourceManager\V3\UpdateProjectRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getOperationsClient

Return an OperationsClient object with the same endpoint as $this.

Returns
Type Description
Google\ApiCore\LongRunning\OperationsClient

resumeOperation

Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.

Parameters
Name Description
operationName string

The name of the long running operation

methodName string

The name of the method used to start the operation

Returns
Type Description
Google\ApiCore\OperationResponse

static::projectName

Formats a string containing the fully-qualified path to represent a project resource.

Parameter
Name Description
project string
Returns
Type Description
string The formatted project resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • project: projects/{project}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name Description
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
Type Description
array An associative array from name component IDs to component values.