← All changes
|
jetpack_vendor/automattic/jetpack-protect-models/src/class-vulnerability-model.php
+94
-0
16.2-beta
→
16.3
View file →
| @@ -1,0 +1,94 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Model class for vulnerability data. | |
| 4 | + * | |
| 5 | + * @package automattic/jetpack-protect-models | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace Automattic\Jetpack\Protect_Models; | |
| 9 | + | |
| 10 | +use Automattic\Jetpack\Redirect; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Model class for vulnerability data. | |
| 14 | + */ | |
| 15 | +class Vulnerability_Model { | |
| 16 | + /** | |
| 17 | + * Vulnerability ID. | |
| 18 | + * | |
| 19 | + * @var null|string | |
| 20 | + */ | |
| 21 | + public $id; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Vulnerability Title. | |
| 25 | + * | |
| 26 | + * @var null|string | |
| 27 | + */ | |
| 28 | + public $title; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Vulnerability Description. | |
| 32 | + * | |
| 33 | + * @var null|string | |
| 34 | + */ | |
| 35 | + public $description; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * The version the vulnerability is fixed in. | |
| 39 | + * | |
| 40 | + * @var null|string | |
| 41 | + */ | |
| 42 | + public $fixed_in; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * The version the vulnerability was introduced. | |
| 46 | + * | |
| 47 | + * @var null|string | |
| 48 | + */ | |
| 49 | + public $introduced_in; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * The type of vulnerability. | |
| 53 | + * | |
| 54 | + * @var null|string | |
| 55 | + */ | |
| 56 | + public $type; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * The source URL for the vulnerability. | |
| 60 | + * | |
| 61 | + * @var null|string | |
| 62 | + */ | |
| 63 | + public $source; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Vulnerability Constructor | |
| 67 | + * | |
| 68 | + * @param array|object $vulnerability Vulnerability data to load into the class instance. | |
| 69 | + */ | |
| 70 | + public function __construct( $vulnerability ) { | |
| 71 | + // Initialize the vulnerability data. | |
| 72 | + foreach ( $vulnerability as $property => $value ) { | |
| 73 | + if ( property_exists( $this, $property ) ) { | |
| 74 | + $this->$property = $value; | |
| 75 | + } | |
| 76 | + } | |
| 77 | + | |
| 78 | + // Ensure the source URL is set. | |
| 79 | + $this->get_source(); | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Get the source URL for the vulnerability. | |
| 84 | + * | |
| 85 | + * @return string | |
| 86 | + */ | |
| 87 | + public function get_source() { | |
| 88 | + if ( empty( $this->source ) && $this->id ) { | |
| 89 | + $this->source = Redirect::get_url( 'jetpack-protect-vul-info', array( 'path' => $this->id ) ); | |
| 90 | + } | |
| 91 | + | |
| 92 | + return $this->source; | |
| 93 | + } | |
| 94 | +} | |