Skip to content

Commit 1ce4aab

Browse files
committed
Add VuePress with UrlHelper component
1 parent f1b1083 commit 1ce4aab

File tree

6 files changed

+12647
-4
lines changed

6 files changed

+12647
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ composer.phar
33
composer.lock
44
/vendor/
55
/.php_cs.cache
6+
/node_modules/
7+
/docs/.vuepress/dist/
8+
/docs/README.md

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![PHP from Packagist](https://img.shields.io/packagist/php-v/swisnl/php-http-fixture-client.svg)](https://packagist.org/packages/swisnl/php-http-fixture-client)
44
[![Latest Version on Packagist](https://img.shields.io/packagist/v/swisnl/php-http-fixture-client.svg)](https://packagist.org/packages/swisnl/php-http-fixture-client)
5-
[![Software License](https://img.shields.io/packagist/l/swisnl/php-http-fixture-client.svg)](LICENSE)
5+
[![Software License](https://img.shields.io/packagist/l/swisnl/php-http-fixture-client.svg)](https://github.com/swisnl/php-http-fixture-client/LICENSE)
66
[![Run Status](https://api.shippable.com/projects/5a7d7deb260fde0600abe59e/badge?branch=master)](https://app.shippable.com/github/swisnl/php-http-fixture-client)
77
[![Coverage Badge](https://api.shippable.com/projects/5a7d7deb260fde0600abe59e/coverageBadge?branch=master)](https://app.shippable.com/github/swisnl/php-http-fixture-client)
88
[![Made by SWIS](https://img.shields.io/badge/%F0%9F%9A%80-made%20by%20SWIS-%23D9021B.svg)](https://www.swis.nl)
@@ -55,6 +55,9 @@ Please see the following table for some examples.
5555
| | | /path/to/fixtures/example.com/api/comments.get.mock |
5656
| | | /path/to/fixtures/example.com/api/comments.mock |
5757

58+
### Helper
59+
<UrlHelper>Please see <a href="https://swisnl.github.io/php-http-fixture-client/#helper">https://swisnl.github.io/php-http-fixture-client/#helper</a> for the URL helper.</UrlHelper>
60+
5861
### Body
5962

6063
The body of a request is loaded directly from a fixture with the file extension _.mock_.
@@ -80,7 +83,7 @@ If no _.status_ file is found, _200 OK_ will be used.
8083

8184
## Change log
8285

83-
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
86+
Please see [CHANGELOG](https://github.com/swisnl/php-http-fixture-client/CHANGELOG.md) for more information on what has changed recently.
8487

8588
## Testing
8689

@@ -90,15 +93,15 @@ $ composer test
9093

9194
## Contributing
9295

93-
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.
96+
Please see [CONTRIBUTING](https://github.com/swisnl/php-http-fixture-client/CONTRIBUTING.md) and [CODE_OF_CONDUCT](https://github.com/swisnl/php-http-fixture-client/CODE_OF_CONDUCT.md) for details.
9497

9598
## Security
9699

97100
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
98101

99102
## License
100103

101-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
104+
The MIT License (MIT). Please see [License File](https://github.com/swisnl/php-http-fixture-client/LICENSE.md) for more information.
102105

103106
## SWIS
104107

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
<template>
2+
<div>
3+
<p>Use this helper to generate the possible fixtures for your own URL.</p>
4+
<h4><label for="url">URL</label></h4>
5+
<input class="input" type="text" id="url" placeholder="http://example.com/api/comments?query=json&order=id" v-model="url"/>
6+
<h4><label for="method">Method</label></h4>
7+
<select class="select" id="method" v-model="method">
8+
<option value="get">GET</option>
9+
<option value="head">HEAD</option>
10+
<option value="post">POST</option>
11+
<option value="put">PUT</option>
12+
<option value="delete">DELETE</option>
13+
<option value="connect">CONNECT</option>
14+
<option value="options">OPTIONS</option>
15+
<option value="trace">TRACE</option>
16+
<option value="patch">PATCH</option>
17+
</select>
18+
<h4>Possible fixtures (in order of specificity)</h4>
19+
<ol v-if="fixtures.length">
20+
<li v-for="fixture in fixtures">/path/to/fixtures/{{ fixture }}</li>
21+
</ol>
22+
<p v-else>Please insert a valid URL!</p>
23+
</div>
24+
</template>
25+
26+
<script>
27+
const REPLACEMENT = '-';
28+
29+
const CHARS = {
30+
'0' : ['°', '', '۰', ''],
31+
'1' : ['¹', '', '۱', ''],
32+
'2' : ['²', '', '۲', ''],
33+
'3' : ['³', '', '۳', ''],
34+
'4' : ['', '', '۴', '٤', ''],
35+
'5' : ['', '', '۵', '٥', ''],
36+
'6' : ['', '', '۶', '٦', ''],
37+
'7' : ['', '', '۷', ''],
38+
'8' : ['', '', '۸', ''],
39+
'9' : ['', '', '۹', ''],
40+
'a' : ['à', 'á', '', 'ã', '', 'ă', '', '', '', '',
41+
'', 'â', '', '', '', '', '', 'ā', 'ą', 'å',
42+
'α', 'ά', '', '', '', '', '', '', '', '',
43+
'', '', '', '', '', '', '', '', '', 'ά',
44+
'', '', '', '', '', '', '', 'а', 'أ', '',
45+
'', '', 'ǻ', 'ǎ', 'ª', '', '', 'ا', '', 'ä'],
46+
'b' : ['б', 'β', 'ب', '', '', ''],
47+
'c' : ['ç', 'ć', 'č', 'ĉ', 'ċ', ''],
48+
'd' : ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', '', '', '',
49+
'д', 'δ', 'د', 'ض', '', '', '', ''],
50+
'e' : ['é', 'è', '', '', '', 'ê', 'ế', '', '', '',
51+
'', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', '',
52+
'', '', '', '', '', '', 'έ', 'е', 'ё', 'э',
53+
'є', 'ə', '', '', '', '', '', 'إ', 'ئ', ''],
54+
'f' : ['ф', 'φ', 'ف', 'ƒ', '', ''],
55+
'g' : ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', '', '', 'گ',
56+
''],
57+
'h' : ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', '', '', '', ''],
58+
'i' : ['í', 'ì', '', 'ĩ', '', 'î', 'ï', 'ī', 'ĭ', 'į',
59+
'ı', 'ι', 'ί', 'ϊ', 'ΐ', '', '', '', '', '',
60+
'', '', '', '', 'ί', '', '', '', 'ΐ', '',
61+
'', 'і', 'ї', 'и', '', '', '', 'ည်', 'ǐ', '',
62+
'', 'ی', ''],
63+
'j' : ['ĵ', 'ј', 'Ј', '', 'ج', ''],
64+
'k' : ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', '', '',
65+
'ک', ''],
66+
'l' : ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', '', '',
67+
''],
68+
'm' : ['м', 'μ', 'م', '', '', ''],
69+
'n' : ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', '',
70+
'', ''],
71+
'o' : ['ó', 'ò', '', 'õ', '', 'ô', '', '', '', '',
72+
'', 'ơ', '', '', '', '', '', 'ø', 'ō', 'ő',
73+
'ŏ', 'ο', '', '', '', '', '', '', '', 'ό',
74+
'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', '', '', '',
75+
'ö'],
76+
'p' : ['п', 'π', '', '', 'پ', ''],
77+
'q' : ['', ''],
78+
'r' : ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', '', ''],
79+
's' : ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', '',
80+
'ſ', '', ''],
81+
't' : ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', '', '', 'ŧ',
82+
'', '', ''],
83+
'u' : ['ú', 'ù', '', 'ũ', '', 'ư', '', '', '', '',
84+
'', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', '',
85+
'', '', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', '', '', '',
86+
'ў', 'ü'],
87+
'v' : ['в', '', 'ϐ', ''],
88+
'w' : ['ŵ', 'ω', 'ώ', '', '', ''],
89+
'x' : ['χ', 'ξ', ''],
90+
'y' : ['ý', '', '', '', '', 'ÿ', 'ŷ', 'й', 'ы', 'υ',
91+
'ϋ', 'ύ', 'ΰ', 'ي', '', ''],
92+
'z' : ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', '', '', ''],
93+
'aa' : ['ع', '', 'آ'],
94+
'ae' : ['æ', 'ǽ'],
95+
'ai' : [''],
96+
'ch' : ['ч', '', '', 'چ'],
97+
'dj' : ['ђ', 'đ'],
98+
'dz' : ['џ', ''],
99+
'ei' : [''],
100+
'gh' : ['غ', ''],
101+
'ii' : [''],
102+
'ij' : ['ij'],
103+
'kh' : ['х', 'خ', ''],
104+
'lj' : ['љ'],
105+
'nj' : ['њ'],
106+
'oe' : ['œ', 'ؤ'],
107+
'oi' : [''],
108+
'oii' : [''],
109+
'ps' : ['ψ'],
110+
'sh' : ['ш', '', 'ش'],
111+
'shch' : ['щ'],
112+
'ss' : ['ß'],
113+
'sx' : ['ŝ'],
114+
'th' : ['þ', 'ϑ', 'ث', 'ذ', 'ظ'],
115+
'ts' : ['ц', '', ''],
116+
'uu' : [''],
117+
'ya' : ['я'],
118+
'yu' : ['ю'],
119+
'zh' : ['ж', '', 'ژ'],
120+
'(c)' : ['©'],
121+
'A' : ['Á', 'À', '', 'Ã', '', 'Ă', '', '', '', '',
122+
'', 'Â', '', '', '', '', '', 'Å', 'Ā', 'Ą',
123+
'Α', 'Ά', '', '', '', '', '', '', '', '',
124+
'', '', '', '', '', '', '', '', '', '',
125+
'', 'Ά', '', 'А', 'Ǻ', 'Ǎ', '', 'Ä'],
126+
'B' : ['Б', 'Β', '', ''],
127+
'C' : ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ', ''],
128+
'D' : ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', '', '', 'Д', 'Δ',
129+
''],
130+
'E' : ['É', 'È', '', '', '', 'Ê', '', '', '', '',
131+
'', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', '',
132+
'', '', '', '', '', 'Έ', '', 'Е', 'Ё', 'Э',
133+
'Є', 'Ə', ''],
134+
'F' : ['Ф', 'Φ', ''],
135+
'G' : ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ', ''],
136+
'H' : ['Η', 'Ή', 'Ħ', ''],
137+
'I' : ['Í', 'Ì', '', 'Ĩ', '', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į',
138+
'İ', 'Ι', 'Ί', 'Ϊ', '', '', '', '', '', '',
139+
'Ἷ', '', '', '', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ',
140+
''],
141+
'J' : [''],
142+
'K' : ['К', 'Κ', ''],
143+
'L' : ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', '', ''],
144+
'M' : ['М', 'Μ', ''],
145+
'N' : ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν', ''],
146+
'O' : ['Ó', 'Ò', '', 'Õ', '', 'Ô', '', '', '', '',
147+
'', 'Ơ', '', '', '', '', '', 'Ø', 'Ō', 'Ő',
148+
'Ŏ', 'Ο', 'Ό', '', '', '', '', '', '', '',
149+
'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ', '', 'Ö'],
150+
'P' : ['П', 'Π', ''],
151+
'Q' : [''],
152+
'R' : ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ', ''],
153+
'S' : ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ', ''],
154+
'T' : ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ', ''],
155+
'U' : ['Ú', 'Ù', '', 'Ũ', '', 'Ư', '', '', '', '',
156+
'', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ',
157+
'Ǘ', 'Ǚ', 'Ǜ', '', 'Ў', 'Ü'],
158+
'V' : ['В', ''],
159+
'W' : ['Ω', 'Ώ', 'Ŵ', ''],
160+
'X' : ['Χ', 'Ξ', ''],
161+
'Y' : ['Ý', '', '', '', '', 'Ÿ', '', '', '', 'Ύ',
162+
'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ', ''],
163+
'Z' : ['Ź', 'Ž', 'Ż', 'З', 'Ζ', ''],
164+
'AE' : ['Æ', 'Ǽ'],
165+
'Ch' : ['Ч'],
166+
'Dj' : ['Ђ'],
167+
'Dz' : ['Џ'],
168+
'Gx' : ['Ĝ'],
169+
'Hx' : ['Ĥ'],
170+
'Ij' : ['IJ'],
171+
'Jx' : ['Ĵ'],
172+
'Kh' : ['Х'],
173+
'Lj' : ['Љ'],
174+
'Nj' : ['Њ'],
175+
'Oe' : ['Œ'],
176+
'Ps' : ['Ψ'],
177+
'Sh' : ['Ш'],
178+
'Shch' : ['Щ'],
179+
'Ss' : [''],
180+
'Th' : ['Þ'],
181+
'Ts' : ['Ц'],
182+
'Ya' : ['Я'],
183+
'Yu' : ['Ю'],
184+
'Zh' : ['Ж'],
185+
' ' : ['\xC2\xA0', '\xE2\x80\x80', '\xE2\x80\x81',
186+
'\xE2\x80\x82', '\xE2\x80\x83', '\xE2\x80\x84',
187+
'\xE2\x80\x85', '\xE2\x80\x86', '\xE2\x80\x87',
188+
'\xE2\x80\x88', '\xE2\x80\x89', '\xE2\x80\x8A',
189+
'\xE2\x80\xAF', '\xE2\x81\x9F', '\xE3\x80\x80',
190+
'\xEF\xBE\xA0'],
191+
};
192+
193+
export default {
194+
name: 'MapUrl',
195+
196+
data() {
197+
return {
198+
url: '',
199+
method: 'get'
200+
};
201+
},
202+
203+
computed: {
204+
fixtures() {
205+
let fixtures = [];
206+
let url;
207+
208+
try {
209+
url = new URL(this.url);
210+
} catch (e) {
211+
return fixtures;
212+
}
213+
214+
let searchParams = Array.from(url.searchParams.entries());
215+
if (searchParams.length) {
216+
const search = this.formatSearchParams(searchParams);
217+
fixtures.push(`${url.hostname}${url.pathname}.${search}.${this.method}.mock`);
218+
fixtures.push(`${url.hostname}${url.pathname}.${search}.mock`);
219+
}
220+
221+
fixtures.push(`${url.hostname}${url.pathname}.${this.method}.mock`);
222+
fixtures.push(`${url.hostname}${url.pathname}.mock`);
223+
224+
return fixtures;
225+
}
226+
},
227+
228+
methods: {
229+
formatSearchParams(searchParams) {
230+
return [...searchParams]
231+
.sort((a, b) => {
232+
if (a[0] > b[0]) {
233+
return 1;
234+
} else if (a[0] < b[0]) {
235+
return -1;
236+
}
237+
238+
return 0;
239+
})
240+
.map(param => {
241+
return param[1] ? `${param[0]}=${param[1]}` : param[0];
242+
})
243+
// replacements
244+
.map(param => {
245+
return param.replace(/[\\/?:*"><|]/g, REPLACEMENT);
246+
})
247+
// toAscii
248+
.map(param => {
249+
Object.keys(CHARS).forEach(key => {
250+
param = param.replace(new RegExp(`[${CHARS[key].join('')}]`, 'g'), key);
251+
});
252+
253+
return param.replace(/[^\x20-\x7E]/gu, '');
254+
})
255+
// delimit
256+
.map(param => {
257+
return param.replace(/\B([A-Z])/g, '-$1')
258+
.toLowerCase()
259+
.replace(/[-_\s]+/g, REPLACEMENT);
260+
})
261+
// removeLeft
262+
.map(param => {
263+
return param.replace(new RegExp(`^${REPLACEMENT}+`), '');
264+
})
265+
// removeRight
266+
.map(param => {
267+
return param.replace(new RegExp(`${REPLACEMENT}+$`), '');
268+
})
269+
.join('&');
270+
}
271+
}
272+
}
273+
</script>
274+
275+
<style scoped>
276+
.input,
277+
.select {
278+
border-radius: 2rem;
279+
border: 1px solid #cfd4db;
280+
box-sizing: border-box;
281+
color: #4e6e8e;
282+
display: inline-block;
283+
font-size: 0.9rem;
284+
height: 2rem;
285+
line-height: 2rem;
286+
outline: none;
287+
transition: all 0.2s ease;
288+
width: 100%;
289+
}
290+
291+
.input {
292+
cursor: text;
293+
padding: 0 1rem;
294+
}
295+
296+
.select {
297+
height: 2rem;
298+
padding: 0 1rem;
299+
}
300+
</style>

docs/.vuepress/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
title: 'swisnl/php-http-fixture-client',
3+
description: 'Fixture client for PHP-HTTP',
4+
base: '/php-http-fixture-client/',
5+
themeConfig: {
6+
repo: 'swisnl/php-http-fixture-client',
7+
editLinks: true,
8+
}
9+
};

0 commit comments

Comments
 (0)