1 | <?php |
||
18 | class Vasri |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var Builder|null |
||
23 | */ |
||
24 | private static $builder = null; |
||
25 | |||
26 | /** |
||
27 | * Vasri constructor. |
||
28 | */ |
||
29 | public function __construct() |
||
30 | { |
||
31 | self::$builder = self::loadBuilder(); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param string $path |
||
36 | * @param bool $enableVersioning |
||
37 | * @param bool $enableSRI |
||
38 | * |
||
39 | * @return string |
||
40 | * @throws Exception |
||
41 | */ |
||
42 | public static function vasri( |
||
43 | string $path, |
||
44 | bool $enableVersioning = true, |
||
45 | bool $enableSRI = true |
||
46 | ): string { |
||
47 | $output = ''; |
||
48 | |||
49 | if (self::isPath($path) === true) { |
||
50 | $output .= self::addAttribute($path, $enableVersioning); |
||
51 | if ($enableSRI === true) { |
||
52 | $output .= self::addSRI($path); |
||
53 | } |
||
54 | |||
55 | return $output; |
||
56 | |||
57 | } else { |
||
58 | throw new Exception('Incorrect file path or file does not exist'); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param string $path |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | private static function addVersioning(string $path): string |
||
68 | { |
||
69 | return self::$builder->versioning($path); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @param string $path |
||
74 | * |
||
75 | * @return string |
||
76 | * @throws Exception |
||
77 | */ |
||
78 | private static function addSRI(string $path): string |
||
79 | { |
||
80 | return self::$builder->sri($path); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return Builder |
||
85 | */ |
||
86 | private static function loadBuilder(): Builder |
||
90 | |||
91 | /** |
||
92 | * @param string $path |
||
93 | * @param bool $enableVersioning |
||
94 | * |
||
95 | * @return string |
||
96 | * @throws Exception |
||
97 | */ |
||
98 | private static function addAttribute(string $path, bool $enableVersioning) |
||
112 | |||
113 | /** |
||
114 | * |
||
115 | * @param string $path |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | private static function isPath(string $path): bool |
||
123 | |||
124 | } |
||
125 |