diff --git a/CHANGELOG.md b/CHANGELOG.md index fd09fae9..ae94c782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,8 @@ Breaking changes are marked with ⚠️. - `name`, `absolute`, `ziggy`, `urlBuilder`, `template`, `urlParams`, `queryParams`, and `hydrated` - `normalizeParams()`, `hydrateUrl()`, `matchUrl()`, `constructQuery()`, `extractParams()`, `parse()`, and `trimParam()` - ⚠️ Remove the `UrlBuilder` class ([#330](https://github.com/tighten/ziggy/pull/330)) -- ⚠️ Remove the `url()` method now that `route(...)` returns a string ([#336](https://github.com/tighten/ziggy/pull/336)): +- ⚠️ Remove the `url()` method now that `route(...)` returns a string ([#336](https://github.com/tighten/ziggy/pull/336)) +- ⚠️ Remove the `baseDomain` and `baseProtocol` properties on the Ziggy config object ([#337](https://github.com/tighten/ziggy/pull/337)) **Fixed** diff --git a/README.md b/README.md index 0cacce98..1cbe5e7c 100644 --- a/README.md +++ b/README.md @@ -263,8 +263,6 @@ Route::get('/login', function () { var Ziggy = { namedRoutes: {"home":{"uri":"\/","methods":["GET","HEAD"],"domain":null},"login":{"uri":"login","methods":["GET","HEAD"],"domain":null}}, baseUrl: 'http://ziggy.test/', - baseProtocol: 'http', - baseDomain: 'ziggy.test', basePort: false }; diff --git a/src/Ziggy.php b/src/Ziggy.php index 26b882a2..e7ced410 100644 --- a/src/Ziggy.php +++ b/src/Ziggy.php @@ -10,9 +10,7 @@ class Ziggy implements JsonSerializable { - protected $baseDomain; protected $basePort; - protected $baseProtocol; protected $baseUrl; protected $group; protected $routes; @@ -22,12 +20,7 @@ public function __construct(string $group = null, string $url = null) $this->group = $group; $this->baseUrl = rtrim($url ?? config('app.url', url('/')), '/'); - - tap(parse_url($this->baseUrl), function ($url) { - $this->baseProtocol = $url['scheme'] ?? 'http'; - $this->baseDomain = $url['host'] ?? ''; - $this->basePort = $url['port'] ?? null; - }); + $this->basePort = parse_url($this->baseUrl)['port'] ?? null; $this->routes = $this->nameKeyedRoutes(); } @@ -136,8 +129,6 @@ public function toArray(): array { return [ 'baseUrl' => $this->baseUrl, - 'baseProtocol' => $this->baseProtocol, - 'baseDomain' => $this->baseDomain, 'basePort' => $this->basePort, 'defaultParameters' => method_exists(app('url'), 'getDefaultParameters') ? app('url')->getDefaultParameters() diff --git a/src/js/route.js b/src/js/route.js index 8807f09f..87f6a078 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -28,7 +28,7 @@ class Route { // If we're building just a path there's no origin, otherwise: if this route has a // domain configured we construct the origin with that, if not we use the app URL const origin = !this.config.absolute ? '' : this.definition.domain - ? `${this.config.baseProtocol}://${this.definition.domain}${this.config.basePort ? `:${this.config.basePort}` : ''}` + ? `${this.config.baseUrl.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.basePort ? `:${this.config.basePort}` : ''}` : this.config.baseUrl; return `${origin}/${this.definition.uri}`; diff --git a/tests/Unit/RouteModelBindingTest.php b/tests/Unit/RouteModelBindingTest.php index b388a7b2..0e0190f4 100644 --- a/tests/Unit/RouteModelBindingTest.php +++ b/tests/Unit/RouteModelBindingTest.php @@ -170,7 +170,7 @@ public function can_include_bindings_in_json() $this->markTestSkipped('Requires Laravel >=7'); } - $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; + $json = '{"baseUrl":"http:\/\/ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; $this->assertSame($json, (new Ziggy)->toJson()); } diff --git a/tests/Unit/ZiggyTest.php b/tests/Unit/ZiggyTest.php index 6cd96736..34525c78 100644 --- a/tests/Unit/ZiggyTest.php +++ b/tests/Unit/ZiggyTest.php @@ -392,8 +392,6 @@ public function route_payload_can_array_itself() $expected = [ 'baseUrl' => 'http://ziggy.dev', - 'baseProtocol' => 'http', - 'baseDomain' => 'ziggy.dev', 'basePort' => null, 'defaultParameters' => [], 'namedRoutes' => [ @@ -439,8 +437,6 @@ public function route_payload_can_json_itself() $expected = [ 'baseUrl' => 'http://ziggy.dev', - 'baseProtocol' => 'http', - 'baseDomain' => 'ziggy.dev', 'basePort' => null, 'defaultParameters' => [], 'namedRoutes' => [ @@ -453,7 +449,7 @@ public function route_payload_can_json_itself() $this->addPostCommentsRouteWithBindings($expected['namedRoutes']); - $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; + $json = '{"baseUrl":"http:\/\/ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; if ($this->laravelVersion(7)) { $json = str_replace( diff --git a/tests/fixtures/admin.js b/tests/fixtures/admin.js index 3bdf27f8..0ca98ce6 100644 --- a/tests/fixtures/admin.js +++ b/tests/fixtures/admin.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.namedRoutes) { diff --git a/tests/fixtures/custom-url.js b/tests/fixtures/custom-url.js index 7e57ae77..a87c5ee3 100644 --- a/tests/fixtures/custom-url.js +++ b/tests/fixtures/custom-url.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","basePort":null,"defaultParameters":{"locale":"en"},"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/example.org","basePort":null,"defaultParameters":{"locale":"en"},"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.namedRoutes) { diff --git a/tests/fixtures/ziggy.js b/tests/fixtures/ziggy.js index e9baec84..2060be70 100644 --- a/tests/fixtures/ziggy.js +++ b/tests/fixtures/ziggy.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.namedRoutes) { diff --git a/tests/js/route.test.js b/tests/js/route.test.js index d730231b..5317a91f 100644 --- a/tests/js/route.test.js +++ b/tests/js/route.test.js @@ -9,8 +9,6 @@ const defaultWindow = { const defaultZiggy = { baseUrl: 'https://ziggy.dev', - baseProtocol: 'https', - baseDomain: 'ziggy.dev', basePort: null, defaultParameters: { locale: 'en' }, namedRoutes: { @@ -345,7 +343,6 @@ describe('route()', () => { test('can generate a URL with a port', () => { global.Ziggy.baseUrl = 'https://ziggy.dev:81'; - global.Ziggy.baseDomain = 'ziggy.dev'; global.Ziggy.basePort = 81; // route with no parameters @@ -393,8 +390,6 @@ describe('route()', () => { test('can accept a custom Ziggy configuration object', () => { const config = { baseUrl: 'http://notYourAverage.dev', - baseProtocol: 'http', - baseDomain: 'notYourAverage.dev', basePort: false, defaultParameters: { locale: 'en' }, namedRoutes: { @@ -512,8 +507,6 @@ describe('current()', () => { const config = { baseUrl: 'https://ziggy.dev', - baseProtocol: 'https', - baseDomain: 'ziggy.dev', basePort: false, namedRoutes: { 'events.index': {