forked from potherca-blog/php-8-yet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
141 lines (109 loc) · 4.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!doctype html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" href="https://favicon.potherca.workers.dev/14">
<h1><title>PHP 8 yet?</title></h1>
<p>The easiest way to see if packages are on PHP 8 yet.</p>
<form class="package-form">
<fieldset class="packages-container">
</fieldset>
<button>Go!</button>
</form>
<template id="add-package-template">
<p>
<label>package <input name="package" placeholder="composer/composer"></label>
<a href="#" class="add-package" title="Add another package">(+)</a>
</p>
</template>
<footer class="created-by">
<p>
Source of this page is available on <a href="https://github.com/potherca-blog/php-8-yet/">Github</a> under a <a rel="license" href="https://spdx.org/licenses/MPL-2.0.html"
>Mozilla Public License 2.0</a> — Created by <a href="https://pother.ca/" class="potherca">Potherca</a>
</p>
</footer>
<style>
@import url(https://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans+Mono);
@import url(https://pother.ca/CssBase/css/created-by-potherca.css);
body {
font-family: Droid Sans,sans-serif;
}
code {
font-family: Droid Sans Mono,sans-serif;
}
title {
display: inline-block;
}
.active button {
display: none;
}
</style>
<script>
(_ => {
const packagesContainer = document.querySelector('.packages-container')
const template = document.getElementById('add-package-template')
const addPackageRow = _ => {
if (document.querySelector('.add-package')) {
document.querySelector('.add-package').remove()
}
const clone = template.content.cloneNode(true)
const link = clone.querySelector('a')
packagesContainer.appendChild(clone)
link.addEventListener('click', addPackageRow)
}
const encode = string => string.replace(/[\u00A0-\u9999<>&]/g, i => '&#' + i.charCodeAt(0) + ';')
window.addEventListener('DOMContentLoaded', (event) => {
const params = new URLSearchParams(document.location.search)
const subject = params.get('subject') || 'php'
const version = params.get('version') || '(\\b|^|~)8.0|>=[57]'
const branch = params.get('branch') || 'dev-master';
const regex = new RegExp(version)
const packages = document.location.search.substr(1)
.split('&')
.filter(value => value.startsWith('package='))
.map(value => decodeURIComponent(value.split('=')[1]))
.filter(value => value)
if (packages[0] === 'undefined' || packages.length === 0) {
addPackageRow()
packagesContainer.insertAdjacentHTML('afterbegin', `
<p>
<label>Dependency <input name="subject" value="${subject}"></label>
Should match
<label>version <input name="version" value="${version}"></label>
for
<label>branch <input name="branch" value="${branch}"></label>
in
</p>
`)
} else {
packagesContainer.parentElement.classList.add('active')
packages.forEach(packageName => {
const element = document.createElement('p')
packagesContainer.appendChild(element)
packageName = encode(packageName)
element.innerHTML = `Checking <code>${packageName}</code> ...`
fetch('https://packagist.org/packages/'+ packageName +'.json')
.then(response => response.ok ? response.json() : Promise.reject(response))
.then(data => {
const versionConstraint = data.package.versions[branch].require[subject]
if ( ! versionConstraint) {
throw `Package <code>${packageName}</code> does not require ${subject}`
}
element.innerHTML = ` <strong>${subject}</strong> (<code>${versionConstraint}<code>) for <code>${packageName}<code>`
if (versionConstraint.match(regex)) {
element.innerHTML = ` ✅ ${element.innerHTML} matches <code>${encode(version)}</code>`
} else {
element.innerHTML = ` ❌ ${element.innerHTML} does not match <code>${encode(version)}</code>`
}
})
.catch(error => {
if (error.status || error.statusText) {
error = `Could not fetch <code>${packageName}</code> ${error.status} ${error.statusText}`
}
element.innerHTML = `🚫 ${error}`
})
})
}
})
})()
</script>