Repository navigation
Replace environment and restHost with endpoint #229
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
base: integration/v2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,29 +5,63 @@ class Defaults { | |
| const API_VERSION = '2'; | ||
| const LIB_VERSION = '2.0.0'; | ||
|
|
||
| static $restHost = "rest.ably.io"; | ||
| static $realtimeHost = "realtime.ably.io"; | ||
| static $endpoint = 'main'; | ||
| static $port = 80; | ||
| static $tlsPort = 443; | ||
|
|
||
| static $internetCheckUrl = "https://internet-up.ably-realtime.com/is-the-internet-up.txt"; | ||
| static $internetCheckOk = "yes\n"; | ||
|
|
||
| static $fallbackHosts = [ | ||
| 'a.ably-realtime.com', | ||
| 'b.ably-realtime.com', | ||
| 'c.ably-realtime.com', | ||
| 'd.ably-realtime.com', | ||
| 'e.ably-realtime.com', | ||
| 'main.a.fallback.ably-realtime.com', | ||
| 'main.b.fallback.ably-realtime.com', | ||
| 'main.c.fallback.ably-realtime.com', | ||
| 'main.d.fallback.ably-realtime.com', | ||
| 'main.e.fallback.ably-realtime.com', | ||
| ]; | ||
|
|
||
| static function getEnvironmentFallbackHosts($environment) { | ||
| return [ | ||
| $environment."-a-fallback.ably-realtime.com", | ||
| $environment."-b-fallback.ably-realtime.com", | ||
| $environment."-c-fallback.ably-realtime.com", | ||
| $environment."-d-fallback.ably-realtime.com", | ||
| $environment."-e-fallback.ably-realtime.com" | ||
| ]; | ||
| const NONPROD_PREFIX = 'nonprod:'; | ||
|
|
||
| /** | ||
| * An endpoint is taken as a hostname rather than a routing policy id when | ||
| * it contains a `.` or `::`, or is `localhost` (REC1b2). | ||
| */ | ||
| static function isHostname($endpoint) { | ||
| return strpos($endpoint, '.') !== false | ||
| || strpos($endpoint, '::') !== false | ||
| || $endpoint === 'localhost'; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the primary domain from an `endpoint` client option (REC1). | ||
| */ | ||
| static function getPrimaryDomain($endpoint) { | ||
| if (self::isHostname($endpoint)) { | ||
| return $endpoint; // REC1b2 | ||
| } | ||
| if (strpos($endpoint, self::NONPROD_PREFIX) === 0) { | ||
| return substr($endpoint, strlen(self::NONPROD_PREFIX)).'.realtime.ably-nonprod.net'; // REC1b3 | ||
| } | ||
| return $endpoint.'.realtime.ably.net'; // REC1b4 | ||
| } | ||
|
Comment on lines
+38
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '20,75p' src/Defaults.php
sed -n '32,75p' src/Models/ClientOptions.php
sed -n '145,192p' src/Models/ClientOptions.php
sed -n '42,74p' UPDATING.mdRepository: ably/ably-pubsub-php Length of output: 6682 Reject empty or non-string
Validate the endpoint at the 🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
| * Resolves the default fallback domains for an `endpoint` client option (REC2c). | ||
| */ | ||
| static function getEndpointFallbackHosts($endpoint) { | ||
| if (self::isHostname($endpoint)) { | ||
| return []; // REC2c2 | ||
| } | ||
| if (strpos($endpoint, self::NONPROD_PREFIX) === 0) { | ||
| $id = substr($endpoint, strlen(self::NONPROD_PREFIX)); | ||
| return self::fallbackHostsFor($id, 'ably-realtime-nonprod.com'); // REC2c3 | ||
| } | ||
| return self::fallbackHostsFor($endpoint, 'ably-realtime.com'); // REC2c1, REC2c4 | ||
| } | ||
|
|
||
| private static function fallbackHostsFor($id, $domain) { | ||
| return array_map(function ($letter) use ($id, $domain) { | ||
| return $id.'.'.$letter.'.fallback.'.$domain; | ||
| }, ['a', 'b', 'c', 'd', 'e']); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: ably/ably-pubsub-php
Length of output: 3263
Bracket IPv6 literals when building request URLs.
Defaults::isHostname()accepts::1, andClientOptionspreserves it as the primary domain.getHostUrl()then constructshttps://::1:443, which is not a valid cURL IPv6 authority. Bracket the URL-only value without changing the stored primary domain.Suggested fix
public function getHostUrl($host) { + if (filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { + $host = '[' . $host . ']'; + } return ($this-> tls ? 'https://' : 'http://') . $host. ':' .$this->activePort(); }🤖 Prompt for AI Agents