@vituum/vite-plugin-latte 1.3.0 → 2.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/handler-single.js +4 -1
- package/handler.js +27 -24
- package/index.js +140 -135
- package/index.php +2 -0
- package/package.json +14 -10
- package/vendor/composer/InstalledVersions.php +7 -4
- package/vendor/composer/autoload_classmap.php +1 -0
- package/vendor/composer/autoload_static.php +1 -0
- package/vendor/composer/installed.json +7 -7
- package/vendor/composer/installed.php +5 -5
- package/vendor/nette/utils/src/Utils/Arrays.php +2 -1
- package/vendor/nette/utils/src/Utils/FileSystem.php +15 -2
- package/vendor/nette/utils/src/Utils/Finder.php +1 -1
- package/vendor/nette/utils/src/Utils/Helpers.php +3 -0
- package/vendor/nette/utils/src/Utils/Image.php +21 -36
- package/vendor/nette/utils/src/Utils/Iterables.php +1 -0
- package/vendor/nette/utils/src/Utils/Reflection.php +2 -2
- package/vendor/nette/utils/src/Utils/Strings.php +1 -2
- package/vendor/nette/utils/src/Utils/Type.php +2 -2
- package/vendor/nette/utils/src/Utils/exceptions.php +5 -5
- package/vendor/nette/utils/src/exceptions.php +20 -15
package/handler-single.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import { Buffer } from 'node:buffer'
|
|
3
|
+
|
|
1
4
|
let params = JSON.parse(process.argv[3])
|
|
2
5
|
const path = process.argv[2]
|
|
3
6
|
|
|
@@ -6,5 +9,5 @@ params = params.map(value => Buffer.from(value, 'base64').toString('utf-8'))
|
|
|
6
9
|
const output = await (await import([path])).default(...params)
|
|
7
10
|
|
|
8
11
|
if (output) {
|
|
9
|
-
|
|
12
|
+
console.log(Buffer.from(output.toString(), 'utf-8').toString('base64'))
|
|
10
13
|
}
|
package/handler.js
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
1
|
import { resolve } from 'node:path'
|
|
2
2
|
import fs from 'node:fs'
|
|
3
|
+
import process from 'node:process'
|
|
4
|
+
import { Buffer } from 'node:buffer'
|
|
3
5
|
|
|
4
|
-
function find
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
6
|
+
function find(obj) {
|
|
7
|
+
if (typeof obj === 'object') {
|
|
8
|
+
if (obj.name === '@vituum/vite-plugin-latte') {
|
|
9
|
+
return obj
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
for (const key in obj) {
|
|
13
|
+
const result = find(obj[key])
|
|
14
|
+
|
|
15
|
+
if (result !== null) {
|
|
16
|
+
return result
|
|
16
17
|
}
|
|
18
|
+
}
|
|
17
19
|
}
|
|
20
|
+
}
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
return null
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
const DEFAULT_CONFIG_FILES = [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
'vite.config.js',
|
|
27
|
+
'vite.config.mjs',
|
|
28
|
+
'vite.config.ts',
|
|
29
|
+
'vite.config.cjs',
|
|
30
|
+
'vite.config.mts',
|
|
31
|
+
'vite.config.cts',
|
|
29
32
|
]
|
|
30
33
|
|
|
31
34
|
let resolvedPath
|
|
32
35
|
|
|
33
36
|
for (const filename of DEFAULT_CONFIG_FILES) {
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
const filePath = resolve(process.cwd(), filename)
|
|
38
|
+
if (!fs.existsSync(filePath)) continue
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
resolvedPath = filePath
|
|
41
|
+
break
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
const vite = (await import(resolvedPath)).default
|
|
@@ -48,5 +51,5 @@ params = params.map(value => Buffer.from(value, 'base64').toString('utf-8'))
|
|
|
48
51
|
const output = await find(vite.plugins)._options[type][name](...params)
|
|
49
52
|
|
|
50
53
|
if (output) {
|
|
51
|
-
|
|
54
|
+
console.log(Buffer.from(output.toString(), 'utf-8').toString('base64'))
|
|
52
55
|
}
|
package/index.js
CHANGED
|
@@ -6,13 +6,13 @@ import * as childProcess from 'node:child_process'
|
|
|
6
6
|
import FastGlob from 'fast-glob'
|
|
7
7
|
import { minimatch } from 'minimatch'
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
getPackageInfo,
|
|
10
|
+
pluginError,
|
|
11
|
+
pluginReload,
|
|
12
|
+
merge,
|
|
13
|
+
pluginBundle,
|
|
14
|
+
normalizePath,
|
|
15
|
+
pluginMiddleware,
|
|
16
16
|
} from 'vituum/utils/common.js'
|
|
17
17
|
import { renameBuildEnd, renameBuildStart } from 'vituum/utils/build.js'
|
|
18
18
|
|
|
@@ -22,70 +22,71 @@ const { name } = getPackageInfo(import.meta.url)
|
|
|
22
22
|
* @type {import('@vituum/vite-plugin-latte/types').PluginUserConfig} options
|
|
23
23
|
*/
|
|
24
24
|
const defaultOptions = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
reload: true,
|
|
26
|
+
root: null,
|
|
27
|
+
filters: {},
|
|
28
|
+
functions: {},
|
|
29
|
+
tags: {},
|
|
30
|
+
globals: {
|
|
31
|
+
format: 'latte',
|
|
32
|
+
},
|
|
33
|
+
data: ['src/data/**/*.json'],
|
|
34
|
+
formats: ['latte', 'json.latte', 'json'],
|
|
35
|
+
bin: 'php',
|
|
36
|
+
renderTransformedHtml: () => false,
|
|
37
|
+
ignoredPaths: [],
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const execSync = (cmd) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
try {
|
|
42
|
+
return {
|
|
43
|
+
output: childProcess.execSync(cmd).toString(),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch ({ output }) {
|
|
47
|
+
return {
|
|
48
|
+
error: true,
|
|
49
|
+
output: output[1].toString(),
|
|
50
50
|
}
|
|
51
|
+
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
const renderTemplate = ({ server, path, filename, cwd, packageRoot }, options, content) => {
|
|
54
|
-
|
|
54
|
+
const renderTemplate = ({ server, path, filename, cwd, packageRoot, viteServer }, options, content) => {
|
|
55
|
+
const renderTransformedHtml = options.renderTransformedHtml(server ? filename.replace('.html', '') : filename)
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
if (options.data) {
|
|
58
|
+
const normalizePaths = Array.isArray(options.data) ? options.data.map(path => normalizePath(path)) : normalizePath(options.data)
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
Object.keys(options.filters).forEach(key => {
|
|
63
|
-
if (typeof options.filters[key] === 'function') {
|
|
64
|
-
options.filters[key] = options.filters[key].toString().match(/\(\s*([^)]+?)\s*\)/)[1].replace(/\s/g, '').split(',')
|
|
65
|
-
}
|
|
66
|
-
})
|
|
60
|
+
options.data = FastGlob.sync(normalizePaths).map(entry => resolve(cwd, entry))
|
|
61
|
+
}
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
Object.keys(options.filters).forEach((key) => {
|
|
64
|
+
if (typeof options.filters[key] === 'function') {
|
|
65
|
+
options.filters[key] = options.filters[key].toString().match(/\(\s*([^)]+?)\s*\)/)[1].replace(/\s/g, '').split(',')
|
|
66
|
+
}
|
|
67
|
+
})
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
Object.keys(options.functions).forEach((key) => {
|
|
70
|
+
if (typeof options.functions[key] === 'function') {
|
|
71
|
+
options.functions[key] = options.functions[key].toString().match(/\(\s*([^)]+?)\s*\)/)[1].replace(/\s/g, '').split(',')
|
|
72
|
+
}
|
|
73
|
+
})
|
|
76
74
|
|
|
77
|
-
|
|
75
|
+
if (renderTransformedHtml) {
|
|
76
|
+
const timestamp = Math.floor(Date.now() * Math.random())
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
fs.mkdirSync(resolve(packageRoot, 'temp'))
|
|
81
|
-
}
|
|
78
|
+
options.contentTimestamp = timestamp
|
|
82
79
|
|
|
83
|
-
|
|
80
|
+
if (!fs.existsSync(resolve(packageRoot, 'temp'))) {
|
|
81
|
+
fs.mkdirSync(resolve(packageRoot, 'temp'))
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
|
|
84
|
+
fs.writeFileSync(resolve(packageRoot, `temp/${timestamp}.html`), content)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const data = Object.assign({ packageRoot, cwd, isRenderTransformedHtml: renderTransformedHtml, viteServer }, options)
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
return execSync(`${options.bin} ${packageRoot}/index.php ${join(options.root, server ? path.replace('.html', '') : path)} ${JSON.stringify(JSON.stringify(data))}`)
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
/**
|
|
@@ -93,91 +94,95 @@ const renderTemplate = ({ server, path, filename, cwd, packageRoot }, options, c
|
|
|
93
94
|
* @returns [import('vite').Plugin]
|
|
94
95
|
*/
|
|
95
96
|
const plugin = (options = {}) => {
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
let resolvedConfig
|
|
98
|
+
let userEnv
|
|
98
99
|
|
|
99
|
-
|
|
100
|
+
options = merge(defaultOptions, options)
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
const cwd = process.cwd()
|
|
103
|
+
const packageRoot = dirname((fileURLToPath(import.meta.url)))
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
if (fs.existsSync(resolve(packageRoot, 'temp'))) {
|
|
106
|
+
fs.rmSync(resolve(packageRoot, 'temp'), { recursive: true, force: true })
|
|
107
|
+
}
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
if (options.bin === 'docker') {
|
|
110
|
+
options.bin = `docker run --rm --name index -v "${process.cwd()}":/usr/src/app -w /usr/src/app php:8-cli php`
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return [{
|
|
114
|
+
_options: options,
|
|
115
|
+
name,
|
|
116
|
+
config(userConfig, env) {
|
|
117
|
+
userEnv = env
|
|
118
|
+
},
|
|
119
|
+
configResolved(config) {
|
|
120
|
+
resolvedConfig = config
|
|
121
|
+
|
|
122
|
+
if (!options.root) {
|
|
123
|
+
options.root = config.root
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
options.root = normalizePath(options.root)
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
buildStart: async () => {
|
|
130
|
+
if (userEnv.command !== 'build' || !resolvedConfig.build.rollupOptions.input) {
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
await renameBuildStart(resolvedConfig.build.rollupOptions.input, options.formats)
|
|
135
|
+
},
|
|
136
|
+
buildEnd: async () => {
|
|
137
|
+
if (userEnv.command !== 'build' || !resolvedConfig.build.rollupOptions.input) {
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
await renameBuildEnd(resolvedConfig.build.rollupOptions.input, options.formats)
|
|
142
|
+
},
|
|
143
|
+
transformIndexHtml: {
|
|
144
|
+
order: 'pre',
|
|
145
|
+
async handler(content, { path, filename, server }) {
|
|
146
|
+
if (options.ignoredPaths.find(ignoredPath => minimatch(path.replace('.html', ''), ignoredPath) === true)) {
|
|
147
|
+
return content
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
!options.formats.find(format => filename.replace('.html', '').endsWith(format))
|
|
152
|
+
|| (filename.replace('.html', '').endsWith('.json') && !content.startsWith('{'))
|
|
153
|
+
) {
|
|
154
|
+
return content
|
|
155
|
+
}
|
|
111
156
|
|
|
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
|
-
transformIndexHtml: {
|
|
142
|
-
order: 'pre',
|
|
143
|
-
async handler (content, { path, filename, server }) {
|
|
144
|
-
if (options.ignoredPaths.find(ignoredPath => minimatch(path.replace('.html', ''), ignoredPath) === true)) {
|
|
145
|
-
return content
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
!options.formats.find(format => filename.replace('.html', '').endsWith(format)) ||
|
|
150
|
-
(filename.replace('.html', '').endsWith('.json') && !content.startsWith('{'))
|
|
151
|
-
) {
|
|
152
|
-
return content
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
(filename.replace('.html', '').endsWith('.json') && content.startsWith('{')) &&
|
|
157
|
-
(JSON.parse(content)?.format && !options.formats.includes(JSON.parse(content)?.format))
|
|
158
|
-
) {
|
|
159
|
-
return content
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const render = renderTemplate({ server, path, filename, cwd, packageRoot }, options, content)
|
|
163
|
-
const warningLog = render.output.includes('Warning: Undefined')
|
|
164
|
-
|
|
165
|
-
if (render.error || warningLog) {
|
|
166
|
-
const message = warningLog ? 'Warning: Undefined' + render.output.split('Warning: Undefined').pop() : render.output
|
|
167
|
-
const renderError = pluginError(message, server, name)
|
|
168
|
-
|
|
169
|
-
if (renderError && server) {
|
|
170
|
-
return
|
|
171
|
-
} else if (renderError) {
|
|
172
|
-
return renderError
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return render.output
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
handleHotUpdate: ({ file, server }) => pluginReload({ file, server }, options)
|
|
180
|
-
}, pluginBundle(options.formats), pluginMiddleware(name, options.formats)]
|
|
157
|
+
if (
|
|
158
|
+
(filename.replace('.html', '').endsWith('.json') && content.startsWith('{'))
|
|
159
|
+
&& (JSON.parse(content)?.format && !options.formats.includes(JSON.parse(content)?.format))
|
|
160
|
+
) {
|
|
161
|
+
return content
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const viteServer = !!server
|
|
165
|
+
|
|
166
|
+
const render = renderTemplate({ server, path, filename, cwd, packageRoot, viteServer }, options, content)
|
|
167
|
+
const warningLog = render.output.includes('Warning: Undefined')
|
|
168
|
+
|
|
169
|
+
if (render.error || warningLog) {
|
|
170
|
+
const message = warningLog ? 'Warning: Undefined' + render.output.split('Warning: Undefined').pop() : render.output
|
|
171
|
+
const renderError = pluginError(message, server, name)
|
|
172
|
+
|
|
173
|
+
if (renderError && server) {
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
else if (renderError) {
|
|
177
|
+
return renderError
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return render.output
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
handleHotUpdate: ({ file, server }) => pluginReload({ file, server }, options),
|
|
185
|
+
}, pluginBundle(options.formats), pluginMiddleware(name, options.formats)]
|
|
181
186
|
}
|
|
182
187
|
|
|
183
188
|
export default plugin
|
package/index.php
CHANGED
package/package.json
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vituum/vite-plugin-latte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"tsc": "tsc",
|
|
9
|
-
"eslint": "eslint '**/*.js'
|
|
9
|
+
"eslint": "eslint '**/*.js'",
|
|
10
|
+
"eslint-fix": "eslint '**/*.js' --fix",
|
|
10
11
|
"dev": "vite dev",
|
|
11
12
|
"build": "vite build",
|
|
12
|
-
"preview": "vite preview"
|
|
13
|
+
"preview": "vite preview",
|
|
14
|
+
"publish-next": "npm publish --tag next"
|
|
13
15
|
},
|
|
14
16
|
"dependencies": {
|
|
15
|
-
"vituum": "^
|
|
17
|
+
"vituum": "^2.0.0-next.1",
|
|
16
18
|
"fast-glob": "^3.3",
|
|
17
19
|
"lodash": "^4.17",
|
|
18
|
-
"minimatch": "^10.
|
|
20
|
+
"minimatch": "^10.1"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
23
|
+
"@eslint/js": "^9.39",
|
|
24
|
+
"@stylistic/eslint-plugin": "^5.6",
|
|
25
|
+
"@types/node": "^25",
|
|
26
|
+
"vite": "^8.0.0-beta.3",
|
|
27
|
+
"eslint": "^9.39",
|
|
28
|
+
"globals": "^16.5",
|
|
29
|
+
"typescript": "^5.9"
|
|
26
30
|
},
|
|
27
31
|
"files": [
|
|
28
32
|
"index.js",
|
|
@@ -322,6 +322,7 @@ class InstalledVersions
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
$installed = array();
|
|
325
|
+
$copiedLocalDir = false;
|
|
325
326
|
|
|
326
327
|
if (self::$canGetVendors) {
|
|
327
328
|
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
|
|
@@ -330,9 +331,11 @@ class InstalledVersions
|
|
|
330
331
|
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
|
331
332
|
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
|
332
333
|
$required = require $vendorDir.'/composer/installed.php';
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
334
|
+
self::$installedByVendor[$vendorDir] = $required;
|
|
335
|
+
$installed[] = $required;
|
|
336
|
+
if (strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
|
337
|
+
self::$installed = $required;
|
|
338
|
+
$copiedLocalDir = true;
|
|
336
339
|
}
|
|
337
340
|
}
|
|
338
341
|
}
|
|
@@ -350,7 +353,7 @@ class InstalledVersions
|
|
|
350
353
|
}
|
|
351
354
|
}
|
|
352
355
|
|
|
353
|
-
if (self::$installed !== array()) {
|
|
356
|
+
if (self::$installed !== array() && !$copiedLocalDir) {
|
|
354
357
|
$installed[] = self::$installed;
|
|
355
358
|
}
|
|
356
359
|
|
|
@@ -204,6 +204,7 @@ return array(
|
|
|
204
204
|
'Nette\\NotImplementedException' => $vendorDir . '/nette/utils/src/exceptions.php',
|
|
205
205
|
'Nette\\NotSupportedException' => $vendorDir . '/nette/utils/src/exceptions.php',
|
|
206
206
|
'Nette\\OutOfRangeException' => $vendorDir . '/nette/utils/src/exceptions.php',
|
|
207
|
+
'Nette\\ShouldNotHappenException' => $vendorDir . '/nette/utils/src/exceptions.php',
|
|
207
208
|
'Nette\\SmartObject' => $vendorDir . '/nette/utils/src/SmartObject.php',
|
|
208
209
|
'Nette\\StaticClass' => $vendorDir . '/nette/utils/src/StaticClass.php',
|
|
209
210
|
'Nette\\UnexpectedValueException' => $vendorDir . '/nette/utils/src/exceptions.php',
|
|
@@ -205,6 +205,7 @@ class ComposerStaticInit8535741375194e2773348db6a0091487
|
|
|
205
205
|
'Nette\\NotImplementedException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
|
|
206
206
|
'Nette\\NotSupportedException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
|
|
207
207
|
'Nette\\OutOfRangeException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
|
|
208
|
+
'Nette\\ShouldNotHappenException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
|
|
208
209
|
'Nette\\SmartObject' => __DIR__ . '/..' . '/nette/utils/src/SmartObject.php',
|
|
209
210
|
'Nette\\StaticClass' => __DIR__ . '/..' . '/nette/utils/src/StaticClass.php',
|
|
210
211
|
'Nette\\UnexpectedValueException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
|
|
@@ -91,17 +91,17 @@
|
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
93
|
"name": "nette/utils",
|
|
94
|
-
"version": "v4.0.
|
|
95
|
-
"version_normalized": "4.0.
|
|
94
|
+
"version": "v4.0.6",
|
|
95
|
+
"version_normalized": "4.0.6.0",
|
|
96
96
|
"source": {
|
|
97
97
|
"type": "git",
|
|
98
98
|
"url": "https://github.com/nette/utils.git",
|
|
99
|
-
"reference": "
|
|
99
|
+
"reference": "ce708655043c7050eb050df361c5e313cf708309"
|
|
100
100
|
},
|
|
101
101
|
"dist": {
|
|
102
102
|
"type": "zip",
|
|
103
|
-
"url": "https://api.github.com/repos/nette/utils/zipball/
|
|
104
|
-
"reference": "
|
|
103
|
+
"url": "https://api.github.com/repos/nette/utils/zipball/ce708655043c7050eb050df361c5e313cf708309",
|
|
104
|
+
"reference": "ce708655043c7050eb050df361c5e313cf708309",
|
|
105
105
|
"shasum": ""
|
|
106
106
|
},
|
|
107
107
|
"require": {
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"ext-mbstring": "to use Strings::lower() etc...",
|
|
126
126
|
"ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()"
|
|
127
127
|
},
|
|
128
|
-
"time": "
|
|
128
|
+
"time": "2025-03-30T21:06:30+00:00",
|
|
129
129
|
"type": "library",
|
|
130
130
|
"extra": {
|
|
131
131
|
"branch-alias": {
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
],
|
|
175
175
|
"support": {
|
|
176
176
|
"issues": "https://github.com/nette/utils/issues",
|
|
177
|
-
"source": "https://github.com/nette/utils/tree/v4.0.
|
|
177
|
+
"source": "https://github.com/nette/utils/tree/v4.0.6"
|
|
178
178
|
},
|
|
179
179
|
"install-path": "../nette/utils"
|
|
180
180
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
'name' => '__root__',
|
|
4
4
|
'pretty_version' => 'dev-main',
|
|
5
5
|
'version' => 'dev-main',
|
|
6
|
-
'reference' => '
|
|
6
|
+
'reference' => '53b0d437bebe1b115ebfbaf941ac81a3f787bf96',
|
|
7
7
|
'type' => 'library',
|
|
8
8
|
'install_path' => __DIR__ . '/../../',
|
|
9
9
|
'aliases' => array(),
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
'__root__' => array(
|
|
14
14
|
'pretty_version' => 'dev-main',
|
|
15
15
|
'version' => 'dev-main',
|
|
16
|
-
'reference' => '
|
|
16
|
+
'reference' => '53b0d437bebe1b115ebfbaf941ac81a3f787bf96',
|
|
17
17
|
'type' => 'library',
|
|
18
18
|
'install_path' => __DIR__ . '/../../',
|
|
19
19
|
'aliases' => array(),
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
'dev_requirement' => false,
|
|
30
30
|
),
|
|
31
31
|
'nette/utils' => array(
|
|
32
|
-
'pretty_version' => 'v4.0.
|
|
33
|
-
'version' => '4.0.
|
|
34
|
-
'reference' => '
|
|
32
|
+
'pretty_version' => 'v4.0.6',
|
|
33
|
+
'version' => '4.0.6.0',
|
|
34
|
+
'reference' => 'ce708655043c7050eb050df361c5e313cf708309',
|
|
35
35
|
'type' => 'library',
|
|
36
36
|
'install_path' => __DIR__ . '/../nette/utils',
|
|
37
37
|
'aliases' => array(),
|
|
@@ -277,7 +277,8 @@ class Arrays
|
|
|
277
277
|
*/
|
|
278
278
|
public static function isList(mixed $value): bool
|
|
279
279
|
{
|
|
280
|
-
return is_array($value) && (
|
|
280
|
+
return is_array($value) && (
|
|
281
|
+
PHP_VERSION_ID < 80100
|
|
281
282
|
? !$value || array_keys($value) === range(0, count($value) - 1)
|
|
282
283
|
: array_is_list($value)
|
|
283
284
|
);
|
|
@@ -271,7 +271,7 @@ final class FileSystem
|
|
|
271
271
|
*/
|
|
272
272
|
public static function isAbsolute(string $path): bool
|
|
273
273
|
{
|
|
274
|
-
return (bool) preg_match('#([a-z]:)?[
|
|
274
|
+
return (bool) preg_match('#([a-z]:)?[/\\\]|[a-z][a-z0-9+.-]*://#Ai', $path);
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
|
|
@@ -280,7 +280,7 @@ final class FileSystem
|
|
|
280
280
|
*/
|
|
281
281
|
public static function normalizePath(string $path): string
|
|
282
282
|
{
|
|
283
|
-
$parts = $path === '' ? [] : preg_split('~[
|
|
283
|
+
$parts = $path === '' ? [] : preg_split('~[/\\\]+~', $path);
|
|
284
284
|
$res = [];
|
|
285
285
|
foreach ($parts as $part) {
|
|
286
286
|
if ($part === '..' && $res && end($res) !== '..' && end($res) !== '') {
|
|
@@ -305,6 +305,19 @@ final class FileSystem
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
|
|
308
|
+
/**
|
|
309
|
+
* Resolves a path against a base path. If the path is absolute, returns it directly, if it's relative, joins it with the base path.
|
|
310
|
+
*/
|
|
311
|
+
public static function resolvePath(string $basePath, string $path): string
|
|
312
|
+
{
|
|
313
|
+
return match (true) {
|
|
314
|
+
self::isAbsolute($path) => self::platformSlashes($path),
|
|
315
|
+
$path === '' => self::platformSlashes($basePath),
|
|
316
|
+
default => self::joinPaths($basePath, $path),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
308
321
|
/**
|
|
309
322
|
* Converts backslashes to slashes.
|
|
310
323
|
*/
|
|
@@ -505,6 +505,6 @@ class Finder implements \IteratorAggregate
|
|
|
505
505
|
'\-' => '-',
|
|
506
506
|
],
|
|
507
507
|
);
|
|
508
|
-
return '#' . $anchor . $pattern . '$#D' . (
|
|
508
|
+
return '#' . $anchor . $pattern . '$#D' . (Helpers::IsWindows ? 'i' : '');
|
|
509
509
|
}
|
|
510
510
|
}
|
|
@@ -718,42 +718,27 @@ class Image
|
|
|
718
718
|
*/
|
|
719
719
|
private function output(int $type, ?int $quality, ?string $file = null): void
|
|
720
720
|
{
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
$quality = $quality === null ? 30 : max(0, min(100, $quality));
|
|
743
|
-
$success = @imageavif($this->image, $file, $quality); // @ is escalated to exception
|
|
744
|
-
break;
|
|
745
|
-
|
|
746
|
-
case ImageType::BMP:
|
|
747
|
-
$success = @imagebmp($this->image, $file); // @ is escalated to exception
|
|
748
|
-
break;
|
|
749
|
-
|
|
750
|
-
default:
|
|
751
|
-
throw new Nette\InvalidArgumentException("Unsupported image type '$type'.");
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
if (!$success) {
|
|
755
|
-
throw new ImageException(Helpers::getLastError() ?: 'Unknown error');
|
|
756
|
-
}
|
|
721
|
+
[$defQuality, $min, $max] = match ($type) {
|
|
722
|
+
ImageType::JPEG => [85, 0, 100],
|
|
723
|
+
ImageType::PNG => [9, 0, 9],
|
|
724
|
+
ImageType::GIF => [null, null, null],
|
|
725
|
+
ImageType::WEBP => [80, 0, 100],
|
|
726
|
+
ImageType::AVIF => [30, 0, 100],
|
|
727
|
+
ImageType::BMP => [null, null, null],
|
|
728
|
+
default => throw new Nette\InvalidArgumentException("Unsupported image type '$type'."),
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
$args = [$this->image, $file];
|
|
732
|
+
if ($defQuality !== null) {
|
|
733
|
+
$args[] = $quality === null ? $defQuality : max($min, min($max, $quality));
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
Callback::invokeSafe('image' . self::Formats[$type], $args, function (string $message) use ($file): void {
|
|
737
|
+
if ($file !== null) {
|
|
738
|
+
@unlink($file);
|
|
739
|
+
}
|
|
740
|
+
throw new ImageException($message);
|
|
741
|
+
});
|
|
757
742
|
}
|
|
758
743
|
|
|
759
744
|
|
|
@@ -233,6 +233,7 @@ final class Iterables
|
|
|
233
233
|
$iterable instanceof \Iterator => $iterable,
|
|
234
234
|
$iterable instanceof \IteratorAggregate => self::toIterator($iterable->getIterator()),
|
|
235
235
|
is_array($iterable) => new \ArrayIterator($iterable),
|
|
236
|
+
default => throw new Nette\ShouldNotHappenException,
|
|
236
237
|
};
|
|
237
238
|
}
|
|
238
239
|
}
|
|
@@ -19,14 +19,14 @@ final class Reflection
|
|
|
19
19
|
{
|
|
20
20
|
use Nette\StaticClass;
|
|
21
21
|
|
|
22
|
-
/** @deprecated use Nette\Utils\
|
|
22
|
+
/** @deprecated use Nette\Utils\Validators::isBuiltinType() */
|
|
23
23
|
public static function isBuiltinType(string $type): bool
|
|
24
24
|
{
|
|
25
25
|
return Validators::isBuiltinType($type);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
/** @deprecated use Nette\Utils\
|
|
29
|
+
/** @deprecated use Nette\Utils\Validators::isClassKeyword() */
|
|
30
30
|
public static function isClassKeyword(string $name): bool
|
|
31
31
|
{
|
|
32
32
|
return Validators::isClassKeyword($name);
|
|
@@ -28,7 +28,7 @@ class Strings
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* @deprecated use Nette\Utils\
|
|
31
|
+
* @deprecated use Nette\Utils\Validators::isUnicode()
|
|
32
32
|
*/
|
|
33
33
|
public static function checkEncoding(string $s): bool
|
|
34
34
|
{
|
|
@@ -547,7 +547,6 @@ class Strings
|
|
|
547
547
|
return $utf8 && $captureOffset
|
|
548
548
|
? self::bytesToChars($subject, [$m])[0]
|
|
549
549
|
: $m;
|
|
550
|
-
|
|
551
550
|
}
|
|
552
551
|
|
|
553
552
|
|
|
@@ -260,8 +260,8 @@ final class Type
|
|
|
260
260
|
$subtypes,
|
|
261
261
|
fn($subtype) => Validators::isBuiltinType($type)
|
|
262
262
|
? strcasecmp($type, $subtype) === 0
|
|
263
|
-
: is_a($subtype, $type, allow_string: true)
|
|
264
|
-
)
|
|
263
|
+
: is_a($subtype, $type, allow_string: true),
|
|
264
|
+
),
|
|
265
265
|
);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
@@ -11,7 +11,7 @@ namespace Nette\Utils;
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* An error occurred while working with the image.
|
|
15
15
|
*/
|
|
16
16
|
class ImageException extends \Exception
|
|
17
17
|
{
|
|
@@ -19,7 +19,7 @@ class ImageException extends \Exception
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* The
|
|
22
|
+
* The image file is invalid or in an unsupported format.
|
|
23
23
|
*/
|
|
24
24
|
class UnknownImageFileException extends ImageException
|
|
25
25
|
{
|
|
@@ -27,7 +27,7 @@ class UnknownImageFileException extends ImageException
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* JSON encoding or decoding failed.
|
|
31
31
|
*/
|
|
32
32
|
class JsonException extends \JsonException
|
|
33
33
|
{
|
|
@@ -35,7 +35,7 @@ class JsonException extends \JsonException
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Regular expression pattern or execution failed.
|
|
39
39
|
*/
|
|
40
40
|
class RegexpException extends \Exception
|
|
41
41
|
{
|
|
@@ -43,7 +43,7 @@ class RegexpException extends \Exception
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* The
|
|
46
|
+
* Type validation failed. The value doesn't match the expected type constraints.
|
|
47
47
|
*/
|
|
48
48
|
class AssertionException extends \Exception
|
|
49
49
|
{
|
|
@@ -11,8 +11,7 @@ namespace Nette;
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* The
|
|
15
|
-
* outside the allowable range of values as defined by the invoked method.
|
|
14
|
+
* The value is outside the allowed range.
|
|
16
15
|
*/
|
|
17
16
|
class ArgumentOutOfRangeException extends \InvalidArgumentException
|
|
18
17
|
{
|
|
@@ -20,8 +19,7 @@ class ArgumentOutOfRangeException extends \InvalidArgumentException
|
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
|
-
* The
|
|
24
|
-
* current state, method has been invoked at an illegal or inappropriate time.
|
|
22
|
+
* The object is in a state that does not allow the requested operation.
|
|
25
23
|
*/
|
|
26
24
|
class InvalidStateException extends \RuntimeException
|
|
27
25
|
{
|
|
@@ -29,7 +27,7 @@ class InvalidStateException extends \RuntimeException
|
|
|
29
27
|
|
|
30
28
|
|
|
31
29
|
/**
|
|
32
|
-
* The
|
|
30
|
+
* The requested feature is not implemented.
|
|
33
31
|
*/
|
|
34
32
|
class NotImplementedException extends \LogicException
|
|
35
33
|
{
|
|
@@ -37,8 +35,7 @@ class NotImplementedException extends \LogicException
|
|
|
37
35
|
|
|
38
36
|
|
|
39
37
|
/**
|
|
40
|
-
* The
|
|
41
|
-
* it is sometimes possible to perform the requested operation, see InvalidStateException.
|
|
38
|
+
* The requested operation is not supported.
|
|
42
39
|
*/
|
|
43
40
|
class NotSupportedException extends \LogicException
|
|
44
41
|
{
|
|
@@ -46,7 +43,7 @@ class NotSupportedException extends \LogicException
|
|
|
46
43
|
|
|
47
44
|
|
|
48
45
|
/**
|
|
49
|
-
* The
|
|
46
|
+
* The requested feature is deprecated and no longer available.
|
|
50
47
|
*/
|
|
51
48
|
class DeprecatedException extends NotSupportedException
|
|
52
49
|
{
|
|
@@ -54,7 +51,7 @@ class DeprecatedException extends NotSupportedException
|
|
|
54
51
|
|
|
55
52
|
|
|
56
53
|
/**
|
|
57
|
-
*
|
|
54
|
+
* Cannot access the requested class property or method.
|
|
58
55
|
*/
|
|
59
56
|
class MemberAccessException extends \Error
|
|
60
57
|
{
|
|
@@ -62,7 +59,7 @@ class MemberAccessException extends \Error
|
|
|
62
59
|
|
|
63
60
|
|
|
64
61
|
/**
|
|
65
|
-
*
|
|
62
|
+
* Failed to read from or write to a file or stream.
|
|
66
63
|
*/
|
|
67
64
|
class IOException extends \RuntimeException
|
|
68
65
|
{
|
|
@@ -70,7 +67,7 @@ class IOException extends \RuntimeException
|
|
|
70
67
|
|
|
71
68
|
|
|
72
69
|
/**
|
|
73
|
-
* The
|
|
70
|
+
* The requested file does not exist.
|
|
74
71
|
*/
|
|
75
72
|
class FileNotFoundException extends IOException
|
|
76
73
|
{
|
|
@@ -78,7 +75,7 @@ class FileNotFoundException extends IOException
|
|
|
78
75
|
|
|
79
76
|
|
|
80
77
|
/**
|
|
81
|
-
* The
|
|
78
|
+
* The requested directory does not exist.
|
|
82
79
|
*/
|
|
83
80
|
class DirectoryNotFoundException extends IOException
|
|
84
81
|
{
|
|
@@ -86,7 +83,7 @@ class DirectoryNotFoundException extends IOException
|
|
|
86
83
|
|
|
87
84
|
|
|
88
85
|
/**
|
|
89
|
-
* The
|
|
86
|
+
* The provided argument has invalid type or format.
|
|
90
87
|
*/
|
|
91
88
|
class InvalidArgumentException extends \InvalidArgumentException
|
|
92
89
|
{
|
|
@@ -94,7 +91,7 @@ class InvalidArgumentException extends \InvalidArgumentException
|
|
|
94
91
|
|
|
95
92
|
|
|
96
93
|
/**
|
|
97
|
-
* The
|
|
94
|
+
* The requested array or collection index does not exist.
|
|
98
95
|
*/
|
|
99
96
|
class OutOfRangeException extends \OutOfRangeException
|
|
100
97
|
{
|
|
@@ -102,8 +99,16 @@ class OutOfRangeException extends \OutOfRangeException
|
|
|
102
99
|
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
|
-
* The
|
|
102
|
+
* The returned value has unexpected type or format.
|
|
106
103
|
*/
|
|
107
104
|
class UnexpectedValueException extends \UnexpectedValueException
|
|
108
105
|
{
|
|
109
106
|
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Houston, we have a problem.
|
|
111
|
+
*/
|
|
112
|
+
class ShouldNotHappenException extends \LogicException
|
|
113
|
+
{
|
|
114
|
+
}
|