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

Remove baseProtocol and baseDomain #337

Merged
merged 4 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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 `baseDomain` and `baseProtocol` properties on the Ziggy config object ([#337](https://github.com/tighten/ziggy/pull/337)):

**Fixed**

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
11 changes: 1 addition & 10 deletions src/Ziggy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class Ziggy implements JsonSerializable
{
protected $baseDomain;
protected $basePort;
protected $baseProtocol;
protected $baseUrl;
protected $group;
protected $routes;
Expand All @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanna make sure, same as the other PR, that this gets updated to $this->url in whatever order these PRs are merged. Not necessarily here, probably in #338, but don't wanna forget.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻


$this->routes = $this->nameKeyedRoutes();
}
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/js/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ''}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this.config.url

: this.config.baseUrl;

return `${origin}/${this.definition.uri}`;
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/RouteModelBindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
6 changes: 1 addition & 5 deletions tests/Unit/ZiggyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/admin.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/custom-url.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/ziggy.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
7 changes: 0 additions & 7 deletions tests/js/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const defaultWindow = {

const defaultZiggy = {
baseUrl: 'https://ziggy.dev',
baseProtocol: 'https',
baseDomain: 'ziggy.dev',
basePort: null,
defaultParameters: { locale: 'en' },
namedRoutes: {
Expand Down Expand Up @@ -353,7 +351,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
Expand Down Expand Up @@ -401,8 +398,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: {
Expand Down Expand Up @@ -520,8 +515,6 @@ describe('current()', () => {

const config = {
baseUrl: 'https://ziggy.dev',
baseProtocol: 'https',
baseDomain: 'ziggy.dev',
basePort: false,
namedRoutes: {
'events.index': {
Expand Down