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.json
file:
"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/05
will be converted intoMercurio/OTA/2007B
PHP namespace
Where place the files?
Mercurio/OTA/2007B
classes will be placed intosrc/Mercurio/OTA/V2007B
directory
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 forCustomOTADateTimeFormat
type insidehttp://www.opentravel.org/OTA/2003/05
namesapce. All reference to this type are replaced with theVendor/Project/CustomDateClass
class.
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/05
will be converted intoMercurio/OTA/2007B
PHP namespace
Where place the files?
http://www.opentravel.org/OTA/2003/05
will be placed intosrc/Metadata/JMS
directory
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 forCustomOTADateTimeFormat
type insidehttp://www.opentravel.org/OTA/2003/05
namesapce. All reference to this type are replaced with theVendor/Project/CustomDateClass
class. You have to provide a custom serializer for this type