FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phpbench/lib/Development/ConfigSchemaDumper.php at program-executor · phpbench/phpbench · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
phpbench
/
phpbench
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
132
Star
2k
Code
Issues
28
Pull requests
10
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phpbench
/
lib
/
Development
/
ConfigSchemaDumper.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
109 lines (92 loc) · 3.13 KB
Breadcrumbs
phpbench
/
lib
/
Development
/
ConfigSchemaDumper.php
Copy path
File metadata and controls
109 lines (92 loc) · 3.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
namespace
PhpBench
\
Development
;
use
PhpBench
\
DependencyInjection
\
ExtensionInterface
;
use
Symfony
\
Component
\
OptionsResolver
\
Debug
\
OptionsResolverIntrospector
;
use
Symfony
\
Component
\
OptionsResolver
\
Exception
\
NoConfigurationException
;
use
Symfony
\
Component
\
OptionsResolver
\
OptionsResolver
;
use
function
json_encode
;
use
function
method_exists
;
class
ConfigSchemaDumper
{
/**
* @var class-string[]
*/
private
$
extensions
;
/**
* @param class-string[] $extensions
*/
public
function
__construct
(
array
$
extensions
)
{
$
this
->
extensions
=
$
extensions
;
}
public
function
dump
():
string
{
if
(!
method_exists
(OptionsResolver::class,
'
getInfo
'
)) {
return
'
Config reference generation requires Symfony Options Resolver ^5.0
'
;
}
$
schema
= [
'
$schema
'
=>
'
https =>//json-schema.org/draft/2020-12/schema
'
,
'
title
'
=>
'
PHPBench configuration
'
,
'
type
'
=>
'
object
'
,
'
properties
'
=> [
'
$include
'
=> [
'
description
'
=>
'
Include another config file relative to this one
'
,
'
type
'
=> [
'
string
'
,
'
array
'
],
],
'
$include-glob
'
=> [
'
description
'
=>
'
Include config files using a glob pattern. Paths are relative to the config file
'
,
'
type
'
=> [
'
string
'
,
'
array
'
],
],
],
];
foreach
(
$
this
->
extensions
as
$
extensionClass
) {
$
optionsResolver
=
new
OptionsResolver
();
$
extension
=
new
$
extensionClass
();
assert
(
$
extension
instanceof
ExtensionInterface);
$
extension
->
configure
(
$
optionsResolver
);
if
(!
$
optionsResolver
->
getDefinedOptions
()) {
continue
;
}
$
inspector
=
new
OptionsResolverIntrospector
(
$
optionsResolver
);
foreach
(
$
optionsResolver
->
getDefinedOptions
()
as
$
option
) {
$
meta
= [
'
description
'
=>
$
optionsResolver
->
getInfo
(
$
option
),
'
type
'
=>
$
this
->
mapTypes
(
$
inspector
->
getAllowedTypes
(
$
option
)),
];
try
{
$
values
=
$
inspector
->
getAllowedValues
(
$
option
);
$
meta
[
'
enum
'
] =
$
values
;
}
catch
(
NoConfigurationException
$
e
) {
}
$
schema
[
'
properties
'
][
$
option
] =
$
meta
;
}
}
return
(
string
)
json_encode
(
$
schema
,
JSON_PRETTY_PRINT
);
}
/**
* @param string[] $types
*
* @return string[]
*/
private
function
mapTypes
(
array
$
types
):
array
{
return
array_map
(
function
(
string
$
type
) {
if
(
$
type
===
'
array
'
) {
return
'
object
'
;
}
if
(
$
type
===
'
bool
'
) {
return
'
boolean
'
;
}
if
(
$
type
===
'
int
'
) {
return
'
integer
'
;
}
if
(
$
type
===
'
float
'
) {
return
'
number
'
;
}
if
(
substr
(
$
type
, -
2
) ===
'
[]
'
) {
return
'
array
'
;
}
return
$
type
;
},
$
types
);
}
}
Back
|
FazBrowse Home
|
New Git URL