Skip to content

Commit 5dae60c

Browse files
committed
Use $_SERVER instead of $_ENV
on many PHP distribution (for example on ubuntu), [`variables_order` ini setting](https://www.php.net/manual/en/ini.core.php#ini.variables-order) does not include `E` flag: ``` php -i | grep variables_order variables_order => GPCS => GPCS ``` So this script: ``` echo 'env(VAR): ' . ($_ENV['VAR'] ?? 'not set'); echo "\n"; echo 'server(VAR): ' . ($_SERVER['VAR'] ?? 'not set'); echo "\n"; ``` outputs: ```console $ VAR=hello php test.php env(VAR): not set server(VAR): hello ```
1 parent 8d4134c commit 5dae60c

File tree

89 files changed

+188
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+188
-188
lines changed

examples/anthropic/chat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
require_once dirname(__DIR__).'/vendor/autoload.php';
2020
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2121

22-
if (!isset($_ENV['ANTHROPIC_API_KEY'])) {
22+
if (!isset($_SERVER['ANTHROPIC_API_KEY'])) {
2323
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;
2424
exit(1);
2525
}
2626

27-
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
27+
$platform = PlatformFactory::create($_SERVER['ANTHROPIC_API_KEY']);
2828
$model = new Claude(Claude::SONNET_37);
2929

3030
$agent = new Agent($platform, $model);

examples/anthropic/image-input-binary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
require_once dirname(__DIR__).'/vendor/autoload.php';
2121
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2222

23-
if (!isset($_ENV['ANTHROPIC_API_KEY'])) {
23+
if (!isset($_SERVER['ANTHROPIC_API_KEY'])) {
2424
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;
2525
exit(1);
2626
}
2727

28-
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
28+
$platform = PlatformFactory::create($_SERVER['ANTHROPIC_API_KEY']);
2929
$model = new Claude(Claude::SONNET_37);
3030

3131
$agent = new Agent($platform, $model);

examples/anthropic/image-input-url.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
require_once dirname(__DIR__).'/vendor/autoload.php';
2121
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2222

23-
if (!isset($_ENV['ANTHROPIC_API_KEY'])) {
23+
if (!isset($_SERVER['ANTHROPIC_API_KEY'])) {
2424
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;
2525
exit(1);
2626
}
2727

28-
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
28+
$platform = PlatformFactory::create($_SERVER['ANTHROPIC_API_KEY']);
2929
$model = new Claude(Claude::SONNET_37);
3030

3131
$agent = new Agent($platform, $model);

examples/anthropic/pdf-input-binary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
require_once dirname(__DIR__).'/vendor/autoload.php';
2121
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2222

23-
if (!isset($_ENV['ANTHROPIC_API_KEY'])) {
23+
if (!isset($_SERVER['ANTHROPIC_API_KEY'])) {
2424
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;
2525
exit(1);
2626
}
2727

28-
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
28+
$platform = PlatformFactory::create($_SERVER['ANTHROPIC_API_KEY']);
2929
$model = new Claude(Claude::SONNET_37);
3030

3131
$agent = new Agent($platform, $model);

examples/anthropic/pdf-input-url.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
require_once dirname(__DIR__).'/vendor/autoload.php';
2121
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2222

23-
if (!isset($_ENV['ANTHROPIC_API_KEY'])) {
23+
if (!isset($_SERVER['ANTHROPIC_API_KEY'])) {
2424
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;
2525
exit(1);
2626
}
2727

28-
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
28+
$platform = PlatformFactory::create($_SERVER['ANTHROPIC_API_KEY']);
2929
$model = new Claude(Claude::SONNET_37);
3030

3131
$agent = new Agent($platform, $model);

examples/anthropic/stream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
require_once dirname(__DIR__).'/vendor/autoload.php';
2020
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2121

22-
if (!isset($_ENV['ANTHROPIC_API_KEY'])) {
22+
if (!isset($_SERVER['ANTHROPIC_API_KEY'])) {
2323
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;
2424
exit(1);
2525
}
2626

27-
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
27+
$platform = PlatformFactory::create($_SERVER['ANTHROPIC_API_KEY']);
2828
$model = new Claude();
2929

3030
$agent = new Agent($platform, $model);

examples/anthropic/toolcall.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
require_once dirname(__DIR__).'/vendor/autoload.php';
2424
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2525

26-
if (!isset($_ENV['ANTHROPIC_API_KEY'])) {
26+
if (!isset($_SERVER['ANTHROPIC_API_KEY'])) {
2727
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;
2828
exit(1);
2929
}
3030

31-
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
31+
$platform = PlatformFactory::create($_SERVER['ANTHROPIC_API_KEY']);
3232
$model = new Claude();
3333

3434
$wikipedia = new Wikipedia(HttpClient::create());

examples/azure/audio-transcript.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
require_once dirname(__DIR__).'/vendor/autoload.php';
1818
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
1919

20-
if (!isset($_ENV['AZURE_OPENAI_BASEURL'], $_ENV['AZURE_OPENAI_WHISPER_DEPLOYMENT'], $_ENV['AZURE_OPENAI_WHISPER_API_VERSION'], $_ENV['AZURE_OPENAI_KEY'])) {
20+
if (!isset($_SERVER['AZURE_OPENAI_BASEURL'], $_SERVER['AZURE_OPENAI_WHISPER_DEPLOYMENT'], $_SERVER['AZURE_OPENAI_WHISPER_API_VERSION'], $_SERVER['AZURE_OPENAI_KEY'])) {
2121
echo 'Please set the AZURE_OPENAI_BASEURL, AZURE_OPENAI_WHISPER_DEPLOYMENT, AZURE_OPENAI_WHISPER_API_VERSION, and AZURE_OPENAI_KEY environment variables.'.\PHP_EOL;
2222
exit(1);
2323
}
2424

2525
$platform = PlatformFactory::create(
26-
$_ENV['AZURE_OPENAI_BASEURL'],
27-
$_ENV['AZURE_OPENAI_WHISPER_DEPLOYMENT'],
28-
$_ENV['AZURE_OPENAI_WHISPER_API_VERSION'],
29-
$_ENV['AZURE_OPENAI_KEY'],
26+
$_SERVER['AZURE_OPENAI_BASEURL'],
27+
$_SERVER['AZURE_OPENAI_WHISPER_DEPLOYMENT'],
28+
$_SERVER['AZURE_OPENAI_WHISPER_API_VERSION'],
29+
$_SERVER['AZURE_OPENAI_KEY'],
3030
);
3131
$model = new Whisper();
3232
$file = Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3');

examples/azure/chat-gpt.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
require_once dirname(__DIR__).'/vendor/autoload.php';
2020
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2121

22-
if (!isset($_ENV['AZURE_OPENAI_BASEURL'], $_ENV['AZURE_OPENAI_GPT_DEPLOYMENT'], $_ENV['AZURE_OPENAI_GPT_API_VERSION'], $_ENV['AZURE_OPENAI_KEY'])) {
22+
if (!isset($_SERVER['AZURE_OPENAI_BASEURL'], $_SERVER['AZURE_OPENAI_GPT_DEPLOYMENT'], $_SERVER['AZURE_OPENAI_GPT_API_VERSION'], $_SERVER['AZURE_OPENAI_KEY'])) {
2323
echo 'Please set the AZURE_OPENAI_BASEURL, AZURE_OPENAI_GPT_DEPLOYMENT, AZURE_OPENAI_GPT_API_VERSION, and AZURE_OPENAI_KEY environment variables.'.\PHP_EOL;
2424
exit(1);
2525
}
2626

2727
$platform = PlatformFactory::create(
28-
$_ENV['AZURE_OPENAI_BASEURL'],
29-
$_ENV['AZURE_OPENAI_GPT_DEPLOYMENT'],
30-
$_ENV['AZURE_OPENAI_GPT_API_VERSION'],
31-
$_ENV['AZURE_OPENAI_KEY'],
28+
$_SERVER['AZURE_OPENAI_BASEURL'],
29+
$_SERVER['AZURE_OPENAI_GPT_DEPLOYMENT'],
30+
$_SERVER['AZURE_OPENAI_GPT_API_VERSION'],
31+
$_SERVER['AZURE_OPENAI_KEY'],
3232
);
3333
$model = new GPT(GPT::GPT_4O_MINI);
3434

examples/azure/chat-llama.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
require_once dirname(__DIR__).'/vendor/autoload.php';
2020
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2121

22-
if (!isset($_ENV['AZURE_LLAMA_BASEURL'], $_ENV['AZURE_LLAMA_KEY'])) {
22+
if (!isset($_SERVER['AZURE_LLAMA_BASEURL'], $_SERVER['AZURE_LLAMA_KEY'])) {
2323
echo 'Please set the AZURE_LLAMA_BASEURL and AZURE_LLAMA_KEY environment variable.'.\PHP_EOL;
2424
exit(1);
2525
}
2626

27-
$platform = PlatformFactory::create($_ENV['AZURE_LLAMA_BASEURL'], $_ENV['AZURE_LLAMA_KEY']);
27+
$platform = PlatformFactory::create($_SERVER['AZURE_LLAMA_BASEURL'], $_SERVER['AZURE_LLAMA_KEY']);
2828
$model = new Llama(Llama::V3_3_70B_INSTRUCT);
2929

3030
$agent = new Agent($platform, $model);

0 commit comments

Comments
 (0)