|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpWinTools\WmiScripting\Testing\Responses; |
|
4
|
|
|
|
|
5
|
|
|
use ArrayIterator; |
|
6
|
|
|
use PhpWinTools\Support\COM\VariantWrapper; |
|
7
|
|
|
use PhpWinTools\WmiScripting\Configuration\Config; |
|
8
|
|
|
use PhpWinTools\WmiScripting\Testing\Wmi\ModelFake; |
|
9
|
|
|
use PhpWinTools\WmiScripting\Testing\Support\VARIANTFake; |
|
10
|
|
|
use PhpWinTools\WmiScripting\Testing\Wmi\ModelFakeCollection; |
|
11
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\SWbemObjectSet; |
|
12
|
|
|
|
|
13
|
|
|
class ObjectSetResponse extends ApiObjectResponseFactory |
|
14
|
|
|
{ |
|
15
|
2 |
|
public static function standard(ModelFakeCollection $collection, Config $config = null) |
|
16
|
|
|
{ |
|
17
|
2 |
|
$config = $config ?? Config::testInstance(); |
|
18
|
|
|
|
|
19
|
2 |
|
static::addVariantResponse(SWbemObjectSet::class, 'Count', $collection->count(), $config); |
|
20
|
2 |
|
static::addVariantResponse(SWbemObjectSet::class, '__objectSet__', static::buildObjects($collection), $config); |
|
21
|
2 |
|
} |
|
22
|
|
|
|
|
23
|
2 |
|
protected static function buildObjects(ModelFakeCollection $collection) |
|
24
|
|
|
{ |
|
25
|
|
|
return new ArrayIterator($collection->map(function (ModelFake $modelFake) { |
|
26
|
2 |
|
return new VariantWrapper( |
|
27
|
2 |
|
VARIANTFake::withResponse('Properties_', static::buildProperties($modelFake)) |
|
28
|
2 |
|
->addResponse('Derivation_', $modelFake->get('derivations')) |
|
29
|
2 |
|
->addResponse('Qualifiers_', static::buildQualifiers($modelFake)) |
|
30
|
2 |
|
->addResponse('Path_', static::buildPath($modelFake)) |
|
31
|
|
|
); |
|
32
|
2 |
|
})->toArray()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
2 |
|
protected static function buildPath(ModelFake $modelFake) |
|
36
|
|
|
{ |
|
37
|
2 |
|
$path = $modelFake->get('path'); |
|
38
|
|
|
|
|
39
|
2 |
|
return new VariantWrapper( |
|
40
|
2 |
|
VARIANTFake::withResponse('Authority', $path['authority']) |
|
41
|
2 |
|
->addResponse('Class', $path['class']) |
|
42
|
2 |
|
->addResponse('DisplayName', $path['display_name']) |
|
43
|
2 |
|
->addResponse('IsClass', $path['is_class']) |
|
44
|
2 |
|
->addResponse('IsSingleton', $path['is_singleton']) |
|
45
|
2 |
|
->addResponse('Keys', $path['keys']) |
|
46
|
2 |
|
->addResponse('Namespace', $path['namespace']) |
|
47
|
2 |
|
->addResponse('ParentNamespace', $path['parent_namespace']) |
|
48
|
2 |
|
->addResponse('Path', $path['path']) |
|
49
|
2 |
|
->addResponse('RelPath', $path['relative_path']) |
|
50
|
2 |
|
->addResponse('Server', $path['server']) |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
protected static function buildProperties(ModelFake $modelFake) |
|
55
|
|
|
{ |
|
56
|
|
|
$properties = $modelFake->get('properties')->map(function ($property) { |
|
57
|
2 |
|
return new VariantWrapper( |
|
58
|
2 |
|
VARIANTFake::withResponse('Name', $property['Name']) |
|
59
|
2 |
|
->addResponse('Value', $property['Value']) |
|
60
|
2 |
|
->addResponse('Origin', $property['Origin']) |
|
61
|
|
|
); |
|
62
|
2 |
|
})->flatten()->toArray(); |
|
63
|
|
|
|
|
64
|
2 |
|
return new VariantWrapper(VARIANTFake::withResponse('__propertySet__', new ArrayIterator($properties))); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
protected static function buildQualifiers(ModelFake $modelFake) |
|
68
|
|
|
{ |
|
69
|
|
|
$qualifiers = $modelFake->get('qualifiers')->map(function ($qualifier) { |
|
70
|
2 |
|
return new VariantWrapper( |
|
71
|
2 |
|
VARIANTFake::withResponse('Name', $qualifier['Name']) |
|
72
|
2 |
|
->addResponse('Value', $qualifier['Value']) |
|
73
|
|
|
); |
|
74
|
2 |
|
})->flatten()->toArray(); |
|
75
|
|
|
|
|
76
|
2 |
|
return new VariantWrapper( |
|
77
|
2 |
|
VARIANTFake::withResponse('__qualifierSet__', new ArrayIterator($qualifiers)) |
|
78
|
2 |
|
->addResponse('Count', $modelFake->get('qualifiers')->count()) |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|