1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpWinTools\WmiScripting\Support\ApiObjects; |
4
|
|
|
|
5
|
|
|
use PhpWinTools\Support\COM\VariantWrapper; |
6
|
|
|
use PhpWinTools\WmiScripting\Models\Classes; |
7
|
|
|
use PhpWinTools\WmiScripting\Models\Win32Model; |
8
|
|
|
use function PhpWinTools\WmiScripting\Support\resolve; |
9
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\ObjectItem; |
10
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\VariantInterfaces\ObjectVariant; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemobject |
14
|
|
|
*/ |
15
|
|
|
class SWbemObject extends AbstractWbemObject implements ObjectItem |
16
|
|
|
{ |
17
|
|
|
protected $win32Model; |
18
|
|
|
|
19
|
|
|
protected $derivations = []; |
20
|
|
|
|
21
|
|
|
protected $propertySet; |
22
|
|
|
|
23
|
|
|
protected $qualifierSet; |
24
|
|
|
|
25
|
|
|
protected $mergedProperties = []; |
26
|
|
|
|
27
|
|
|
protected $path; |
28
|
|
|
|
29
|
|
|
/** @var VariantWrapper|ObjectVariant */ |
30
|
|
|
protected $object; |
31
|
|
|
|
32
|
|
|
public function __construct(VariantWrapper $variant, array $resolve_property_sets = []) |
33
|
|
|
{ |
34
|
|
|
parent::__construct($variant); |
35
|
|
|
|
36
|
|
|
$this->buildDerivations(); |
37
|
|
|
|
38
|
|
|
$this->propertySet = resolve()->propertySet($this->object->Properties_, $resolve_property_sets); |
|
|
|
|
39
|
|
|
$this->qualifierSet = resolve()->qualifierSet($this->object->Qualifiers_); |
|
|
|
|
40
|
|
|
$this->path = resolve()->objectPath($this->object->Path_); |
|
|
|
|
41
|
|
|
|
42
|
|
|
$this->mergedProperties = array_merge( |
43
|
|
|
$this->propertySet->toArray(), |
44
|
|
|
['qualifiers' => $this->qualifierSet->toArray()['qualifiers']], |
45
|
|
|
['objectPath' => $this->path->toArray()], |
46
|
|
|
['derivations' => $this->derivations] |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$this->instantiateWin32Model(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return Win32Model |
54
|
|
|
*/ |
55
|
|
|
public function getModel(): Win32Model |
56
|
|
|
{ |
57
|
|
|
return $this->getAttribute('win32Model'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function get() |
61
|
|
|
{ |
62
|
|
|
return $this->mergedProperties; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function instantiateWin32Model(Win32Model $model = null): Win32Model |
66
|
|
|
{ |
67
|
|
|
$model = $model ?? Classes::getClass($this->path->getAttribute('class')); |
68
|
|
|
|
69
|
|
|
if (!is_null($this->win32Model) && get_class($this->win32Model) === $model) { |
|
|
|
|
70
|
|
|
return $this->win32Model; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->win32Model = new $model($this->mergedProperties); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function buildDerivations() |
77
|
|
|
{ |
78
|
|
|
$this->derivations = $this->object->propertyToArray('Derivation_'); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|