Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Xml Laravel Package

veewee/xml

Type-safe, declarative XML toolkit for PHP. Includes DOM helpers, safe error handling, memory-safe reader/writer, XML encode/decode, plus XSD and XSLT utilities. Spec-compliance ready for PHP 8.4+, with maintained v3 for older PHP.

View on GitHub
Deep Wiki
Context7

ErrorHandling Component

The biggest advantage of this package is that it deals with all XML errors for you! Normally, the PHP API would return false and triggers PHP warnings. We provide the tools to deal with this and to get a clear Exception that tells you what is wrong, so that you can focus on fixing the issue!

All our components are using the ErrorHandling component. If you want to extend the provided functionality, you can always use our error handling tools as well!

The ErrorHandling component consists out of following blocks:

Assertions

Assertions validate input and throw an InvalidArgumentException if the input is invalid.

assert_strict_prefixed_name

Some functions require you to pass a strict prefixed name: prefix:localName="someting". This assertions validates it for you!

assert_strict_qualified_name($qualifiedName);

Blockers

Blockers don't mess around with errors ... !

disallow_issues

This function takes a callable as input and fetches all triggered XML specific warnings. If the provided function throws any Exception, it will wrap the detected issues with it and rethrow that new exception! You will frequently use it together with disallow_libxml_false_returns to make sure the result type is safe to use!

use function VeeWee\Xml\ErrorHandling\disallow_issues;
use function VeeWee\Xml\ErrorHandling\disallow_libxml_false_returns;

/** [@var](https://github.com/var) true $result */
$result = disallow_issues(
    static fn (): bool => disallow_libxml_false_returns(
        $document->load('some-file.xml'),
        'Could not load the DOM Document'
    )
);

disallow_libxml_false_returns

In PHP, a lot of XML related functions return false. This function deals with the false return and throws an InvalidArgumentException if that is the case. You must provide a clear and helpful error message for failure cases:

use function VeeWee\Xml\ErrorHandling\disallow_libxml_false_returns;

/** [@var](https://github.com/var) true $result */
$result = disallow_libxml_false_returns(
    $document->load('some-file.xml'),
    'Could not load the DOM Document'
);

stop_on_first_issue

This function can be used in situations where you want to wrap error handling on lazy iterators (generators). Before every tick, it will wrap error handling around the executed functionality. Once the tick is done, it will check for errors and throw an exception if that's the case:

use function VeeWee\Xml\ErrorHandling\stop_on_first_issue;

/** [@var](https://github.com/var) Generator<string> $result */
$result = stop_on_first_issue(
    static fn(): bool => $reader->read(),
    static fn(): ?string =>
        $reader->nodeType === XMLReader::ELEMENT && $reader->name === 'user'
            ? $reader->readOuterXml() ?: null
            : null,
);

Detectors

In some cases, you don't want errors to block. Especially in situations where you want to validate the XML document based on XSD, DTD, ...

detect_issues

This function detects XML issues in a provided callback function. It returns both the result of the executed function and the detected issues.

use Psl\Result\Success;
use Psl\Result\Failure;
use VeeWee\Xml\ErrorHandling\Issue\IssueCollection;
use VeeWee\Xml\Exception\ExceptionInterface;
use function VeeWee\Xml\ErrorHandling\detect_issues;

/** [@var](https://github.com/var) Success<bool>|Failure<ExceptionInterface> $result */
/** [@var](https://github.com/var) IssueCollection $issues */

[$result, $issues] = detect_issues(
    static fn () => $document->schemaValidate($xsd)
);

Issues

An issue is what we call an XML error. It looks like this:

namespace VeeWee\Xml\ErrorHandling\Issue;

#[Immutable]
final class Issue
{
    public function level(): Level;
    public function code(): int;
    public function column(): int;
    public function message(): string;
    public function file(): string;
    public function line(): int;

    public function toString(): string;
}

The Level is an enum with following supported values:

namespace VeeWee\Xml\ErrorHandling\Issue;

#[Immutable]
final class Level
{
    public static function error(): self;
    public static function fatal(): self;
    public static function warning(): self;
}

This component often gives you a collection of issues to work with:

namespace VeeWee\Xml\ErrorHandling\Issue;

#[Extends iterable<Issue>]
#[Immutable]
final class IssueCollection implements Countable, IteratorAggregate
{
    // Check the source code for a list of all functions you can use on this collection! 
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor