Skip to content

Commit

Permalink
Merge pull request #16 from platformsh/dedicated
Browse files Browse the repository at this point in the history
Dedicated
  • Loading branch information
Crell authored Nov 5, 2019
2 parents 9cb8f00 + 060e9e2 commit 9951de0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 13 deletions.
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Changelog

## [2.3.1] - 2019-11-04

### Added

* `CHANGELOG` added.
* `onDedicated` method that determines if the current environment is a Platform.sh Dedicated environment. Replaces deprecated `onEnterprise` method.

### Changed

* Deprecates `onEnterprise` method - which is for now made to wrap around the added `onDedicated` method. `onEnterprise` **will be removed** in a future release, so update your projects to use `onDedicated` instead as soon as possible.

## [2.3.0] - 2019-09-19

### Added

* `getPrimaryRoute` method for accessing routes marked "primary" in `routes.yaml`.
* `getUpstreamRoutes` method returns an object map that includes only those routes that point to a valid upstream.

## [2.2.2] - 2019-04-29

### Changed

* Updates `routes` method to use `routesDef` instead of `variablesDef` while checking if routes are defined in a Platform.sh environment.
* Updates `getRoute` method documentation in `README`.

### Removed

* Guard on the `variables` method.

## [2.2.1] - 2019-04-25

### Changed

* Improved the error handling for missing property variables.

## [2.2.0] - 2019-04-24

### Changed

* Route URL addition moved to constructor.
* Switch to more permissive checking of variable availability.

## [2.1.0] - 2019-03-22

### Added

* Adds `hasRelationship` method, which determines if a relationship is defined, and thus has credentials available.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ $config->inBuild();

$config->inRuntime();

$config->onEnterprise();
$config->onDedicated();

$config->onProduction();
```

> **Note:**
>
> Platform.sh will no longer refer to its [99.99% uptime SLA product](https://platform.sh/solutions/) as "Enterprise", but rather as "Dedicated". Configuration Reader libraries have in turn been updated to include an `onDedicated` method to replace `onEnterprise`. For now `onEnterprise` remains available. It now calls the new method and no breaking changes have been introduced.
>
> It is recommended that you update your projects to use `onDedicated` as soon as possible, as `onEnterprise` will be removed in a future version of this library.
### Read environment variables

The following magic properties return the corresponding environment variable value. See the [Platform.sh documentation](https://docs.platform.sh/development/variables.html) for a description of each.
Expand Down Expand Up @@ -129,7 +135,7 @@ In some cases the library being used to connect to a service wants its credentia
Credential Formatters can be registered on the configuration object, and a few are included out of the box. That allows 3rd party libraries to ship their own formatters that can be easily integrated into the `Config` object to allow easier use.

```php
function formatMyService(array $credentials) string
function formatMyService(array $credentials) string
{
return "some string based on $credentials";
}
Expand Down
30 changes: 25 additions & 5 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,40 @@ public function application() : array
}

/**
* Determines if the current environment is a Platform.sh Enterprise environment.
* Determines if the current environment is a Platform.sh Dedicated environment.
*
* @return bool
* True on an Enterprise environment, False otherwise.
* True on an Dedicated environment, False otherwise.
*/
public function onEnterprise() : bool
public function onDedicated() : bool
{
return $this->isValidPlatform() && $this->getValue('MODE') == 'enterprise';
}

/**
* Determines if the current environment is a Platform.sh Dedicated environment.
*
* @deprecated
*
* The Platform.sh "Enterprise" will soon be referred to exclusively as
* "Dedicated". the `onEnterprise` method remains available for now, but it
* will be removed in a future version of this library.
*
* It is recommended that you update your projects to use `onDedicated` as
* soon as possible.
*
* @return bool
* True on an Dedicated environment, False otherwise.
*/
public function onEnterprise() : bool
{
return $this->onDedicated();
}

/**
* Determines if the current environment is a production environment.
*
* Note: There may be a few edge cases where this is not entirely correct on Enterprise,
* Note: There may be a few edge cases where this is not entirely correct on Dedicated,
* if the production branch is not named `production`. In that case you'll need to use
* your own logic.
*
Expand All @@ -417,7 +437,7 @@ public function onProduction() : bool
return false;
}

$prodBranch = $this->onEnterprise() ? 'production' : 'master';
$prodBranch = $this->onDedicated() ? 'production' : 'master';

return $this->getValue('BRANCH') == $prodBranch;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,24 @@ public function test_upstream_routes_for_app_on_dedicated() : void
$this->assertEquals('https://www.{default}/', $routes['https://www.master-7rqtwti-gcpjkefjk4wc2.us-2.platformsh.site/']['original_url']);
}

public function test_onenterprise_returns_true_on_enterprise() : void
public function test_ondedicated_returns_true_on_dedicated() : void
{
$env = $this->mockEnvironmentDeploy;
$env['PLATFORM_MODE'] = 'enterprise';
$config = new Config($env);

$this->assertTrue($config->onEnterprise());
$this->assertTrue($config->onDedicated());
}

public function test_onenterprise_returns_false_on_standard() : void
public function test_ondedicated_returns_false_on_standard() : void
{
$env = $this->mockEnvironmentDeploy;
$config = new Config($env);

$this->assertFalse($config->onEnterprise());
$this->assertFalse($config->onDedicated());
}

public function test_onproduction_on_enterprise_prod_is_true() : void
public function test_onproduction_on_dedicated_prod_is_true() : void
{
$env = $this->mockEnvironmentDeploy;
$env['PLATFORM_MODE'] = 'enterprise';
Expand All @@ -210,7 +210,7 @@ public function test_onproduction_on_enterprise_prod_is_true() : void
$this->assertTrue($config->onProduction());
}

public function test_onproduction_on_enterprise_stg_is_false() : void
public function test_onproduction_on_dedicated_stg_is_false() : void
{
$env = $this->mockEnvironmentDeploy;
$env['PLATFORM_MODE'] = 'enterprise';
Expand Down

0 comments on commit 9951de0

Please sign in to comment.