PHP to UML class Diagrams - php

Just wanted to know if there is any way i can create class Diagram from PHP code. I have PHP code
accepting POST data from Android(HTTP ) and storing that Data in a MySql database.how do i represent it, i created a class diagram of my android code using ObjectAid plugin for Eclipse. but cannot figure out how to represent PHPMYSql in a class diagram. Tried Enterprise Architect , Didn't work for me.
Thanks..

I'm looking for this as well. In my search I did find phuml.
https://github.com/jakobwesthoff/phuml
It is currently not being developed on and I am unsure on how good the results are (the test I've run is on a codebase that is quite large and that I do not know myself).
However, it is quite easy to work with.
Requires graphviz installed.
apt-get graphviz if you're on linux.
The bad part of it is that you get the UML as img, or pdf. If you generate a PDF it is searchable, but I still haven't figured out a way to make it editable as UML in any uml diagram application.
Supported file formats to export to: http://www.graphviz.org/doc/info/output.html

The set of tools (and their capabilities) that can do this automagically for you is limited. UML models are usually created manually, before a code is written.
From the UML perspective there is no difference between PHP Object-Oriented code and Android Object-Oriented code and MySQL tables are just classes without operations.
Although you may be lucky in partially automating the model creation through reverse-engineering, to make it readable and emphasize parts that are important through diagrams with different level of detail, you'll have to involve a manual work.
For an overview of what can UML do for you, walk through Kirill Fakhroutdinov's online book uml-diagrams.org: UML Diagrams Examples

Related

Recommended Software Design Pattern to define CSV/XML or any other format generator?

Hi I'm writing a CSV/XML package for my own project, I'm not using packages around there because I need to render for some cases CSVs with more than 100.000.000 of rows. So I figured my basic solution doesn't work when the database queries take long time, then I wrote a script to download the file batching it. It's working I just want extend and re-factor it for XML. Would be great do it with a good design pattern.
Several libraries working on this kind of subject in PHP are implementing a design pattern adapter because standard PHP libraries (that you should use if you want performances) associated to each kind of file provide a completely different interface.
So, in fact, you just have to find your own interface (you can do that with many interfaces if you can identify different functional aspects).
Example of standard library for CSV in PHP: http://php.net/manual/fr/function.fgetcsv.php
Example of abstraction tool on type of file: https://github.com/KnpLabs/Gaufrette
This question is primarily opinion-based - I will tell how I have solved this problem.
I have recently met the same problem in one of my projects and I decided to solve this problem with writing reading and writing interfaces.
As result, I had a code like:
public interface IReportReader
{
Report ReadFromFile(string filePath);
Report ReadFromStream(Stream stream);
}
public interface IReportWriter
{
void WriteToFile(string filePath, Report report);
void WriteToStream(Stream stream, Report report);
}
Then, I have implemented two implementations:
StubConsoleReportReader \ StubConsoleReportWriter - just for debug purposes.
CSVReportReader \ CSVReportWriter.
Later, I have easily added XML, HTML and word output formats.
As for me, this pattern suits great because:
1. It is plain and simple, without over-engineering, can be easily extended;
2. These two interfaces describe two fundamental operations - input and output, which are fitting any existing file types and formats.

generating UML class diagrams for drupal

Hi I am using Drupal 6 for my final year project, I am required to create class diagrams for my website, so can you point to useful tools for this task.
Thank you
Drupal is not Object Oriented, it won't easily documented with classes diagrams. So I don't expect any tools to be available to generate them. You can hoewever use any UML tools to create high level functional documentation.
I was specifically studying the drupal way to write plugin. I wrote a blog on this accompanied by component diagrams. At first I prepared a component diagram for the menu subsystem as in the following,
Also there is a component diagram for the blog module,
Finally, I did not come up with any class diagram. But the component diagrams help to understand the internal working pretty well.
Update
In new(8x) edition of drupal there are talks for class diagrams here.
Drupal uses the doxygen standard for documenting code. You can generate the entire API of Drupal Core and all modules and themes you've installed in you Drupal application using doxygen. With regards to class diagrams, you will be able to generate class diagrams such as the one shown below. The example below uses graphviz library but you don't need it to generate those images.
You could just try to use a reverse engineering tool to get a class diagram of the database tables that drupal uses. Should be good enough.

PHP & MySQL code generation from UML

Is there an Eclipse plug-in that will allow me to graphically generate a data model, and produce from it a MySQL Database Script for generation of that database, and generate PHP code for simple add/change/delete methods?
This way I can focus on programming the business logic, instead of fussing with the details of the SQL code.
You should use what is called a framework or ORM. Kohana is a good one, as is codeIgniter, and Doctrine. You can specify your data models in one location and have the DB and code generated. I'm not sure about generating it from a UML model tho.
You can use this UMLtoPHP online generation service that can take as input a UML Eclipse class diagram and generate the corresponding doctrine file for you. With that you can easily generate a full CRUD php application using, for instance, symfony

PHP UML Generator [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
How do I generate UML diagram based on existing classes in PHP?
There's also the PHP UML tool available from pear.
PHP_UML:
Can generate UML/XMI files in version 1.4, or in version 2.1 (logical, component, and deployment views)
Can generate an API documentation in HTML format
Can generate PHP code (code skeleton) from a given XMI file
Can convert UML/XMI content from version 1.4 to version 2.1
Install it on the command line via:
$ pear install pear/php_uml
(This used to be $ pear install pear/php_uml-alpha but the package has since gone stable.)
Generate your xmi:
$ phpuml -o project.xmi
I strongly recommend BOUML which:
is extremely fast (fastest UML tool ever created, check out benchmarks),
has rock solid PHP import and export support (also supports C++, Java, Python)
is multiplatform (Linux, Windows, other OSes),
is full featured, impressively intensively developed (look at development history, it's hard to believe that such fast progress is possible).
supports plugins, has modular architecture (this allows user contributions, looks like BOUML community is forming up)
phUML
phUML is fully automatic UML class diagramm generator written in PHP, licensed under the BSD license. It is capable of parsing any PHP5 object oriented source code and create an appropriate image representation of the oo structure based on the UML specification.
./phuml -r /var/www/my_project -graphviz -createAssociations false -neato out.png
Step by step guide
the best (Windows) software i have found to do PHP and UML is Sparx Systems Enterprise Architect. besides a pletora of features, it supports the following for PHP:
Reverse engineer object oriented PHP into UML class diagrams
Generate PHP class definitions from UML class diagrams
Synchronize changes made in a UML class into the corresponding PHP class definition
Synchronize changes made in a PHP class definition into the corresponding UML class
Create UML sequence diagrams to show what PHP classes use and how they are used
Produce detailed documentation of your PHP code in standard RTF and HTML format
Perform code engineering on models to generate base PHP pages.
not free ($199), but definitely worth the money.
Have you tried Autodia yet? Last time I tried it it wasn't perfect, but it was good enough.
There's also php2xmi. You have to do a bit of manual work, but it generates all the classes, so all you have to do is to drag them into a classdiagram in Umbrello.
Otherwise, generating a diagram with the use of reflection and graphviz, is fairly simple. I have a snippet over here, that you can use as a starting point.
Here's how I did it (directly from code to PDF drawing without manual drawing of anything):
Use BOUML for "reverse engineering PHP code" [sic] to extract the class model (BOUML is available from "universe" repository of Ubuntu). I seriously recommend BOUML for this step because it's really fast compared to many other programs I have tried. In addition, it seems that BOUML seems to extract the model correctly (for the parts that BOUML even tries to extract).
Use BOUML to export model as XMI 1.4 file
Use ArgoUML to import said XMI file (you can use webstart version for this step)
Export XMI from ArgoUML (I don't know which XMI version/variant the output is but it is not the same result as the output from BOUML. The argouml-graphviz cannot handle XMI file directly from BOUML).
Use argouml-graphviz to convert ArgoUML exported XMI file to dot format (you may need to use saxon instead of xsltproc to get it work due to use of XSLT2)
Use dot or fdp or sfdp to render the class diagram.
Here's an example of suitable command line for using fdp to output PDF diagram (assuming that dot file generated by argouml-graphviz XLST processing is saved as xmi-model.dot):
fdp -Tpdf -Gmaxiter=1000 -Gmindist=0.5 -Gpackmode=node \
-Eweight=0.05 -Elen=1.0 -Eminlen=1.0 -Gsplines=true \
-Goverlap=false xmi-model.dot -oxmi-model.pdf
As an alternative you could try PHP_UML or php2xmi instead of BOUML for doing the "reverse engineering" part. I haven't yet tried that.
(I'm using the phrase "reverse engineering" because it seems that UML people are using those words when they mean extracting class and method information from the source code. I would personally interpret those words as extracting information from executable binary file or captured raw wire data.)
If you prefer drawing the class diagram by hand (instead of using computer to do all the drawing), you can use either BOUML or ArgoUML for the drawing. Using the "reverse engineered" data via BOUML will help in that case.
If you are looking to generate UML easily from your existing PHP Classes you might want to consider PHPStorm 3.0 IDE. It does a good job of replicating existing code into UML.
Have a look at the PHP Storm feature list.
In theory you can use PhpStorm to visualise your classes using UML. The generation is not really great but you can effectively refactor stuff and again, at least preview parents, implementations, constants, attributes, methods and their visibility in a nice way.
Situation
I want to visualise a communication between already existing components to a colleague.
Process using PHPStorm
https://blog.jetbrains.com/phpstorm/2017/09/uml-diagrams-in-phpstorm-2017-2/
Advantages
Nice UI, final diagram.
Able to refactor code from a diagram.
Able to add notes.
The class diagram symbolises private/public properties, constructors, methods nicely.
Disadvantages
No support for PHP 7.
Painfully to use. Can't resize the generated boxes.
When adding a new relation, the previous ones get randomly lost :O wtf?
Restarting PhpStorm destroys the diagrams
Changed my mind, impossible to use relations
Result
Anyway, after some painful hour of work I was only able to generate unrelated boxes and had to use additional program to link relations. Really bad. But I believe once they make it work properly it will be a great feature because as the code changes, the diagrams would be automatically updated!
For now, don't use PhpStorm for UML diagrams.
You can use Visual Paradigm for UML. This might not be the best paid (it's US$699) product, just as an option if anyone would like to try. It can create class diagram from PHP and vice versa, and not only PHP, there's a bunch of language you can choose such as C#, C++, Ruby, Java, VB.NET, Python, Objective C, Perl, etc. There's also a trial you can check on.
Well to be honest, first and foremost you shouldn't generate UML model from code, but code from UML model ;).
Even if you are in a rare situation, when you need to do this reverse engineering, it is generally suggested that you do it by hand or at least tidy-up the diagrams, as auto-generated UML has really poor visual (=information) value most of the time.
If you just need to generate the diagrams, it's probably a good thing to ask yourself why exactly? Who is the intended audience and what is the goal? What does the auto-generated diagram have to offer, what code doesn't?
Basicly I accept only one answer to that question. It just got too big and incomprehensible.
Which again is a reason to start with UML in the first place, as opposed to start coding ;) It's called analysis and it's on decline, because every second guy in business thinks it's a bit too expensive and not really necessary.

Using Visio (Dia) to Map Out Algorithms

I was just wondering how many experienced programers out there actually map out their process or algorithms in a program like MS Visio or Gnome Dia?
I am trying to code some complex PHP for my website and just seem to be missing something. Is a diagram program going to help or should I be looking in another area?
I use Visio only for quick graph that doesn't need to follow UML rules. Sometime useful for documentation that aren't about the detail of the code : if you need to show some high abstract view of your code, Visio do the job, Example, documentation that display how each big part communicate, or a simple activity diagram...
You can find a SO list of free UML editor if you require to do intensive UML design.
Everytime I've tried to make a truly usage diagram in Visio, it always ends up being more work than it's worth. Never underestimate the power of pencil & paper, or better yet, a white board.
But yes, explaining or writing out your problems will more quickly lead to a solution than merely sitting there and thinking about it.
OmniGraffle. Class diagrams. Sequence diagrams. Interaction diagrams. 'Nuff said.
When I want to make a sketch with 3 boxes and a handful of arrows I use graphviz.
I hate graphical stuff where you have to realign everything each time you change a name.
It's (nearly) as simple as writing :
Input -> Frobnicator -> Output
in a text file then run "dot -Tpng -O myfile"
give it a try ...
but be warned that graphical representation just work for very high level views (i.e. with few objects)
I use magicdraw to chart out my use cases (so my team and I understand the features needed exactly) and then I do activity charts and class diagrams for the more complex features. You can also do database architecture in there and have it generate the sql for your (a god send if you're database is huge). Magicdraw isn't free however but if you anticipate doing a fair amount of complex projects it might be worth the investment. Outside of going the diagramming route you can look into using a PHP framework that might take care of some stuff for e.g. Zend Framework, or Code Ignitor

Categories