/** * @param string $file the xml file to be loaded * @return null|array where null is an indicator for an error */ public function parse($file) { if (!file_exists($file)) { return null; } libxml_use_internal_errors(true); $loadEntities = libxml_disable_entity_loader(false); $xml = simplexml_load_file($file); libxml_disable_entity_loader($loadEntities); if ($xml == false) { libxml_clear_errors(); return null; } $array = $this->xmlToArray($xml); if (is_null($array)) { return null; } if (!array_key_exists('info', $array)) { $array['info'] = array(); } if (!array_key_exists('remote', $array)) { $array['remote'] = array(); } if (!array_key_exists('public', $array)) { $array['public'] = array(); } if (!array_key_exists('types', $array)) { $array['types'] = array(); } if (array_key_exists('documentation', $array) && is_array($array['documentation'])) { foreach ($array['documentation'] as $key => $url) { // If it is not an absolute URL we assume it is a key // i.e. admin-ldap will get converted to go.php?to=admin-ldap if (!$this->httpHelper->isHTTPURL($url)) { $url = $this->urlGenerator->linkToDocs($url); } $array['documentation'][$key] = $url; } } if (array_key_exists('types', $array)) { if (is_array($array['types'])) { foreach ($array['types'] as $type => $v) { unset($array['types'][$type]); if (is_string($type)) { $array['types'][] = $type; } } } else { $array['types'] = array(); } } return $array; }
/** * @dataProvider isHttpTestData */ public function testIsHTTP($url, $expected) { $this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url)); }