- What is goetas-webservices/xsd2php-runtime used for?
- It is the runtime support package for PHP classes generated by goetas-webservices/xsd2php from XML Schema (XSD) definitions. It supplies the base classes, interfaces, JMS Serializer handlers and metadata, and type converters that generated DTOs need so XML or SOAP payloads can be hydrated into PHP objects and serialized back with schema-defined types and namespaces preserved. It does not generate code itself; that is the job of the separate xsd2php generator.
- Does xsd2php-runtime work with Laravel?
- Yes, but there is no Laravel service provider or facade, so integration is manual. You install the runtime plus JMS Serializer, add your generated classes under a dedicated namespace such as App\Infrastructure\Xml\Generated, register the serializer handlers, and bind a configured serializer or adapter as a singleton in one of your own service providers. Keep generated schema objects at the integration boundary and map them to domain DTOs or Eloquent models rather than letting them leak into application code.
- How do I install goetas-webservices/xsd2php-runtime with Composer?
- Run composer require goetas-webservices/xsd2php-runtime, which pulls in the runtime base classes and helpers. You will also need jms/serializer configured in your application, and the classes produced by the xsd2php generator either committed to your repository or built as an artifact. Because there is no auto-discovery, expect to write a small service provider that wires the serializer and your XML adapter.
- Do I need the xsd2php generator as well as this runtime package?
- Yes. This package is only the runtime half of the pair and contains nothing that reads XSD files. You use goetas-webservices/xsd2php to generate PHP model classes from your schema, typically as a dev dependency or in CI, and this runtime provides the classes and JMS Serializer handlers those generated models extend and rely on. A common setup is the generator in require-dev and the runtime in require so production deployments stay lightweight.
- Which PHP, Laravel and Symfony versions does xsd2php-runtime support?
- Release 0.2.18 adds Symfony 8.0 support, so the constraint now spans Symfony 5.x through 8.x components, with CI running on PHP versions above 8.0. Laravel itself pins specific symfony/* component ranges, so the practical limit is the intersection Composer resolves for your Laravel version, JMS Serializer and PHP. Check with composer why-not if resolution fails, and remember the generator and runtime versions should be pinned together.
- How do I deserialize an XML or SOAP payload into generated PHP objects in Laravel?
- Configure a JMS Serializer instance with the XML handlers and metadata this runtime provides, then call deserialize with the generated class name and the raw XML string. Register that serializer configuration and a thin adapter service in a Laravel service provider, and expose narrow methods such as parsePartnerOrder or submitClaimXml to the rest of the application. Always feed the serializer a specific generated class rather than an arbitrary type chosen from user input.
- Should I commit xsd2php-generated classes or generate them at build time?
- Either works, but generation should happen in development or CI, never during a production request. Committing generated classes makes code review and drift visible, while generating in CI keeps the repository small but requires a deterministic generator version and a diff check against the XSD. In both cases pin the generator and runtime versions and add fixture-based serialization and deserialization tests so schema changes fail the build instead of production.
- Is xsd2php-runtime safe for parsing untrusted XML payloads (XXE)?
- The runtime itself does not add XML parsing hardening, so protection depends on how the underlying serializer and libxml are configured. Disable external entity loading, reject documents containing DOCTYPE declarations, cap payload size and depth, and validate against the XSD before hydration. If you accept XML from third parties, treat deserialization as an untrusted-input boundary and test it with malicious fixtures.
- What are the alternatives to xsd2php-runtime for XML and SOAP integrations in Laravel?
- Alternatives include other XSD or WSDL code generators, Symfony Serializer with custom normalizers and encoders, hand-written DTO mapping, or a vendor-provided SDK when the counterparty supplies one. xsd2php is strongest when you have real XSD contracts and want generated, schema-accurate models with JMS Serializer handling namespaces and types. For JSON-first APIs or domains without stable schemas, a full XSD toolchain is usually unnecessary overhead.
- Is goetas-webservices/xsd2php-runtime actively maintained and is upgrading risky?
- The project is identifiable, uses tagged releases and MIT licensing, and has CI covering multiple PHP versions, though the contributor pool is small. The 0.2.18 release only changed dependency constraints and CI coverage with no functional or API changes, so upgrading from 0.2.17 carries essentially no risk. The real risk sits in the surrounding ecosystem: JMS Serializer version conflicts, Symfony component ranges, and generated-code drift when your XSDs change.