Skip to content

Commit

Permalink
Changes cache directory to the user's home. (#100)
Browse files Browse the repository at this point in the history
* Changes cache directory to the user's home.

* Make finding the user's home directory more cross-platform.

* Use PHP constant for directory separation.
  • Loading branch information
typhonius committed Oct 17, 2020
1 parent 5e9ddac commit a301ebd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Connector/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function __construct(array $config)
public function createRequest($verb, $path)
{
if (!isset($this->accessToken) || $this->accessToken->hasExpired()) {
$cache = new FilesystemAdapter('acquia-php-sdk-v2');
$directory = sprintf('%s%s%s', posix_getpwuid(getmyuid())['dir'], \DIRECTORY_SEPARATOR, '.acquia-php-sdk-v2');
$cache = new FilesystemAdapter('cache', 0, $directory);
$accessToken = $cache->get('cloudapi-token', function (ItemInterface $item) {
$item->expiresAfter(300);
return $this->provider->getAccessToken('client_credentials');
Expand Down
3 changes: 2 additions & 1 deletion tests/Endpoints/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function setUp()
$this->connector = new Connector($config);

// Clear the cache to make sure we get fresh results during testing.
$this->cache = new FilesystemAdapter('acquia-php-sdk-v2');
$directory = sprintf('%s%s%s', posix_getpwuid(getmyuid())['dir'], \DIRECTORY_SEPARATOR, '.acquia-php-sdk-v2');
$this->cache = new FilesystemAdapter('cache', 0, $directory);
$this->cache->deleteItem('cloudapi-token');
}

Expand Down

0 comments on commit a301ebd

Please sign in to comment.