Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust environment variable fetching #530

Merged
merged 2 commits into from
Aug 15, 2019
Merged

More robust environment variable fetching #530

merged 2 commits into from
Aug 15, 2019

Conversation

GrahamCampbell
Copy link
Contributor

Goal

The getenv and putenv functions in PHP are not threadsafe. For this reason, sometimes people choose not to call them when loading any environment variables in a scripted fashion, for example, from a ruby-style .env file, using some custom software.

Thus, we may need to check beyond getenv to find the environment variable the user has set. Fortunately, there is a mature package for doing this (and for loading .env files... it is actually exactly the package that ships with Laravel): vlucas/phpdotenv.

Design

We replace the calls to getenv with checking all of the possible sources environment variables could be in: $_SERVER[...], $_ENV[...], getenv(...), apache_getenv(...) (where available).

Changeset

There area no API changes.

Tests

An additional test has been added, demonstrating that loading the api key and server url into the env superglobal can now be detected by the client on instantiation.

Review

For the pull request reviewer(s), this changeset has been reviewed for:

  • Consistency across platforms for structures or concepts added or modified
  • Consistency between the changeset and the goal stated above
  • Internal consistency with the rest of the library - is there any overlap between existing interfaces and any which have been added?
  • Usage friction - is the proposed change in usage cumbersome or complicated?
  • Performance and complexity - are there any cases of unexpected O(n^3) when iterating, recursing, flat mapping, etc?
  • Concurrency concerns - if components are accessed asynchronously, what issues will arise
  • Thoroughness of added tests and any missing edge cases
  • Idiomatic use of the language

@tomlongridge tomlongridge changed the base branch from master to next August 15, 2019 09:48
Copy link
Contributor

@tomlongridge tomlongridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks @GrahamCampbell!

@tomlongridge tomlongridge merged commit 426b64f into next Aug 15, 2019
@tomlongridge tomlongridge deleted the env branch August 15, 2019 10:22
tomlongridge added a commit that referenced this pull request Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants