GithubHelp home page GithubHelp logo

moyarada / xsd-to-php Goto Github PK

View Code? Open in Web Editor NEW
119.0 15.0 44.0 1.24 MB

Legko XML: compile XSD schema to PHP, XML marshalling/unmashalling

Home Page: http://mikebevz.com/xsd-to-php-tool/

License: Other

Shell 0.01% PHP 99.74% XSLT 0.26%

xsd-to-php's Introduction

Legko XML

!!!!
Note: We are constantly looking for user stories on how they used LegkoXML (XSD2PHP).
If you would like to help to our project, please send your story about how you have used
LegkoXML in your project. Email is myb (at) mikebevz (dot) com. 
!!!!

See PhpDocs at http://legkoxml.org/docs
Discussion Group http://groups.google.com/group/legkoxml-support

With the present library you are able to compile PHP binding from XML Schema files, 
and consequently, bind XML files to PHP models (unmarshalling), and save PHP bindings 
as XML (marshalling).

Versions history

Current release
 # Fixed #24: Fix problem with WSDL generation - soap:operation must not have any child 

0.0.5 Major refactoring 
 # Fixed #17: Array of objects is not converted to XML correctly
 # Implemented #12: Feature: WSDL generator utilizing existing mapping in classes
 # Added NullLogger - mock for logger. It will be used later for #18: Feature: Logger injection
 # #13 Command line tool: Initial version developed, compile-schema target only.
 # #8 Create facade class: Initial version implemented, only compileSchema method works. (See LegkoXml.php)
 
0.0.4 Issue #12. WSDL autodiscovery
 # Fixed #10: Directory structure do not correspond to PHP namespaces
 # Fixed #5: Add debug output option to XSD2PHP
 # Fixed #9: Generated WSDL tested with Zend_Soap
 # WSDL tested with Apache CXF

0.0.3 XML generation refactored
 # namespaces generated as ns0 ... nsX 
 # Fixed #4: added @var to PHP models with full class name (with namespace)
 
0.0.2 XSD Imports and includes routines rewritten
 # Refactored XSD import and include tags processing
 # Fixed problem with numeric namespaces in generated PHP models
 # Added new test cases: Multi level include and import processing, custom schema based on UBL2.0
 
0.0.1 Initial release
 # Compile XSD to PHP
 # Marshal/unmarshal XML 


==========
If you wanna help the project you are welcome to donate BitCoins. Send those to account 1P6iMj85EmYMqgxDkNkDVWWMm7h5EmMM7a

xsd-to-php's People

Contributors

danishmalik-maplesoftwares avatar hakito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xsd-to-php's Issues

Check marshalling/unmarshalling against XMLSchema/model metadata

In the process of marshalling a PHP class instance to XML, PhpXml should:

  • throw an exception if class attribute has incompatible data type (@var annotation)
  • throw an exception if we have minOccurs = 1 and no value has been provided
  • not include an element in xml if its related attribute is null and minOccurs = 0

toArray() helper method

Implement a method, which return a PHP model as an array.
For example,






Will return an array

array(
    "adGroupId" => 0,
    "adType" => 'TextAd',
    //...
)

support for include/import remote schemas

It seems that including and importing remote schema isn't supported. Bunches of empty "importing message" are printed on screen, and nothing is generated.

So I've made some change to the PHP and XSL a bit. I seems working on my box. How should I upload them?

Feature: WSDL generator utilizing existing mapping in classes

I've tried to use Zend_Soap_Autodiscovery, and it turned out that it doesn't support namespaces in the way it can be of any use by Apache CXF. After some research I've found nothing, so it would be great to have a method, which can generate WSDL for a service, which uses PHP models already generated by XSD compiler.

Example:
Given a class, which must be exposed as webservice:

class ExampleService
{
/**
  * Extract name from ContactPerson model
  * 
  * @param dk\nordsign\schema\ContactPerson\ContactPerson $contactPerson Contact person model
  * 
  * @return string
  */
  public function update(dk\nordsign\schema\ContactPerson\ContactPerson $contactPerson) {
     // use contactPerson as follows
     $name = $contactPerson->name;
     return $name;
  }
}

Example SOAP server would look like

$service = new ExampleService();
if(isset($_GET['wsdl'])) {
  $legkoWsdl = new xsd2php\Wsdl($service);
  $legkoWsdl->setLocation("http://localhost:10088/api/soap.php");
  $legkoWsdl->setSchemasPath("../../application/resources/xsd");
  echo $legkoWsdl->getWsdl(); 
} else {
  $soap = new Zend_Soap_Server("http://localhost:10088/api/test.wsdl");
  $soap->setObject($service);
  $soap->handle();    
}

Restrict model class name charset

Using HL7 XSD schema https://dl.dropboxusercontent.com/u/8709992/HL7.xsd, I found that elements with periods in their name attributes were converted into classes with periods in their names, which is illegal syntax based on the PHP standard. I recommend name attributes be processed and substituted with legal characters as this is probably a general issue, not restricted to periods.

I do not receive an error or warning when generating the PHP classes from the XSD file. Rather PHP throws an error when trying to load the files.

This library seems good, but unfortunately due to lack of documentation and minor hangups, I'm going to parse my XML files manually. Not to dissuade you from working on the tool. But I've found most people have a low threshold for incorporating these sorts of libraries and will quickly fall back to one-off hacks due to time constraints.

Add debug output option to XSD2PHP

It was added as the second argument of the constructor.

Example:
// Show debug output
$this->tclass = new xsd2php\Xsd2Php("../resources/ContactCompany/ContactCompany.xsd", true);
// Clean run
$this->tclass = new xsd2php\Xsd2Php("../resources/ContactCompany/ContactCompany.xsd", true);

Doesn't run, goes into infinite loop for imports with URL schemaLocation

I tried to run this on the SAML2 spec ([http://docs.oasis-open.org/security/saml/v2.0/saml-2.0-os.zip]) but the code seems to produce a fatal error on an undefined variable in the XSL file and it goes into an infinite loop (using Gbs of memory) when encountering an import when a URL in the schemaLocation.
These problems are fixed in the fork.

After fixing this the SAML2 classes still have issues with the namespace and classdefinition.

Research on Zend_Soap classmap feature

Preliminary Zend_Soap didn't work with namespaces and objects received in service classes weren't equal to specified in WSDL.

There should be implemented a method, which returns a classmap for given service class.

For example,
$service = new services\ExampleService();
$legkoXml = new xsd2php\Wsdl($service);
$soap = new Zend_Soap_Server("http://localhost/api/soap.php?wsdl");
$soap->setObject($service);
$soap->setClassmap($legkoXml->getClassMap());
$soap->handle();

getClassMap() should return an associative array as follows:

array('SOAP Type' => 'PHP Class',
       'SOAP Type' => 'PHP Class',
        ....
      )

Create facade class

It's better to have one class, that's responsible for all operation, instead of three different classes.
For example,

$xtp = new Xtp();

// Compile XSD

$xtp->generateCode($xsdFile);

// Marshal XML

$xtp->marshal($model, $xmlFile);

// Unmarshal XML

$xtp->unmarshal($xml);

Generated PHP models are not accepted by Zend_Soap

Error: Fatal error: Uncaught exception 'Zend_Soap_Wsdl_Exception' with message 'Cannot add a complex type dk\nordsign\schema\ContactPerson\IDType that is not an object or where class could not be found in 'DefaultComplexType' strategy.

missing namespace field in my fork

Hi. I forked this repo and added a composer.json file (along with cleaning up the "require_once" lines and the namespaces) and ran the unit tests, but I'm getting a mismatch between the expected xml output in the tests and the generated ones. The difference is that the namespaces are now empty. If you look here, you can see the empty namespaces. I tried to debug this to figure out where I went wrong, but I couldn't figure it out. Can someone help me fix this so I can make a PR afterwards? My fork is here. Thanks

Map simpleType restriction to constants

IMHO, mapping a simpleType restriction to a group of static members would help producing less error-prone code.

e.g. mapping

<xs:simpleType name="ActivityStatus">
    <xs:restriction base="xs:string">
        <xs:enumeration value="pending"/>
        <xs:enumeration value="in_progress"/>
                    ...
    </xs:restriction>
</xs:simpleType>

to

class ActivityStatus {
     public static $PENDING = "pending";
     public static $IN_PROGRESS = "in_progress";
     ....
}

would allow a safer usage of ActivityStatus values

    $myStatus = ActivityStatus::$PENDING;

Command line tool

This tool should expose all functionality of the LegkoXML.

Examples:

$ legko compile-schema -xsd schema.xsd -dest ./generated/classes
$ legko generate-wsdl -service path/to/Service.php -xsd-dir path/to/schema -dest ./generated/wsdl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.