-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Expand file tree
/
Copy pathHtml.php
More file actions
54 lines (49 loc) · 1.59 KB
/
Html.php
File metadata and controls
54 lines (49 loc) · 1.59 KB
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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Module\I18n\Parser\Adapter;
use Magento\Email\Model\Template\Filter;
/**
* Html parser adapter
*/
class Html extends AbstractAdapter
{
/**
* Covers
* <span><!-- ko i18n: 'Next'--><!-- /ko --></span>
* <th class="col col-method" data-bind="i18n: 'Select Method'"></th>
*/
const HTML_FILTER = "/i18n:\s?'(?<value>[^'\\\\]*(?:\\\\.[^'\\\\]*)*)'/i";
/**
* {@inheritdoc}
*/
protected function _parse()
{
$data = file_get_contents($this->_file);
if ($data === false) {
throw new \Exception('Failed to load file from disk.');
}
$results = [];
preg_match_all(Filter::CONSTRUCTION_PATTERN, $data, $results, PREG_SET_ORDER);
$resultsCount = count($results);
for ($i = 0; $i < $resultsCount; $i++) {
if ($results[$i][1] === Filter::TRANS_DIRECTIVE_NAME) {
$directive = [];
if (preg_match(Filter::TRANS_DIRECTIVE_REGEX, $results[$i][2], $directive) !== 1) {
continue;
}
$quote = $directive[1];
$this->_addPhrase($quote . $directive[2] . $quote);
}
}
preg_match_all(self::HTML_FILTER, $data, $results, PREG_SET_ORDER);
$resultsCount = count($results);
for ($i = 0; $i < $resultsCount; $i++) {
if (!empty($results[$i]['value'])) {
$this->_addPhrase($results[$i]['value']);
}
}
}
}