Skip to content

Commit

Permalink
fix(php): open_basedir restriction (#944)
Browse files Browse the repository at this point in the history
* Only load composer cache, when required

* Reverted short syntax

* Remain empty line

* Made Psalm happy again

* Removed spaces in empty line
  • Loading branch information
xolf authored Dec 11, 2023
1 parent ed22dd1 commit 36506cd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/php/src/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Metrics
private Client $readme_api_client;

private string|null $package_version;
private string $cache_dir;
private string|null $cache_dir;
private string $user_agent;

/**
Expand Down Expand Up @@ -80,7 +80,7 @@ public function __construct(public string $api_key, public string $group_handler
]);

$this->package_version = InstalledVersions::getVersion(self::PACKAGE_NAME);
$this->cache_dir = Factory::createConfig()->get('cache-dir');
$this->cache_dir = null;

$this->user_agent = 'readme-metrics-php/' . ($this->package_version ?? 'unknown');
}
Expand Down Expand Up @@ -247,7 +247,20 @@ public function getCacheFile(): string
// Replace potentially unsafe characters in the cache key so it can be safely used as a filename on the server.
$cache_key = str_replace([DIRECTORY_SEPARATOR, '@'], '-', $cache_key);

return $this->cache_dir . DIRECTORY_SEPARATOR . $cache_key;
return $this->getCacheDir() . DIRECTORY_SEPARATOR . $cache_key;
}

/**
* Retrieve the cache dir where the cache file will be stored.
*
*/
public function getCacheDir(): string
{
if ($this->cache_dir === null) {
$this->cache_dir = Factory::createConfig()->get('cache-dir');
}

return $this->cache_dir;
}

public function getPackageVersion(): ?string
Expand Down

0 comments on commit 36506cd

Please sign in to comment.