PHP Class Google\Cloud\Compute\Metadata

The metadata is available from Google Compute Engine instances and App Engine Managed VMs instances. You can get the GCE metadata values very easily like: use Google\Cloud\Compute\Metadata; $metadata = new Metadata(); $project_id = $metadata->getProjectId(); $val = $metadata->getProjectMetadata($key);
Exibir arquivo Open project: GoogleCloudPlatform/gcloud-php

Public Methods

Method Description
__construct ( ) We use StreamReader for the default implementation for fetching the URL.
get ( string $path ) Fetch a metadata item by its path
getInstanceMetadata ( string $key ) : string Fetch an item from the instance metadata
getProjectId ( ) : string Detect and return the project ID
getProjectMetadata ( string $key ) : string Fetch an item from the project metadata
setReader ( mixed $reader ) Replace the default reader implementation

Method Details

__construct() public method

We use StreamReader for the default implementation for fetching the URL.
public __construct ( )

get() public method

Example: $projectId = $reader->get('project/project-id');
public get ( string $path )
$path string The path of the item to retrieve.

getInstanceMetadata() public method

Example: $foo = $reader->getInstanceMetadata('foo');
public getInstanceMetadata ( string $key ) : string
$key string The instance metadata key
return string

getProjectId() public method

Example: $projectId = $reader->getProjectId();
public getProjectId ( ) : string
return string

getProjectMetadata() public method

Example: $foo = $reader->getProjectMetadata('foo');
public getProjectMetadata ( string $key ) : string
$key string The metadata key
return string

setReader() public method

Replace the default reader implementation
public setReader ( mixed $reader )
$reader mixed The reader implementation