PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / jetpack_vendor / automattic / jetpack-protect-models / src / class-extension-model.php

class-extension-model.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.5, at jetpack_vendor/automattic/jetpack-protect-models/src/class-extension-model.php

117 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Model class for extensions.
4 *
5 * @package automattic/jetpack-protect-models
6 */
7
8 namespace Automattic\Jetpack\Protect_Models;
9
10 /**
11 * Model class for extension data.
12 */
13 class Extension_Model {
14
15 /**
16 * The extension name.
17 *
18 * @var null|string
19 */
20 public $name;
21
22 /**
23 * The extension slug.
24 *
25 * @var null|string
26 */
27 public $slug;
28
29 /**
30 * The extension version.
31 *
32 * @var null|string
33 */
34 public $version;
35
36 /**
37 * A collection of threats related to this version of the extension.
38 *
39 * @deprecated 0.4.0 This property is deprecated. Use Threat_Model::$extension instead.
40 *
41 * @var array<Threat_Model>
42 */
43 public $threats = array();
44
45 /**
46 * Whether the extension has been checked for threats.
47 *
48 * @var null|bool
49 */
50 public $checked;
51
52 /**
53 * The type of extension ("plugins", "themes", or "core").
54 *
55 * @var null|string
56 */
57 public $type;
58
59 /**
60 * Extension Model Constructor
61 *
62 * @param array|object $extension Extension data to load into the model instance.
63 */
64 public function __construct( $extension = array() ) {
65 if ( is_object( $extension ) ) {
66 $extension = (array) $extension;
67 }
68
69 foreach ( $extension as $property => $value ) {
70 if ( property_exists( $this, $property ) ) {
71 // use the property's setter method when possible
72 if ( method_exists( $this, "set_$property" ) ) {
73 $this->{ "set_$property" }( $value );
74 continue;
75 }
76
77 // otherwise, map the value directly into the class property
78 $this->$property = $value;
79 }
80 }
81 }
82
83 /**
84 * Set Threats
85 *
86 * @deprecated 0.4.0 This method is deprecated. Use Threat_Model::$extension instead.
87 *
88 * @param array<Threat_Model|array|object> $threats An array of threat data to add to the extension.
89 */
90 public function set_threats( $threats ) {
91 if ( ! is_array( $threats ) ) {
92 // @phan-suppress-next-line PhanDeprecatedProperty -- Maintaining backwards compatibility.
93 $this->threats = array();
94 return;
95 }
96
97 // convert each provided threat item into an instance of Threat_Model
98 $threats = array_map(
99 function ( $threat ) {
100 if ( is_a( $threat, 'Threat_Model' ) ) {
101 return $threat;
102 }
103
104 if ( is_object( $threat ) ) {
105 $threat = (array) $threat;
106 }
107
108 return new Threat_Model( $threat );
109 },
110 $threats
111 );
112
113 // @phan-suppress-next-line PhanDeprecatedProperty -- Maintaining backwards compatibility.
114 $this->threats = $threats;
115 }
116 }
117