Skip to content

Commit

Permalink
Fixes #101 to get home directory on other OSs. (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius authored Oct 20, 2020
1 parent a301ebd commit 9dbeeeb
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 128 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"guzzlehttp/guzzle": "^6.3",
"php": ">=7.3",
"league/oauth2-client": "^2.4",
"symfony/cache": "^4|^5"
"symfony/cache": "^4|^5",
"webmozart/path-util": "^2.3"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.0.0",
Expand Down
296 changes: 171 additions & 125 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/Connector/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Psr\Http\Message\RequestInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Contracts\Cache\ItemInterface;
use Webmozart\PathUtil\Path;

/**
* Class Connector
Expand Down Expand Up @@ -66,7 +67,7 @@ public function __construct(array $config)
public function createRequest($verb, $path)
{
if (!isset($this->accessToken) || $this->accessToken->hasExpired()) {
$directory = sprintf('%s%s%s', posix_getpwuid(getmyuid())['dir'], \DIRECTORY_SEPARATOR, '.acquia-php-sdk-v2');
$directory = sprintf('%s%s%s', Path::getHomeDirectory(), \DIRECTORY_SEPARATOR, '.acquia-php-sdk-v2');
$cache = new FilesystemAdapter('cache', 0, $directory);
$accessToken = $cache->get('cloudapi-token', function (ItemInterface $item) {
$item->expiresAfter(300);
Expand Down
3 changes: 2 additions & 1 deletion tests/Endpoints/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Request;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Webmozart\PathUtil\Path;

class ConnectorTest extends CloudApiTestCase
{
Expand All @@ -33,7 +34,7 @@ public function setUp()
$this->connector = new Connector($config);

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

0 comments on commit 9dbeeeb

Please sign in to comment.