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

Allow customising where the ray.php config file can go with an env variable #935

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow customising where the ray.php config file can go with an env va…
…riable.

Setting the env variable RAY_CONFIG_DIR will look for ray.php in that
directory instead of in the root project directory. This allows us to separate
our config out of the main codebase.
  • Loading branch information
cwarwicker committed Sep 10, 2024
commit 408ee817680bafa0a8773ae4fc8b99d8eb28910c
3 changes: 2 additions & 1 deletion src/Ray.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class Ray

public static function create(?Client $client = null, ?string $uuid = null): self
{
$settings = SettingsFactory::createFromConfigFile();
$configDir = (isset($_SERVER['RAY_CONFIG_DIR'])) ? $_SERVER['RAY_CONFIG_DIR'] : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think using getenv() here would be a better choice instead of directly accessing $_SERVER. It might also be good to do some validation of the value before passing it to SettingsFactory.

$settings = SettingsFactory::createFromConfigFile($configDir);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also add some additional unit tests to ensure the functionality works as expected.


return new static($settings, $client, $uuid);
}
Expand Down
3 changes: 2 additions & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function ray(...$args)
$rayClass = SymfonyRay::class;
}

$settings = SettingsFactory::createFromConfigFile();
$configDir = (isset($_SERVER['RAY_CONFIG_DIR'])) ? $_SERVER['RAY_CONFIG_DIR'] : null;
$settings = SettingsFactory::createFromConfigFile($configDir);

return (new $rayClass($settings))->send(...$args);
}
Expand Down