Giter Club home page Giter Club logo

oxm's Introduction

Doctrine 2 OXM

Doctrine OXM is a PHP 5.3 project for PHP object to XML mapping that provides support for persisting the XML to a file system via common Doctrine techniques.

Note: This project is still in it's infancy and should not be used for any production related code. Its API is still quite unstable and not all features are yet implemented. Any help in advancing the project forward would be welcome. Let the forking begin!

XmlEntityManager

Based on the EntityManager of the Doctrine 2 ORM project. Objects mapped as an @XmlRootEntity may be managed by the XmlEntityManager. As these objects are persisted, they are saved in XML format to the file system under a user configured directory and naming scheme.

$user = new User();
$user->setId(1);
$user->setName("Malcolm Reynolds");
$user->setOccupation("Space Cowboy");

$em->persist($user);
$em->flush();            // saves marshalled user object as XML to the file system.

The XmlEntityManager also allows access to repository type objects for loading entities back again.

$user = $em->getRepository("User")->findById(1);

Xml Marshallers

OXM also provides first class support for the Marshalling and Unmarshalling of PHP Objects to XML and vice-versa based on ideas within the Java Castor XML mapping project. Class metadata for mapped class may be configured via @Annotations, XML, Yaml, or even PHP itself. Marshallers will uses this class metadata to convert your defined objects to XML, as well as reading in XML and converting them to objects.

The behavior of the marshalling and unmarshalling process is completely configurable by the defined class metadata. You can specify the exact xml names for each element, and how they map to the fields of your class. XML attributes, elements, and "text" nodes are all supported, as well as collections.

Marshallers are utilized by the XmlEntityManager internally, but are also provided to be used as first class citizens within your code for whatever you need. This makes working with XML in your application so much easier because you don't really have to think about it anymore!

Example use case:

$xml = $this->getRequest()->getParam('posted_xml');

$order = $marshaller->unmarshalFromString($xml);
$this->view->message = "Order recieved:  " . $order->getId();

$update = new UpdateNotification("Order " . $order->getId() . " was received by the application");
$xml = $marshaller->marshalToString($update);

$this->sendToExternalService($xml);

Run tests

Install PHPUnit (>= 3.5)

Copy the phpunit.xml

cp ./phpunit.xml.dist ./phpunit.xml

Run the tests

phpunit ./tests

API DOCUMENTATION - todo

oxm's People

Contributors

beberlei avatar fightmaster avatar gromnan avatar igorgolovanov avatar jakzal avatar richardfullmer avatar

Watchers

 avatar  avatar

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.