Skip to content

Commit ed80871

Browse files
improved
1 parent ad4001c commit ed80871

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

src/Bolt.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ final class Bolt
2626

2727
public function __construct(private IConnection $connection)
2828
{
29-
if (!getenv('TEMP')) {
30-
putenv('TEMP=' . dirname(__DIR__) . DIRECTORY_SEPARATOR . 'temp');
31-
if (!file_exists(getenv('TEMP'))) {
32-
mkdir(getenv('TEMP'), recursive: true);
33-
}
29+
$_ENV['TEMP_DIR'] = getenv('TEMP') ?? getenv('TMPDIR') ?? (dirname(__DIR__) . DIRECTORY_SEPARATOR . 'temp');
30+
if (!file_exists($_ENV['TEMP_DIR'])) {
31+
mkdir($_ENV['TEMP_DIR'], recursive: true);
3432
}
3533

3634
if (!getenv('BOLT_ANALYTICS_OPTOUT')) {
37-
if (!file_exists(getenv('TEMP') . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR)) {
38-
mkdir(getenv('TEMP') . DIRECTORY_SEPARATOR . 'php-bolt-analytics');
35+
if (!file_exists($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR)) {
36+
mkdir($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics');
3937
}
4038
$this->track();
4139
}
@@ -45,7 +43,7 @@ public function __construct(private IConnection $connection)
4543

4644
private function track(): void
4745
{
48-
foreach (glob(getenv('TEMP') . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR . 'queries.*.cnt') as $file) {
46+
foreach (glob($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR . 'queries.*.cnt') as $file) {
4947
$time = intval(explode('.', basename($file))[1]);
5048
if ($time < strtotime('today')) {
5149
$count = file_get_contents($file);

src/helpers/FileCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class FileCache implements CacheInterface
1717

1818
public function __construct()
1919
{
20-
$this->tempDir = getenv('TEMP') . DIRECTORY_SEPARATOR . 'php-bolt-filecache' . DIRECTORY_SEPARATOR;
20+
$this->tempDir = $_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-filecache' . DIRECTORY_SEPARATOR;
2121
if (!file_exists($this->tempDir)) {
22-
mkdir(getenv('TEMP') . DIRECTORY_SEPARATOR . 'php-bolt-filecache');
22+
mkdir($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-filecache');
2323
}
2424

2525
// clean old

src/protocol/AProtocol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function write(iterable $generator): void
7373

7474
private function track(): void
7575
{
76-
$file = getenv('TEMP') . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR . 'queries.' . strtotime('today') . '.cnt';
76+
$file = $_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR . 'queries.' . strtotime('today') . '.cnt';
7777
$count = file_exists($file) ? intval(file_get_contents($file)) : 0;
7878
file_put_contents($file, $count + 1);
7979
}

tests/protocol/ProtocolLayer.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,14 @@ public function readCallback(int $length = 2048): string
100100
*/
101101
protected function setUp(): void
102102
{
103-
if (!getenv('TEMP')) {
104-
putenv('TEMP=' . dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'temp');
105-
if (!file_exists(getenv('TEMP'))) {
106-
mkdir(getenv('TEMP'), recursive: true);
107-
}
108-
var_dump(getenv('TEMP'));
103+
$_ENV['TEMP_DIR'] = getenv('TEMP') ?? getenv('TMPDIR') ?? (dirname(__DIR__) . DIRECTORY_SEPARATOR . 'temp');
104+
if (!file_exists($_ENV['TEMP_DIR'])) {
105+
mkdir($_ENV['TEMP_DIR'], recursive: true);
109106
}
110107

111108
if (!getenv('BOLT_ANALYTICS_OPTOUT')) {
112-
if (!file_exists(getenv('TEMP') . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR)) {
113-
mkdir(getenv('TEMP') . DIRECTORY_SEPARATOR . 'php-bolt-analytics');
109+
if (!file_exists($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR)) {
110+
mkdir($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics');
114111
}
115112
}
116113

0 commit comments

Comments
 (0)