# Cloud PubSub Client - Class Schema (2.19.3)

2.19.3 (latest) 2.19.2 2.18.0 2.17.0 2.16.2 2.15.1 2.14.0 2.13.2 2.12.0 2.11.3 2.10.1 2.9.1 2.8.2 2.7.0 2.6.0 2.5.2 2.4.0 2.3.0 2.2.1 2.1.2 1.50.0 1.49.0 1.48.0 1.47.0 1.46.5 1.45.2 1.44.0 1.43.2 1.42.1 1.41.3 1.40.1 1.39.3 Reference documentation and code samples for the Cloud PubSub Client class Schema.

Represents a Pub/Sub Schema resource.

Schema Support for Cloud Pub/Sub allows you to register schemas in common
formats as standalone versioned resources, associates schemas with Pub/Sub
topics, validates message structure on-publish, and provides APIs
parameterized on your entity types.

Example:

    use Google\Cloud\PubSub\PubSubClient;

    $client = new PubSubClient(['projectId' => 'my-project']);
    $schema = $client->schema('my-schema');

## Namespace

Google \\ Cloud \\ PubSub

## Methods

### __construct

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `requestHandler` | `Google\Cloud\Core\RequestHandler` |
| `serializer` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/Serializer.html` The serializer instance to encode/decode messages. |
| `name` | `string` The schema name. |
| `info` | `array` \[optional\] Schema data. |

### name

Get the schema resource name.

Example:

    $name = $schema->name();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### delete

Delete the schema.

Example:

    $schema->delete();

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` \[optional\] Configuration options |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### info

Get schema information.

Since this method will throw an exception if the schema is not found, you
may find that [Schema::exists()](https://docs.cloud.google.com/php/docs/reference/cloud-pubsub/latest/Schema#_Google_Cloud_PubSub_Schema__exists__) is a better fit
for a true/false check.

This method will use the previously cached result, if available. To force
a refresh from the API, use [Schema::reload()](https://docs.cloud.google.com/php/docs/reference/cloud-pubsub/latest/Schema#_Google_Cloud_PubSub_Schema__reload__).

Example:

    $info = $schema->info();
    echo $info['name']; // projects/my-awesome-project/schemas/my-schema

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration Options |
| `↳ view` | `string` The set of Schema fields to return in the response. If not set, returns Schemas with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all fields. For allowed values, use constants defined on [V1\\SchemaView](https://docs.cloud.google.com/php/docs/reference/cloud-pubsub/latest/V1.SchemaView). **Note** : for this method, `$options.view` defaults to `FULL`. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

### reload

Get schema information from the API.

Since this method will throw an exception if the schema is not found, you
may find that [Schema::exists()](https://docs.cloud.google.com/php/docs/reference/cloud-pubsub/latest/Schema#_Google_Cloud_PubSub_Schema__exists__) is a better fit
for a true/false check.

This method will retrieve a new result from the API. To use a previously
cached result, if one exists, use [Schema::info()](https://docs.cloud.google.com/php/docs/reference/cloud-pubsub/latest/Schema#_Google_Cloud_PubSub_Schema__info__).

Example:

    $info = $schema->reload();
    echo $info['name']; // projects/my-awesome-project/schemas/my-schema

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration Options |
| `↳ view` | `string` The set of Schema fields to return in the response. If not set, returns Schemas with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all fields. For allowed values, use constants defined on [V1\\SchemaView](https://docs.cloud.google.com/php/docs/reference/cloud-pubsub/latest/V1.SchemaView). **Note** : for this method, `$options.view` defaults to `FULL`. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

### exists

Check if a schema exists.

Example:

    if ($schema->exists()) {
        echo 'Schema exists';
    }

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` \[optional\] Configuration Options |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `bool` |   |

### listRevisions

See also:

- [List revisions](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/listRevisions)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` \[optional\] Configuration Options |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

### commit

See also:

- [Commit Schema revision.
  \`\`\`](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/commit)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `definition` | `string` The definition of the schema. This should contain a string representing the full definition of the schema that is a valid schema definition of the type specified in `type`. See [Schema](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas#Schema) for details. |
| `type` | `string` The schema type. Allowed values are `AVRO` and `PROTOCOL_BUFFER`. |
| `options` | `array` \[optional\] Configuration options |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` | revision created |

### deleteRevision

See also:

- [Delete revision.
  \`\`\`](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/deleteRevision)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `revisionId` | `string` The revisionId |
| `options` | `mixed` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` | deleted revision |