-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config object which controls what kind of urls are generated. The lib supports now to only generate relative urls or only absolute urls. Change tests accordingly to fit new api
- Loading branch information
Showing
12 changed files
with
189 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,4 +77,5 @@ composer.phar | |
.phpunit.result.cache | ||
vendor | ||
node_modules/ | ||
.idea/ | ||
.idea/ | ||
.phpunit.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bolzer\SymfonyTypescriptRoutes\Dto; | ||
|
||
class GeneratorConfig | ||
{ | ||
private function __construct( | ||
private bool $generateAbsoluteUrls, | ||
private bool $generateRelativeUrls, | ||
) { | ||
} | ||
|
||
public static function generateOnlyRelativeUrls(): self | ||
{ | ||
return new self( | ||
generateAbsoluteUrls: false, | ||
generateRelativeUrls: true, | ||
); | ||
} | ||
|
||
public static function generateOnlyAbsoluteUrls(): self | ||
{ | ||
return new self( | ||
generateAbsoluteUrls: true, | ||
generateRelativeUrls: false, | ||
); | ||
} | ||
|
||
public static function generateEverything(): self | ||
{ | ||
return new self( | ||
generateAbsoluteUrls: true, | ||
generateRelativeUrls: true, | ||
); | ||
} | ||
|
||
public function isGenerateAbsoluteUrls(): bool | ||
{ | ||
return $this->generateAbsoluteUrls; | ||
} | ||
|
||
public function isGenerateRelativeUrls(): bool | ||
{ | ||
return $this->generateRelativeUrls; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const rRP = (rawRoute: string, routeParams: Record<string, string>): string => {Object.entries(routeParams).forEach(([key, value]) => rawRoute = rawRoute.replace(`{${key}}`, value)); return rawRoute;} | ||
const aQP = (route: string, queryParams?: Record<string, string>): string => queryParams ? route + "?" + new URLSearchParams(queryParams).toString() : route; | ||
export const path_user_route = ():{ relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string, absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string} => {return {relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('/user/{id}/notes/{noteId}', routeParams), queryParams), absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('https://app.development.org/user/{id}/notes/{noteId}', routeParams), queryParams)}}; | ||
export const path_users_route = ():{ relative: (queryParams?: Record<string, string>) => string, absolute: (queryParams?: Record<string, string>) => string} => {return {relative: (queryParams?: Record<string, string>): string => aQP('/users', queryParams), absolute: (queryParams?: Record<string, string>): string => aQP('https://app.development.org/users', queryParams)}}; | ||
export const path_user_route = (): { relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string, absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string} => {return {relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('/user/{id}/notes/{noteId}', routeParams), queryParams), absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('https://app.development.org/user/{id}/notes/{noteId}', routeParams), queryParams)}}; | ||
export const path_user_route_http = (): { relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string, absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string} => {return {relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('/user/{id}/notes/{noteId}', routeParams), queryParams), absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('http://app.development.org/user/{id}/notes/{noteId}', routeParams), queryParams)}}; | ||
export const path_users_route = (): { relative: (queryParams?: Record<string, string>) => string, absolute: (queryParams?: Record<string, string>) => string} => {return {relative: (queryParams?: Record<string, string>): string => aQP('/users', queryParams), absolute: (queryParams?: Record<string, string>): string => aQP('https://app.development.org/users', queryParams)}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {path_user_route} from "./output_absolute"; | ||
|
||
test('test path_user_route absolute route', () => { | ||
const result1 = path_user_route().absolute({id: "exampleID", noteId: "exampleNoteID"}) | ||
expect(result1).toBe('https://app.development.org/user/exampleID/notes/exampleNoteID'); | ||
|
||
const result2 = path_user_route().absolute({id: "exampleID", noteId: "exampleNoteID"}, {count: "20", page: "3"}) | ||
expect(result2).toBe('https://app.development.org/user/exampleID/notes/exampleNoteID?count=20&page=3'); | ||
}); | ||
|
||
test('test specific generation of only absolute routes', () => { | ||
const routeObject = path_user_route(); | ||
|
||
expect(routeObject).toHaveProperty("absolute"); | ||
expect(routeObject).not.toHaveProperty("relative"); | ||
expect(Object.keys(routeObject).length).toBe(1) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const rRP = (rawRoute: string, routeParams: Record<string, string>): string => {Object.entries(routeParams).forEach(([key, value]) => rawRoute = rawRoute.replace(`{${key}}`, value)); return rawRoute;} | ||
const aQP = (route: string, queryParams?: Record<string, string>): string => queryParams ? route + "?" + new URLSearchParams(queryParams).toString() : route; | ||
export const path_user_route = (): { absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string} => {return {absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('https://app.development.org/user/{id}/notes/{noteId}', routeParams), queryParams)}}; | ||
export const path_user_route_http = (): { absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string} => {return {absolute: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('http://app.development.org/user/{id}/notes/{noteId}', routeParams), queryParams)}}; | ||
export const path_users_route = (): { absolute: (queryParams?: Record<string, string>) => string} => {return {absolute: (queryParams?: Record<string, string>): string => aQP('https://app.development.org/users', queryParams)}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {path_user_route} from "./output_relative"; | ||
|
||
test('test path_user_route relative route', () => { | ||
const result1 = path_user_route().relative({id: "exampleID", noteId: "exampleNoteID"}) | ||
expect(result1).toBe('/user/exampleID/notes/exampleNoteID'); | ||
|
||
const result2 = path_user_route().relative({id: "exampleID", noteId: "exampleNoteID"}, {count: "20", page: "3"}) | ||
expect(result2).toBe('/user/exampleID/notes/exampleNoteID?count=20&page=3'); | ||
}); | ||
|
||
test('test specific generation of only relative routes', () => { | ||
const routeObject = path_user_route(); | ||
|
||
expect(routeObject).toHaveProperty("relative"); | ||
expect(routeObject).not.toHaveProperty("absolute"); | ||
expect(Object.keys(routeObject).length).toBe(1) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const rRP = (rawRoute: string, routeParams: Record<string, string>): string => {Object.entries(routeParams).forEach(([key, value]) => rawRoute = rawRoute.replace(`{${key}}`, value)); return rawRoute;} | ||
const aQP = (route: string, queryParams?: Record<string, string>): string => queryParams ? route + "?" + new URLSearchParams(queryParams).toString() : route; | ||
export const path_user_route = (): { relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string, } => {return {relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('/user/{id}/notes/{noteId}', routeParams), queryParams), }}; | ||
export const path_user_route_http = (): { relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>) => string, } => {return {relative: (routeParams: {id: string, noteId: string}, queryParams?: Record<string, string>): string => aQP(rRP('/user/{id}/notes/{noteId}', routeParams), queryParams), }}; | ||
export const path_users_route = (): { relative: (queryParams?: Record<string, string>) => string, } => {return {relative: (queryParams?: Record<string, string>): string => aQP('/users', queryParams), }}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters