19declare(strict_types=1);
31 private readonly DataTypeFactory $dataFactory,
38 if ([] === $this->errorStack) {
39 $this->xmlErrorState = libxml_use_internal_errors(
true);
40 libxml_clear_errors();
45 $this->errorStack[] = [];
50 $currentErrors = libxml_get_errors();
51 libxml_clear_errors();
53 $level = count($this->errorStack) - 1;
54 $this->errorStack[$level] = array_merge($this->errorStack[$level], $currentErrors);
64 $errors = array_pop($this->errorStack);
66 if ([] === $this->errorStack) {
67 libxml_use_internal_errors($this->xmlErrorState);
81 $xml =
new SimpleXMLElement($xmlString);
83 $xml->registerXPathNamespace(
'md',
'urn:oasis:names:tc:SAML:2.0:metadata');
84 $xml->registerXPathNamespace(
'mdui',
'urn:oasis:names:tc:SAML:metadata:ui');
86 $idps = $xml->xpath(
'//md:EntityDescriptor[//md:IDPSSODescriptor]');
88 $entity_id = ($idps[0] ??
null)?->attributes(
'',
true)[
'entityID'][0] ??
'';
89 $entity_id = (string) $entity_id;
91 if ($entity_id !==
'') {
92 return $this->
ok($entity_id);
95 $error =
new LibXMLError();
96 $error->level = LIBXML_ERR_FATAL;
98 $error->message =
'No entityID found';
102 return $this->
error([$error]);
103 }
catch (Exception) {
104 return $this->
error();
112 return $this->dataFactory->ok($entity_id);
120 return $this->dataFactory->
error($this->errorFormatter->formatErrors(...$this->endLogging(), ...$additional_errors));
A result encapsulates a value or an error and simplifies the handling of those.
error()
Get the encapsulated error.