|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpWinTools\WmiScripting\Support\ApiObjects; |
|
4
|
|
|
|
|
5
|
|
|
use PhpWinTools\Support\COM\VariantWrapper; |
|
6
|
|
|
use function PhpWinTools\WmiScripting\Support\resolve; |
|
7
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Property; |
|
8
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\PropertySet; |
|
9
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\VariantInterfaces\PropertySetVariant; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbempropertyset |
|
13
|
|
|
*/ |
|
14
|
|
|
class SWbemPropertySet extends AbstractWbemObject implements PropertySet |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var array|SWbemProperty[] */ |
|
17
|
|
|
protected $properties = []; |
|
18
|
|
|
|
|
19
|
|
|
protected $resolve_property_sets; |
|
20
|
|
|
|
|
21
|
|
|
/** @var VariantWrapper|PropertySetVariant */ |
|
22
|
|
|
protected $object; |
|
23
|
|
|
|
|
24
|
2 |
|
public function __construct(VariantWrapper $variant, array $resolve_property_sets = []) |
|
25
|
|
|
{ |
|
26
|
2 |
|
parent::__construct($variant); |
|
27
|
|
|
|
|
28
|
2 |
|
$this->resolve_property_sets = $resolve_property_sets; |
|
29
|
2 |
|
$this->buildProperties(); |
|
30
|
2 |
|
} |
|
31
|
|
|
|
|
32
|
2 |
|
public function toArray(): array |
|
33
|
|
|
{ |
|
34
|
2 |
|
$array = []; |
|
35
|
|
|
|
|
36
|
2 |
|
foreach ($this->properties as $key => $property) { |
|
37
|
2 |
|
if ($property instanceof SWbemObject) { |
|
38
|
|
|
$array[$key] = $property->getModel(); |
|
39
|
|
|
continue; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
$array[$key] = $property->toArray(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
return $array; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
2 |
|
protected function buildProperties() |
|
49
|
|
|
{ |
|
50
|
2 |
|
foreach ($this->object as $item) { |
|
51
|
2 |
|
$this->properties[$item->Name] = $this->resolveProperty( |
|
52
|
2 |
|
resolve()->property($item), |
|
53
|
2 |
|
$item->Name |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
2 |
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
protected function resolveProperty(Property $property, $name) |
|
59
|
|
|
{ |
|
60
|
2 |
|
if (!array_key_exists('services', $this->resolve_property_sets) |
|
61
|
2 |
|
|| !array_key_exists('property_names', $this->resolve_property_sets) |
|
62
|
|
|
) { |
|
63
|
|
|
return $property; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
2 |
|
if (in_array($name, $this->resolve_property_sets['property_names'])) { |
|
67
|
|
|
return $this->resolve_property_sets['services']->get($property->getAttribute('value')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
2 |
|
return $property; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|