-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Models\Entity; | ||
use DOMNode; | ||
use DOMXPath; | ||
|
||
abstract class TagService | ||
{ | ||
abstract public function create(Entity $entity); | ||
|
||
abstract public function delete(Entity $entity); | ||
|
||
abstract public function update(Entity $entity); | ||
|
||
protected function buildXPathQuery(string $value): string | ||
{ | ||
return "//saml:AttributeValue[text()='$value']"; | ||
} | ||
|
||
protected function getRootTag(DOMXPath $xPath): DOMNode | ||
{ | ||
$rootTag = $xPath->query("//*[local-name()='EntityDescriptor']")->item(0); | ||
if (! $rootTag) { | ||
throw new \RuntimeException('Root tag EntityDescriptor not found'); | ||
} | ||
|
||
return $rootTag; | ||
} | ||
|
||
protected function getOrCreateExtensions(DOMXPath $xPath, \DOMDocument $dom, \DOMNode $rootTag, string $mdURI): \DOMNode | ||
{ | ||
$extensions = $xPath->query('//md:Extensions'); | ||
if ($extensions->length === 0) { | ||
$extensions = $dom->createElementNS($mdURI, 'md:Extensions'); | ||
$rootTag->appendChild($extensions); | ||
} else { | ||
$extensions = $extensions->item(0); | ||
} | ||
|
||
return $extensions; | ||
} | ||
|
||
protected function getOrCreateEntityAttributes(\DOMXPath $xPath, \DOMDocument $dom, \DOMNode $extensions, string $mdattrURI): \DOMNode | ||
{ | ||
$entityAttributes = $xPath->query('//mdattr:EntityAttributes'); | ||
if ($entityAttributes->length === 0) { | ||
$entityAttributes = $dom->createElementNS($mdattrURI, 'mdattr:EntityAttributes'); | ||
$extensions->appendChild($entityAttributes); | ||
} else { | ||
$entityAttributes = $entityAttributes->item(0); | ||
} | ||
|
||
return $entityAttributes; | ||
} | ||
} |