-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.php
106 lines (92 loc) · 3.79 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
// Set these variables
$clientId = '';
$clientSecret = '';
require_once(__DIR__ . '/vendor/autoload.php');
// This is a regular OpenID client credenials grant request to obtain an authentication token
$authHeader = base64_encode($clientId.':'.$clientSecret);
$url = 'https://identity.dangl-it.com/connect/token';
$data = array('grant_type' => 'client_credentials', 'scope' => 'avacloud');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n"
."Authorization: Basic ".$authHeader."\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$authResult = file_get_contents($url, false, $context);
if ($authResult === false) {
echo 'auth failure';
}
$authToken = json_decode($authResult)->access_token;
// Configure OAuth2 access token for authorization: Dangl.Identity
$config = Dangl\AVACloud\Configuration::getDefaultConfiguration()->setAccessToken($authToken);
$apiInstance = new Dangl\AVACloud\Api\GaebConversionApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$gaebFile = './GAEBXML_EN.X86';
try {
$result = $apiInstance->gaebConversionConvertToAva($gaebFile);
// Uncomment this line if you want to print all element types
//printElementTypes($result->getServiceSpecifications()[0]->getElements());
echo '<h2>Positions:</h2>';
printPositions($result);
echo '<h2>Full Project:</h2>';
echo '<pre>';
print_r($result);
echo '</pre>';
} catch (Exception $e) {
echo 'Exception when calling GaebConversionApi->gaebConversionConvertToAva: ', $e->getMessage(), PHP_EOL;
}
function printPositions($project) {
$baseContainer = $project->getServiceSpecifications()[0];
$elements = getElementsInContainer($baseContainer);
foreach ($elements as $element) {
if ($element->getElementTypeDiscriminator() == 'PositionDto') {
// The 'elementTypeDiscriminator' identifies the kind of element,
// in this case it's a position
echo $element->getItemNumber()->getStringRepresentation().'<br>';
}
}
}
function getElementsInContainer($container) {
$elementsList = [];
foreach ($container->getElements() as $element) {
array_push($elementsList, $element);
if ($element->getElementTypeDiscriminator() == 'ServiceSpecificationGroupDto') {
$childElements = getElementsInContainer($element);
foreach ($childElements as $childElement) {
array_push($elementsList, $childElement);
}
}
}
return $elementsList;
}
function printElementTypes($elements) {
foreach ($elements as $element) {
if ($element->getElementTypeDiscriminator() == 'ServiceSpecificationGroupDto') {
echo 'Group start '.$element->getItemNumber()->getStringRepresentation()
.' - '
.$element->getShortText()
.'<br>';
// Groups have elements of their own
printElementTypes($element->getElements());
echo 'Group end '.$element->getItemNumber()->getStringRepresentation().'<br>';
} else if ($element->getElementTypeDiscriminator() == 'PositionDto') {
echo 'Position '.$element->getItemNumber()->getStringRepresentation()
.' - '
.$element->getShortText()
.'<br>';
} else if ($element->getElementTypeDiscriminator() == 'NoteTextDto') {
echo 'Note Text<br>';
} else if ($element->getElementTypeDiscriminator() == 'ExecutionDescriptionDto') {
echo 'ExecutionDescription<br>';
}
}
}
?>