PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.4
Elementor Website Builder – more than just a page builder v4.2.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / utils / api / parse-errors.php

parse-errors.php in Elementor Website Builder – more than just a page builder 4.2.4, at core/utils/api/parse-errors.php

57 lines 1023 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Core\Utils\Api;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 class Parse_Errors {
10
11 /**
12 * @var array<array{key: string, error: string}>
13 */
14 private array $errors = [];
15
16 public static function make() {
17 return new static();
18 }
19
20 public function add( string $key, string $error ): self {
21 $this->errors[] = [
22 'key' => $key,
23 'error' => $error,
24 ];
25
26 return $this;
27 }
28
29 public function is_empty(): bool {
30 return empty( $this->errors );
31 }
32
33 public function all(): array {
34 return $this->errors;
35 }
36
37 public function to_string(): string {
38 $errors = [];
39
40 foreach ( $this->errors as $error ) {
41 $errors[] = $error['key'] . ': ' . $error['error'];
42 }
43
44 return implode( ', ', $errors );
45 }
46
47 public function merge( Parse_Errors $errors, ?string $prefix = null ): self {
48 foreach ( $errors->all() as $error ) {
49 $new_key = $prefix ? "{$prefix}.{$error['key']}" : $error['key'];
50
51 $this->add( $new_key, $error['error'] );
52 }
53
54 return $this;
55 }
56 }
57