FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
formatphp/tests/Extractor/parser.php at main · formatphp/formatphp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
formatphp
/
formatphp
Public
forked from
Skillshare/formatphp
Notifications
You must be signed in to change notification settings
Fork
0
Star
3
Code
Issues
0
Pull requests
1
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
formatphp
/
tests
/
Extractor
/
parser.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (39 loc) · 1.31 KB
Breadcrumbs
formatphp
/
tests
/
Extractor
/
parser.php
Copy path
File metadata and controls
49 lines (39 loc) · 1.31 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
<?php
declare
(strict_types=
1
);
use
FormatPHP
\
Descriptor
;
use
FormatPHP
\
DescriptorCollection
;
use
FormatPHP
\
Extractor
\
MessageExtractorOptions
;
use
FormatPHP
\
Extractor
\
Parser
\
ParserError
;
use
FormatPHP
\
Extractor
\
Parser
\
ParserErrorCollection
;
return
function
(
string
$
filePath
,
MessageExtractorOptions
$
options
,
ParserErrorCollection
$
errors
):
DescriptorCollection
{
$
descriptors
=
new
DescriptorCollection
();
$
contents
= (
string
)
file_get_contents
(
$
filePath
);
preg_match_all
(
'
/{{#formatMessage *\|? *(?<id>[a-z0-9\-_]*)}}(?<defaultMessage>.*){{\/formatMessage}}/i
'
,
$
contents
,
$
matches
,
);
foreach
(
$
matches
[
'
id
'
]
as
$
index
=>
$
id
) {
if
(
strlen
(
trim
(
$
id
)) ===
0
) {
$
errors
[] =
new
ParserError
(
sprintf
(
'
Missing "id" in "%s"
'
,
$
matches
[
0
][
$
index
]),
$
filePath
,
);
continue
;
}
$
defaultMessage
=
$
matches
[
'
defaultMessage
'
][
$
index
] ??
''
;
if
(
strlen
(
trim
(
$
defaultMessage
)) ===
0
) {
$
errors
[] =
new
ParserError
(
sprintf
(
'
Missing "defaultMessage" in "%s"
'
,
$
matches
[
0
][
$
index
]),
$
filePath
,
);
continue
;
}
$
descriptors
[] =
new
Descriptor
(
$
id
,
$
defaultMessage
);
}
return
$
descriptors
;
};
Back
|
FazBrowse Home
|
New Git URL