-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
24 changed files
with
437 additions
and
80 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
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,79 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Xml\Node; | ||
|
||
use DOMElement; | ||
use Stringable; | ||
use VeeWee\Xml\Dom\Document; | ||
use function Psl\invariant; | ||
|
||
final class Element implements Stringable | ||
{ | ||
private ?DOMElement $element = null; | ||
/** | ||
* @var non-empty-string|null | ||
*/ | ||
private ?string $value = null; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param non-empty-string $xml | ||
*/ | ||
public static function fromString(string $xml): Element | ||
{ | ||
$new = new self(); | ||
$new->element = null; | ||
$new->value = $xml; | ||
|
||
return $new; | ||
} | ||
|
||
public static function fromDOMElement(DOMElement $element): self | ||
{ | ||
$new = new self(); | ||
$new->element = $element; | ||
$new->value = null; | ||
|
||
return $new; | ||
} | ||
|
||
public function element(): DOMElement | ||
{ | ||
if (!$this->element) { | ||
invariant($this->value !== null, 'Expected an XML value to be present'); | ||
$this->element = Document::fromXmlString($this->value)->locateDocumentElement(); | ||
} | ||
|
||
return $this->element; | ||
} | ||
|
||
/** | ||
* @return non-empty-string | ||
*/ | ||
public function value(): string | ||
{ | ||
if ($this->value === null) { | ||
invariant($this->element !== null, 'Expected an DOMElement to be present'); | ||
$this->value = Document::fromXmlNode($this->element)->stringifyDocumentElement(); | ||
} | ||
|
||
return $this->value; | ||
} | ||
|
||
public function document(): Document | ||
{ | ||
return Document::fromUnsafeDocument($this->element()->ownerDocument); | ||
} | ||
|
||
/** | ||
* @return non-empty-string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->value(); | ||
} | ||
} |
Oops, something went wrong.