PluginProbe
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager / trunk
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager vtrunk
0.0.11 0.0.10 0.0.9 0.0.8 0.0.7 0.0.6 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5
cookiez / modules / script / classes / dto / script-dto.php

script-dto.php in Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager trunk, at modules/script/classes/dto/script-dto.php

99 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Cookiez\Modules\Script\Classes\Dto;
4
5 use Cookiez\Modules\Script\Database\Script_Table;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 /**
12 * Class Script_DTO
13 */
14 class Script_DTO {
15 public ?int $id;
16 public ?int $cookie_id;
17 public ?string $name;
18 public ?string $value;
19 public ?string $type;
20 public ?string $description;
21 public ?string $category;
22 public ?string $blocking_mode;
23 public ?string $created_at;
24 public ?string $updated_at;
25
26 public static function from_rest_api( array $data ): Script_DTO {
27 $dto = new self();
28
29 $dto->id = $data['id'] ?? null;
30 $dto->cookie_id = $data['cookie_id'] ?? null;
31 $dto->name = $data['name'] ?? null;
32 $dto->value = $data['value'] ?? null;
33 $dto->type = $data['type'] ?? null;
34 $dto->description = $data['description'] ?? null;
35 $dto->category = $data['category'] ?? null;
36 $dto->blocking_mode = $data['blocking_mode'] ?? null;
37
38 return $dto;
39 }
40
41 public static function from_scan( array $data ): Script_DTO {
42 $dto = new self();
43
44 $dto->id = null;
45 $dto->cookie_id = null;
46 $dto->name = $data['name'] ?? '';
47 $dto->value = $data['value'] ?? '';
48 $dto->type = $data['type'] ?? null;
49 $dto->description = $data['description'] ?? '';
50 $dto->category = $data['category'] ?? '';
51 $dto->blocking_mode = $data['blocking_mode'] ?? '';
52
53 return $dto;
54 }
55
56 public static function from_entry( $entry ): Script_DTO {
57 $dto = new self();
58
59 $dto->id = $entry->id;
60 $dto->cookie_id = $entry->cookie_id;
61 $dto->name = $entry->name;
62 $dto->value = $entry->value;
63 $dto->type = $entry->type;
64 $dto->description = $entry->description;
65 $dto->category = $entry->category;
66 $dto->blocking_mode = $entry->blocking_mode;
67 $dto->created_at = $entry->created_at;
68 $dto->updated_at = $entry->updated_at;
69
70 return $dto;
71 }
72
73 public function to_entry(): array {
74 $fields = [
75 Script_Table::COOKIE_ID => $this->cookie_id,
76 Script_Table::NAME => $this->name,
77 Script_Table::VALUE => $this->value,
78 Script_Table::TYPE => $this->type,
79 Script_Table::DESCRIPTION => $this->description,
80 Script_Table::CATEGORY => $this->category,
81 Script_Table::BLOCKING_MODE => $this->blocking_mode,
82 ];
83
84 return array_filter( $fields, fn( $value ) => null !== $value );
85 }
86
87 public function to_array(): array {
88 return [
89 'id' => $this->id,
90 'cookie_id' => $this->cookie_id,
91 'name' => $this->name,
92 'value' => $this->value,
93 'description' => $this->description,
94 'category' => $this->category,
95 'blocking_mode' => $this->blocking_mode,
96 ];
97 }
98 }
99