Download the PHP package goetas/xsd2php without Composer
On this page you can find all versions of the php package goetas/xsd2php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package xsd2php
xsd2php
This repository is DEPRECATED, please use goetas-webservices/xsd2php
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.
Installation
There is one recommended way to install xsd2php via Composer:
- adding the dependency to your
composer.json
file:
Usage
With this example we will convert OTA XSD definitions into PHP classes.
Suppose that you have allo XSD files in /home/my/ota
.
Generate PHP classes
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='http://www.opentravel.org/OTA/2003/05;CustomOTADateTimeFormat;Vendor/Project/CustomDateClass'
will instruct XSD2PHP to not generate any class forCustomOTADateTimeFormat
type inside thehttp://www.opentravel.org/OTA/2003/05
namespace. All reference to this type are replaced with theVendor/Project/CustomDateClass
class.
Use composer scripts to generate classes
Now you can build your classes with composer build
.
Serialize / Unserialize
XSD2PHP can also generate for you JMS Serializer metadata that you can use to serialize/unserialize the generated PHP class instances.
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='http://www.opentravel.org/OTA/2003/05;CustomOTADateTimeFormat;Vendor/Project/CustomDateClass'
will instruct XSD2PHP to not generate any metadata information forCustomOTADateTimeFormat
type inside thehttp://www.opentravel.org/OTA/2003/05
namespace. All reference to this type are replaced with theVendor/Project/CustomDateClass
class. You have to provide a custom serializer for this type - Add xsd2php dependency to satisfy BaseTypesHandler and XmlSchemaDateHandler.
Dealing with xsd:anyType
or xsd:anySimpleType
If your XSD contains xsd:anyType
or xsd:anySimpleType
types you have to specify a handler for this.
When you generate the JMS metadata you have to specify a custom handler:
Now you have to create a custom serialization handler:
Naming Strategy
There are two types of naming strategies: short
and long
. The default is short
, this naming strategy can however generate naming conflicts.
The long
naming strategy will suffix elements with Element
and types with Type
.
MyNamespace\User
will becomeMyNamespace\UserElement
MyNamespace\UserType
will becomeMyNamespace\UserTypeType
An XSD for instance with a type named User
, a type named UserType
, a root element named User
and UserElement
, will only work when using the long
naming strategy.
- If you don't have naming conflicts and you want to have short and descriptive class names, use the
--naming-strategy=short
option. - If you have naming conflicts use the
--naming-strategy=long
option. - If you want to be safe, use the
--naming-strategy=long
option.
Note
The code in this project is provided under the MIT license. For professional support contact [email protected] or visit https://www.goetas.com
All versions of xsd2php with dependencies
symfony/console Version ^2.1|^3.0
symfony/yaml Version ^2.1|^3.0
goetas-webservices/xsd-reader Version ^0.1.2
doctrine/inflector Version ^1.0
zendframework/zend-code Version ~2.3