Skip to content

Commit

Permalink
fix: deprecate domain sharding (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherwinski authored May 1, 2019
1 parent 8decfc8 commit b1fabd9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ echo $builder->createURL("bridge.png", $params);
```

## Domain Sharded URLs
**Warning: Domain Sharding has been deprecated and will be removed in the next major release**

Domain sharding enables you to spread image requests across multiple domains.
This allows you to bypass the requests-per-host limits of browsers. We
Expand Down
2 changes: 2 additions & 0 deletions src/Imgix/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function __construct($domains, $useHttps = false, $signKey = "", $shardSt
if (!is_array($domains)) {
$this->domains = array($domains);
} else {
$warning_message = "Warning: Domain sharding has been deprecated and will be removed in the next major version.";
@trigger_error($warning_message, E_USER_DEPRECATED);
$this->domains = $domains;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Imgix/Tests/UrlBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,17 @@ public function test_invalid_domain_array() {

$builder = new UrlBuilder(array("demos.imgix.net","demos.imgix.net-"), true, "", ShardStrategy::CYCLE, false);
}
public function test_deprecation_warning() {
# Tests for deprecation warning using a custom error handler
# as the warning is typically suppressed to prevent polluting
# error logs
set_error_handler(function($errno, $errstr, $errfile, $errline) {
$warning_message = "Warning: Domain sharding has been deprecated and will be removed in the next major version.";
$this->assertEquals($warning_message, $errstr);
$this->assertEquals(E_USER_DEPRECATED, $errno);
}, E_USER_DEPRECATED);

$builder = new UrlBuilder(array("demos.imgix.net","demos.imgix.net"), true, "", ShardStrategy::CYCLE, false);
}
}
?>

0 comments on commit b1fabd9

Please sign in to comment.