Skip to content

Commit

Permalink
feat: Add the protected apiVersion property
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Apr 22, 2024
1 parent 633d41f commit cf8ee77
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Service/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Resource
/** @var string $rootUrl */
private $rootUrl;

/** @var string $apiVersion */
protected $apiVersion;

/** @var \Google\Client $client */
private $client;

Expand Down Expand Up @@ -235,6 +238,13 @@ public function call($name, $arguments, $expectedClass = null)
return $request;
}

// If the class which is extending from this one contains
// an Api Version, add it to the header
if ($this->apiVersion) {
$request = $request
->withHeaders('X-Goog-Api-Version', $this->apiVersion);
}

return $this->client->execute($request, $expectedClass);
}

Expand Down
25 changes: 25 additions & 0 deletions test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
class Test
{
protected $name;

public function getName(){
if ($this->name) {
return $this->name;
}

return "No name";
}
}

class Child extends Test
{
protected $name = "Hector";
}

$p = new Test();

print($p->getName());

$c = new Child();
print($c->getName());

0 comments on commit cf8ee77

Please sign in to comment.