Addons
2 years ago
License
1 year ago
Pro
2 years ago
VariationOptions
2 years ago
CategoriesService.php
5 years ago
ScheduledExport.php
3 weeks ago
SnippetParser.php
8 years ago
WooCommerceVersion.php
8 years ago
SnippetParser.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\App\Service; |
| 4 | |
| 5 | class SnippetParser |
| 6 | { |
| 7 | const SNIPPET_MATCH_REGEX = '/{([^}^\"^\']*)}/'; |
| 8 | |
| 9 | const FUNCTION_MATCH_REGEX = '%(\[[^\]\[]*\])%'; |
| 10 | |
| 11 | public function parseSnippets($string) |
| 12 | { |
| 13 | $snippets = array(); |
| 14 | |
| 15 | preg_match_all(self::SNIPPET_MATCH_REGEX, $string, $snippets); |
| 16 | |
| 17 | if(is_array($snippets)) { |
| 18 | $snippets = array_filter($snippets[1]); |
| 19 | } |
| 20 | |
| 21 | foreach ($snippets as &$snippet) { |
| 22 | $snippet = trim($snippet, "{}"); |
| 23 | } |
| 24 | return $snippets; |
| 25 | } |
| 26 | |
| 27 | public function parseFunctions($string) |
| 28 | { |
| 29 | $functions = array(); |
| 30 | $functionsResponse = array(); |
| 31 | |
| 32 | preg_match_all(self::FUNCTION_MATCH_REGEX, $string, $functions); |
| 33 | |
| 34 | if(is_array($functions) && isset($functions[0]) && !empty($functions[0]) && $functions[0]) { |
| 35 | |
| 36 | $functionsResponse[] = $functions[0]; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | $functionsResponse = array_filter($functionsResponse); |
| 41 | if(isset($functionsResponse[0])) { |
| 42 | $functionsResponse = $functionsResponse[0]; |
| 43 | } |
| 44 | |
| 45 | foreach($functionsResponse as &$function) { |
| 46 | $function = trim($function,"[]"); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | return $functionsResponse; |
| 51 | } |
| 52 | } |