A library for accessing the Google Compute Engine (GCE) metadata.

The metadata is available from Google Compute Engine instances and
App Engine Managed VMs instances.

Example:

use Google\Cloud\Core\Compute\Metadata;

$metadata = new Metadata();
$projectId = $metadata->getProjectId();
// It is easy to get any metadata from a project.
$val = $metadata->getProjectMetadata($key);
CloneableInstantiable
Methods
public __construct(?Google\Cloud\Core\Compute\Metadata\Readers\ReaderInterface $reader = NULL)
 
    public get( $path)
     

    Fetch a metadata item by its path

    Example:

    $projectId = $metadata->get('project/project-id');
    
      public getInstanceMetadata( $key)
       

      Fetch an item from the instance metadata

      Example:

      $foo = $metadata->getInstanceMetadata('foo');
      
      • return string
      public getNumericProjectId()
       

      Detect and return the numeric project ID

      Example:

      $projectId = $metadata->getNumericProjectId();
      
      • return string
      public getProjectId()
       

      Detect and return the project ID

      Example:

      $projectId = $metadata->getProjectId();
      
      • return string
      public getProjectMetadata( $key)
       

      Fetch an item from the project metadata

      Example:

      $foo = $metadata->getProjectMetadata('foo');
      
      • return string
      public setReader(Google\Cloud\Core\Compute\Metadata\Readers\ReaderInterface $reader)
       

      Replace the default reader implementation

      • deprecated If a custom reader implementation is desired, provide it at construction.
      Properties
      private $numericProjectId
       
      • var int The numeric project id.
      private $projectId
       
      • var string The project id.
      private $reader
       
      • var ReaderInterface The metadata reader.
      © 2020 Bruce Wells
      Search Namespaces \ Classes
      ConfigurationNumbers (0-9.) only