SAT publishes three types of XML resources that CfdiUtils needs at runtime: XSD schema files for structural validation, XSLT transform files for generating the Cadena de Origen, and CER certificate files for signature verification. These resources are large (the SAT catalogue XSD alone is over 6 MB), change infrequently, and live at remote URLs. Fetching them from the internet on every operation would be slow, unreliable, and wasteful.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/eclipxe13/CfdiUtils/llms.txt
Use this file to discover all available pages before exploring further.
CfdiUtils\XmlResolver\XmlResolver solves this by maintaining a local file-system cache: the first time a resource is needed it is downloaded and stored; subsequent requests use the local copy.
A secondary problem is that SAT resources reference each other using absolute URLs, not relative paths. XmlResolver handles this transparently through the underlying eclipxe/xml-resource-retriever library, which rewrites embedded references to point at the local copies as it downloads each file.
How It Works
Whenresolve(string $resource, string $type) is called:
- No local path configured → the original remote URL is returned unchanged.
- Local path configured, file exists → the local file path is returned immediately, no network request.
- Local path configured, file missing → the resource is downloaded (along with its dependencies), stored under the local path, and the local file path is returned.
XSD, XSLT, or CER) determines which retriever is used. The type is inferred automatically from the file extension when not specified explicitly.
Default Local Path
When no path is provided,XmlResolver stores resources at:
Configure the Local Path
Pass the local path to the constructor, or callsetLocalPath() on an existing instance. Both accept the same three-case logic:
null— use the default path (<library>/build/resources/)''(empty string) — disable local caching entirely; all resources resolve to their remote URLs- any other string — use that directory as the cache root (e.g.
'/tmp/sat/')
Using XmlResolver with Creators and Validators
Pass your configuredXmlResolver instance to any CfdiUtils object that needs it via setXmlResolver() or its constructor.
CfdiCreator40 or CfdiCreator33 without providing a resolver, a default one is created automatically. You can retrieve and configure it in place:
Custom Downloader
The default downloader uses PHP’s built-infile_get_contents(). If your server is behind a corporate proxy or needs special HTTP headers, implement Eclipxe\XmlResourceRetriever\Downloader\DownloaderInterface and pass your implementation to the resolver.
Invalidating the Cache
There is no TTL or expiry mechanism — the local cache is valid until you delete it. When SAT publishes updated XSD or XSLT files, delete the affected files from the cache directory and they will be re-downloaded on the next request. To refresh all SAT schema files:During the download phase, network access is required. If the SAT servers are unavailable — which happens occasionally — CfdiUtils will throw an exception. The PHPCfdi project provides a pre-packaged mirror of the most common SAT resources at phpcfdi/resources-sat-xml that you can copy into your local path to avoid depending on SAT availability.
Resolving the Cadena de Origen XSLT Location
XmlResolver exposes a convenience method that looks up the correct XSLT file for a given CFDI version:
'3.3', '4.0'.