19declare(strict_types=1);
42 if (0 === count($this->errorStack)) {
43 $this->xmlErrorState = libxml_use_internal_errors(
true);
44 libxml_clear_errors();
49 $this->errorStack[] = [];
54 $currentErrors = libxml_get_errors();
55 libxml_clear_errors();
57 $level = count($this->errorStack) - 1;
58 $this->errorStack[$level] = array_merge($this->errorStack[$level], $currentErrors);
68 $errors = array_pop($this->errorStack);
70 if (0 === count($this->errorStack)) {
71 libxml_use_internal_errors($this->xmlErrorState);
77 public function parse(
string $xmlString): void
82 $xml =
new SimpleXMLElement($xmlString);
84 $xml->registerXPathNamespace(
'md',
'urn:oasis:names:tc:SAML:2.0:metadata');
85 $xml->registerXPathNamespace(
'mdui',
'urn:oasis:names:tc:SAML:metadata:ui');
87 $idps =
$xml->xpath(
'//md:EntityDescriptor[//md:IDPSSODescriptor]');
89 if ($idps && is_array($idps) && isset($idps[0]) && $idps[0] instanceof SimpleXMLElement) {
103 $error =
new LibXMLError();
104 $error->level = LIBXML_ERR_FATAL;
106 $error->message =
'No entityID found';
112 $this->
result = $this->dataFactory->error($this->errorFormatter->formatErrors(...$errors));
113 }
catch (Exception
$e) {
114 $this->
result = $this->dataFactory->error($this->errorFormatter->formatErrors(...$this->endLogging()));
A result encapsulates a value or an error and simplifies the handling of those.
A result encapsulates a value or an error and simplifies the handling of those.