Convert XSD into PHP classes.
With goetas/xsd2php you can convert any XSD/WSDL definition into PHP classes.
XSD2PHP can also generate JMS Serializer compatible metadata that can be used to serialize/unserialize the object instances.
There are two recommended ways to install xsd2php via Composer:
- adding the dependency to your
composer.jsonfile:
"require": {
..
"goetas/xsd2php":"2.*@dev",
"goetas/xsd-reader":"2.*@dev",
..
}With this example we will convert OTA XSD definitions into PHP classes.
Suppose that you have allo XSD files in /home/my/ota.
bin/xsd2php.php convert:php \
`/home/my/ota/OTA_HotelAvail*.xsd \
--ns-map='http://www.opentravel.org/OTA/2003/05; Mercurio/OTA/2007B/' \
--ns-dest='Mercurio/OTA/2007B/; src/Mercurio/OTA/V2007B;' \
--alias-map='Vendor/Project/CustomDateClass; http://www.opentravel.org/OTA/2003/05#CustomOTADateTimeFormat'
What about namespaces?
http://www.opentravel.org/OTA/2003/05will be converted intoMercurio/OTA/2007BPHP namespace
Where place the files?
Mercurio/OTA/2007Bclasses will be placed intosrc/Mercurio/OTA/V2007Bdirectory
What about custom types?
--alias-map='Vendor/Project/CustomDateClass;http://www.opentravel.org/OTA/2003/05#CustomOTADateTimeFormat'will instcut XSD2PHP to do not generate any class forCustomOTADateTimeFormattype insidehttp://www.opentravel.org/OTA/2003/05namesapce. All reference to this type are replaced with theVendor/Project/CustomDateClassclass.
XSD2PHP can also generate for you JMS Serializer metadata that you can use to serialize/unserialize the generated PHP class instances.
bin/xsd2php.php convert:jms-yaml \
`/home/my/ota/OTA_HotelAvail*.xsd \
--ns-map='http://www.opentravel.org/OTA/2003/05;Mercurio/OTA/2007B/' \
--ns-dest='Mercurio/OTA/2007B/;src/Metadata/JMS;' \
--alias-map='http://www.opentravel.org/OTA/2003/05#CustomOTADateTimeFormat;Vendor/Project/CustomDateClass'
What about namespaces?
http://www.opentravel.org/OTA/2003/05will be converted intoMercurio/OTA/2007BPHP namespace
Where place the files?
http://www.opentravel.org/OTA/2003/05will be placed intosrc/Metadata/JMSdirectory
What about custom types?
--alias-map='Vendor/Project/CustomDateClass;http://www.opentravel.org/OTA/2003/05#CustomOTADateTimeFormat'will instcut XSD2PHP to do not generate any metadata infmation forCustomOTADateTimeFormattype insidehttp://www.opentravel.org/OTA/2003/05namesapce. All reference to this type are replaced with theVendor/Project/CustomDateClassclass. You have to provide a custom serializer for this type

