PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.7
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.7
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
insert-php / admin / includes / dto / class-type.php

class-type.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.7.7, at admin/includes/dto/class-type.php

67 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * API Type DTO class
4 *
5 * Data Transfer Object for snippet types from the Woody API.
6 * Replaces the non-GPL-compatible JsonMapper implementation.
7 *
8 * @package Woody_Code_Snippets
9 * @copyright Copyright (c) 2025, Themeisle
10 * @license GPL-2.0+
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * WINP_DTO_Type class - represents a snippet type/category from the API.
20 */
21 class WINP_DTO_Type extends WINP_DTO_Base {
22
23 /**
24 * Type ID.
25 *
26 * @var int
27 */
28 public $id;
29
30 /**
31 * Type title.
32 *
33 * @var string
34 */
35 public $title;
36
37 /**
38 * Type slug.
39 *
40 * @var string
41 */
42 public $slug;
43
44 /**
45 * Create instance from associative array.
46 *
47 * @param array<string, mixed> $data Associative array of data.
48 *
49 * @return self
50 * @throws Exception If required fields are missing.
51 */
52 public static function from_array( array $data ) {
53 // Validate required fields.
54 self::require_field( $data, 'id', 'Type' );
55 self::require_field( $data, 'title', 'Type' );
56 self::require_field( $data, 'slug', 'Type' );
57
58 $instance = new self();
59
60 $instance->id = (int) $data['id'];
61 $instance->title = (string) $data['title'];
62 $instance->slug = (string) $data['slug'];
63
64 return $instance;
65 }
66 }
67