PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / ShortCodeParser / ShortcodeTemplateBuilder.php

ShortcodeTemplateBuilder.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/ShortCodeParser/ShortcodeTemplateBuilder.php

72 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\ShortCodeParser;
4
5 use FluentCart\Framework\Container\Contracts\BindingResolutionException;
6 use FluentCart\Framework\Foundation\App;
7 use FluentCart\Framework\Support\Arr;
8
9 class ShortcodeTemplateBuilder
10 {
11 protected ?SmartCodeParser $parser;
12
13 /**
14 * TemplateBuilder constructor.
15 */
16 public function __construct()
17 {
18 $this->parser = SmartCodeParser::make();
19 }
20
21 /**
22 * Factory method to create an instance of TemplateBuilder and parse the template.
23 *
24 * @param string $template
25 * @param array $data
26 * @return string
27 * @throws BindingResolutionException
28 */
29 public static function make(string $template, array $data = []): string
30 {
31 $instance = new static();
32 return $instance->parser->parseTemplate($template, $data);
33 }
34
35 /**
36 * Factory method to create an instance of TemplateBuilder and parse the template array.
37 *
38 * @param array $templates
39 * @param array $data
40 * @return array
41 * @throws BindingResolutionException
42 */
43 public static function makeFromTemplatesArray(array $templates, array $data): array
44 {
45 foreach ($templates as $templateKey => $template) {
46 if (is_array($template)) {
47 $templates[$templateKey] = self::makeFromTemplatesArray($template, $data);
48 } elseif (is_string($template)) {
49 $templates[$templateKey] = static::make($template, $data);
50 }
51 }
52 return $templates;
53 }
54
55 /**
56 * Factory method to create an instance of TemplateBuilder and parse the template.
57 *
58 * @param array<mixed, string> $templates
59 * @param array $data
60 * @return string
61 * @throws BindingResolutionException
62 */
63 public static function makeFromTemplates(array $templates, array $data): string
64 {
65 $instance = new static();
66 $parsedTemplate = "";
67 foreach ($templates as $template) {
68 $parsedTemplate .= $instance->parser->parseTemplate($template, $data);
69 }
70 return $parsedTemplate;
71 }
72 }