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

Add environment property to context #25

Merged

Conversation

fenix20113
Copy link
Contributor

Add the environment property to context to be able to:

  1. Use the Constrain on a specific environment
  2. Create custom strategies based on the environment.

src/Configuration/Context.php Outdated Show resolved Hide resolved
src/Configuration/UnleashContext.php Outdated Show resolved Hide resolved
src/DefaultUnleash.php Outdated Show resolved Hide resolved
@fenix20113 fenix20113 force-pushed the add-environment-property-to-context branch 3 times, most recently from e5edecd to 55deac7 Compare September 10, 2021 10:08
@RikudouSage
Copy link
Collaborator

The current error is because the environment is not set in \Unleash\Client\Tests\ClientSpecificationTest::createContext(). That's why I would advise to do it similarly to how the hostname is handled in context:

    public function getHostname(): ?string
    {
        return $this->findContextValue(ContextField::HOSTNAME) ?? (gethostname() ?: null);
    }

    public function setHostname(?string $hostname): self
    {
        if ($hostname === null) {
            $this->removeCustomProperty(ContextField::HOSTNAME);
        } else {
            $this->setCustomProperty(ContextField::HOSTNAME, $hostname);
        }

        return $this;
    }

And in constructor you will just call $this->setEnvironment($environment) while removing the private modifier from the constructor parameter. But it's up to you, I'll accept both solutions.

@fenix20113 fenix20113 force-pushed the add-environment-property-to-context branch from 55deac7 to 0a6e201 Compare September 10, 2021 11:40
@fenix20113
Copy link
Contributor Author

Thanks for the explanation. I updated \Unleash\Client\Tests\ClientSpecificationTest::createContext()

@RikudouSage RikudouSage merged commit c538c7c into Unleash:master Sep 10, 2021
@RikudouSage
Copy link
Collaborator

Thank you for your contribution!

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.

3 participants