/
Converter.php
executable file
·56 lines (50 loc) · 1.97 KB
/
Converter.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
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Integration\Model\Config;
/**
* Converter of integration.xml content into array format.
*/
class Converter implements \Magento\Framework\Config\ConverterInterface
{
/**#@+
* Array keys for config internal representation.
*/
const KEY_EMAIL = 'email';
const KEY_AUTHENTICATION_ENDPOINT_URL = 'endpoint_url';
const KEY_IDENTITY_LINKING_URL = 'identity_link_url';
/**#@-*/
/**
* {@inheritdoc}
*/
public function convert($source)
{
$result = [];
/** @var \DOMNodeList $integrations */
$integrations = $source->getElementsByTagName('integration');
/** @var \DOMElement $integration */
foreach ($integrations as $integration) {
if ($integration->nodeType != XML_ELEMENT_NODE) {
continue;
}
$integrationName = $integration->attributes->getNamedItem('name')->nodeValue;
$result[$integrationName] = [];
/** @var \DOMElement $email */
$email = $integration->getElementsByTagName('email')->item(0)->nodeValue;
$result[$integrationName][self::KEY_EMAIL] = $email;
if ($integration->getElementsByTagName('endpoint_url')->length) {
/** @var \DOMElement $endpointUrl */
$endpointUrl = $integration->getElementsByTagName('endpoint_url')->item(0)->nodeValue;
$result[$integrationName][self::KEY_AUTHENTICATION_ENDPOINT_URL] = $endpointUrl;
}
if ($integration->getElementsByTagName('identity_link_url')->length) {
/** @var \DOMElement $identityLinkUrl */
$identityLinkUrl = $integration->getElementsByTagName('identity_link_url')->item(0)->nodeValue;
$result[$integrationName][self::KEY_IDENTITY_LINKING_URL] = $identityLinkUrl;
}
}
return $result;
}
}