A php sources class/interface generator from UML Models in XMI. It has been written using the great Acceleo eclipse plugin.
Make sure a java runtime and Maven >= 3+ is installed in your system. Clone this repository somewhere in your drive and launch the compilation using Maven :
mkdir /destpath
cd /destpath
git clone https://github.com/TiBeN/UmlToPhpGenerator ./
mvn clean package
To launch the generator, go to the folder where you cloned the github repository then type:
$ cd /repo-folder
$ mvn exec:java -Dumltophp.model="/path/to/your/model/file.uml" -Dumltophp.out="/out"
where /path/to/your/model/file.uml
is the path to your dot uml model file made with some eclipse EMF compatible tool like Papyrus and /out
is the output path where the PHP classes will be generated.
For the generator handle your UML model correctly, you should consider some rules :
Once the generation is done. You can edit the generated classes inside some markers :
// Start of user code of SomeClass.someMethod
Place your code here
//
Edit only your classes inside theses marker and don't remove them! They are used by the generator to update yours classes/interfaces according to the changes made in the model without erase your handwritten code. If you change the name of yours class methods in your model or remove some of thems, don't worry, the generator will backup the lost code inside some txt file. Theses behavior are made possible thanks to the Acceleo nature of project. For more information about the global behavior of the generator, please take a look at The Acceleo Project
Once Acceleo plugin installed inside eclipse, create a new Acceleo project then simply import the .mtl sources files available at src/main/java/umltophp/main/
of this project. Please refer to Acceleo documentation for more information.
Note : This use case could be improved (see TODO.md)
For the sake of the design of a web Framework i started to make some diagrams for modeling the components of the framework by using Eclipse Papyrus. I read at the same time a lot of articles about software design and especially on MDA/MDE methodologies. The case of this web framework was a great "pretext" to go a bit further into my discovery of the MDE design.
So I've started to integrate the auto generation ("model to text") of class skeletons of this project into my workflow. For this purpose the eclipse EMF platform hosts a very good plugin named "Acceleo". The aim is to orchestrate the generation of formated text file (code, documentation, sql statements and so on..) from any ecore compatible models. The generation is done using templates written in "MOF2Text" language wich is an OMG language specification.
The initial complexity of the eclipse modeling tools and environnment is a little bit frustrating but, once this gap passed, the workflow is very effective. I started to write some simple acceleo template in order to convert my framework's UML model into PHP classes. As my initial project evolve i encountered a lot of different cases to handle like generating interfaces, class extends, interface implementation, template typed classes, multiplicity and so on, making the generator more and more generic and become usable for differents kinds of projects.
So, despite some issues about the build, the lack of documentation and the need of some minor improvements to be used in production i decided to share it on github.