Download the PHP package i-complex/xsd2php without Composer
On this page you can find all versions of the php package i-complex/xsd2php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package xsd2php
xsd2php
Convert XSD into PHP classes.
With goetas-webservices/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 all XSD files in /home/my/ota
, first of all we need a configuration file
(as example config.yml
) that will keep all the namespace and directory mappings information.
Here is an explanation on the meaning of each parameter:
-
xsd2php.namespaces
(required) defines the mapping between XML namespaces and PHP namespaces. (in the example we have thehttp://www.example.org/test/
XML namespace mapped toTestNs\MyApp
) -
xsd2php.destinations_php
(required) specifies the directory where to save the PHP classes that belongs toTestNs\MyApp
PHP namespace. (in this exampleTestNs\MyApp
classes will be saved intosoap/src
directory. -
xsd2php.destinations_jms
(required) specifies the directory where to save JMS Serializer metadata files that belongs toTestNs\MyApp
PHP namespace. (in this exampleTestNs\MyApp
metadata will be saved intosoap/metadata
directory. -
xsd2php.aliases
(optional) specifies some mappings that are handled by custom JMS serializer handlers. Allows to specify to do not generate metadata for some XML types, and assign them directly a PHP class. For that PHP class is necessary to create a custom JMS serialize/deserialize handler. -
xsd2php.naming_strategy
(optional) specifies the naming strategy to use when converting XML names PHP classes. -
xsd2php.path_generator
(optional) specifies the strategy to use for path generation and file saving -
xsd2php.known_locations
(optional) override remote location with a local file. -
xsd2php.known_namespace_locations
(optional) Specify schema location by namespace. This can be used to read schemas which import namespaces but do not specify schemaLocation attributes. xsd2php.configs_jms.xml_cdata
(optional) Specify if CDATA should be used or not in serialization.
Generate PHP classes and JMS metadata info
This command will generate PHP classes and JMS metadata files for all the XSD files matching /home/my/ota/OTA_Air*.xsd
and using the configuration available in config.yml
Serialize / Unserialize
XSD2PHP can also generate for you JMS Serializer metadata that you can use to serialize/unserialize the generated PHP class instances.
The parameter aliases
in the configuration file, will instruct XSD2PHP to not generate any metadata information or
PHP class for the {http://www.example.org/test/}MyCustomXSDType
type.
All reference to this type are replaced with the MyCustomMappedPHPType
name.
You have to provide a custom serializer for this type/alis.
Here is an example on how to configure JMS serializer to handle custom types
To disable the CDATA, configure JMS as so:
Validation
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
short
option. - If you have naming conflicts use the
long
option. - If you want to be safe, use the
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.7|^3.0|^4.0|^5.0|^6.0
symfony/dependency-injection Version ^2.2|^3.0|^4.0|^5.0|^6.0
symfony/yaml Version ^2.2|^3.0|^4.0|^5.0|^6.0
symfony/config Version ^2.2|^3.0|^4.0|^5.0|^6.0
i-complex/xsd-reader Version ^0.1
doctrine/inflector Version ^2.0
laminas/laminas-code Version ^3.3.2|^4.0
psr/log Version ^1.0 | ^2.0 | ^3.0