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');
The set of Schema fields to return in the response. If not set, returns Schemas withnameandtype, but notdefinition. Set toFULLto retrieve all fields. For allowed values, use constants defined onV1\SchemaView.Note: for this method,$options.viewdefaults toFULL.
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 thatSchema::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, useSchema::info().
The set of Schema fields to return in the response. If not set, returns Schemas withnameandtype, but notdefinition. Set toFULLto retrieve all fields. For allowed values, use constants defined onV1\SchemaView.Note: for this method,$options.viewdefaults toFULL.
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 intype. SeeSchemafor details.
type
string
The schema type. Allowed values areAVROandPROTOCOL_BUFFER.
[[["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,["# Cloud PubSub Client - Class Schema (2.13.2)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.2 (latest)](/php/docs/reference/cloud-pubsub/latest/Schema)\n- [2.13.1](/php/docs/reference/cloud-pubsub/2.13.1/Schema)\n- [2.12.0](/php/docs/reference/cloud-pubsub/2.12.0/Schema)\n- [2.11.3](/php/docs/reference/cloud-pubsub/2.11.3/Schema)\n- [2.10.1](/php/docs/reference/cloud-pubsub/2.10.1/Schema)\n- [2.9.1](/php/docs/reference/cloud-pubsub/2.9.1/Schema)\n- [2.8.2](/php/docs/reference/cloud-pubsub/2.8.2/Schema)\n- [2.7.0](/php/docs/reference/cloud-pubsub/2.7.0/Schema)\n- [2.6.0](/php/docs/reference/cloud-pubsub/2.6.0/Schema)\n- [2.5.2](/php/docs/reference/cloud-pubsub/2.5.2/Schema)\n- [2.4.0](/php/docs/reference/cloud-pubsub/2.4.0/Schema)\n- [2.3.0](/php/docs/reference/cloud-pubsub/2.3.0/Schema)\n- [2.2.1](/php/docs/reference/cloud-pubsub/2.2.1/Schema)\n- [2.1.2](/php/docs/reference/cloud-pubsub/2.1.2/Schema)\n- [1.50.0](/php/docs/reference/cloud-pubsub/1.50.0/Schema)\n- [1.49.0](/php/docs/reference/cloud-pubsub/1.49.0/Schema)\n- [1.48.0](/php/docs/reference/cloud-pubsub/1.48.0/Schema)\n- [1.47.0](/php/docs/reference/cloud-pubsub/1.47.0/Schema)\n- [1.46.5](/php/docs/reference/cloud-pubsub/1.46.5/Schema)\n- [1.45.2](/php/docs/reference/cloud-pubsub/1.45.2/Schema)\n- [1.44.0](/php/docs/reference/cloud-pubsub/1.44.0/Schema)\n- [1.43.2](/php/docs/reference/cloud-pubsub/1.43.2/Schema)\n- [1.42.1](/php/docs/reference/cloud-pubsub/1.42.1/Schema)\n- [1.41.3](/php/docs/reference/cloud-pubsub/1.41.3/Schema)\n- [1.40.1](/php/docs/reference/cloud-pubsub/1.40.1/Schema)\n- [1.39.3](/php/docs/reference/cloud-pubsub/1.39.3/Schema) \nReference documentation and code samples for the Cloud PubSub Client class Schema.\n\nRepresents a Pub/Sub Schema resource.\n\nSchema Support for Cloud Pub/Sub allows you to register schemas in common\nformats as standalone versioned resources, associates schemas with Pub/Sub\ntopics, validates message structure on-publish, and provides APIs\nparameterized on your entity types.\n\nExample: \n\n use Google\\Cloud\\PubSub\\PubSubClient;\n\n $client = new PubSubClient(['projectId' =\u003e 'my-project']);\n $schema = $client-\u003eschema('my-schema');\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ PubSub\n\nMethods\n-------\n\n### __construct\n\n### name\n\nGet the schema resource name.\n\nExample: \n\n $name = $schema-\u003ename();\n\n### delete\n\nDelete the schema.\n\nExample: \n\n $schema-\u003edelete();\n\n### info\n\nGet schema information.\n\nSince this method will throw an exception if the schema is not found, you\nmay find that [Schema::exists()](/php/docs/reference/cloud-pubsub/latest/Schema#_Google_Cloud_PubSub_Schema__exists__) is a better fit\nfor a true/false check.\n\nThis method will use the previously cached result, if available. To force\na refresh from the API, use [Schema::reload()](/php/docs/reference/cloud-pubsub/latest/Schema#_Google_Cloud_PubSub_Schema__reload__).\n\nExample: \n\n $info = $schema-\u003einfo();\n echo $info['name']; // projects/my-awesome-project/schemas/my-schema\n\n### reload\n\nGet schema information from the API.\n\nSince this method will throw an exception if the schema is not found, you\nmay find that [Schema::exists()](/php/docs/reference/cloud-pubsub/latest/Schema#_Google_Cloud_PubSub_Schema__exists__) is a better fit\nfor a true/false check.\n\nThis method will retrieve a new result from the API. To use a previously\ncached result, if one exists, use [Schema::info()](/php/docs/reference/cloud-pubsub/latest/Schema#_Google_Cloud_PubSub_Schema__info__).\n\nExample: \n\n $info = $schema-\u003ereload();\n echo $info['name']; // projects/my-awesome-project/schemas/my-schema\n\n### exists\n\nCheck if a schema exists.\n\nExample: \n\n if ($schema-\u003eexists()) {\n echo 'Schema exists';\n }\n\n### listRevisions\n\nSee also:\n\n- [List revisions](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/listRevisions)\n\n### commit\n\nSee also:\n\n- [Commit Schema revision.\n \\`\\`\\`](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/commit)\n\n### deleteRevision\n\nSee also:\n\n- [Delete revision.\n \\`\\`\\`](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/deleteRevision)"]]