Generation of Class Diagram from XMI - php

Situation
I have a PHP project with lots of classes with lots of relationships in lots of folders following the Zend Naming Convention.
I use the NetBeans IDE 7.1.
I work under Windows 7.
Goal
I need to see a graphical representation of the class relationships, possibly in varying depths and varying degrees of complexity. Also, it would be nice if the classes in the diagram are clickable. I do not necessarily need to generate documentation.
Attempts
1. Within NetBeans
NetBeans is an awesome IDE with lots of features. In fact, it recognizes class dependencies, and it would be wise to assume that it has some sort of way to graphically view this relationship, natively, or through a plugin. Such a plugin exists, but is for version 5.5. I have 7.1, and it's not compatible. Fail.
2. Enterprise Architect
A simple google search brings up Enterprise Architect as an all-capable, completely comprehensive tool for solving such problems. So, I download and install. I'm not going to go to the detail of how I couldn't understand how to do anything, and how the tutorials are bragging about what the software can do, but rarely say how.
So, I imported the source. It generated many different classes and parsed all the members. Also, it generated the class diagrams. "Perfect!", I though, but alas. The class diagrams only show relationships between classes, the files of which were in the same source folder, despite the relationships being visibly registered in the classes' properties. A search for documentation on how I could merge all these diagrams into one was unsuccessful. Fail.
NOTE: I created a parallel thread before this one here.
3. PHP_UML
Found this PEAR tool. Looked good. So, I read through documentation on how to install it for my setup from various sources, and ran it. First, I used the html output format. Great! Lots of documentation with an index, bla bla bla. However, the best it could do in the direction I want was this:
Needless to say, I guess, that this is a very poor, super simplified version of what I actually need. Conclusion: fail.
4. Enterprise Architect + PHP_UML
However, PHP_UML can also generate XMI. Wow. Very nice. I can store my relationships and view them in different ways and exchange with other people.
So, I imported it into Enterprise Architect. Result: same as before with Enterprise Architect alone, only no class diagrams. Just the classes. As far as I've read about it, I can now manually create the relationships. Epic fail.
5. ArgoUML + PHP_UML
Somewhere through my search for solution I stumbled upon someone's comment that said they use ArgoUML. Downloaded and installed. XMI imported with some hassle (had to change version explicitly to 1). Fail (see Attempt 3).
Conclusion
Such a seemingly trivial task, and yet, so difficult. Do I have to go through this whole list, trying out each application?

One of the ways to do this would be to take the approach illustrated in my attempt 2 or 4,
and then follow instructions given here for Enterprise Architect.
To generate an XMI file using PHP_UML:
Follow these instructions to install PEAR if not installed already, if you have PHP installed separately.
If you are using XAMPP under Windows (my case), follow these instructions to add PEAR to the PATH env variable and thus make PEAR available through CMD, and to learn how to install packages in both *nix and Windows systems. Hint: the PATH separator is ";" (semicolon) for Windows.
In some setups, like if using XAMPP, you may need to activate the XSL extension. In this case, open your php.ini file (you may need Administrator privileges to save it), and uncomment or add the following line to the bottom of the "Dynamic Extensions" section: extension=php_xsl.dll.
Install the PHP_UML package with pear install PHP_UML.
Execute phpuml -f xmi -o name_of_output_dir. If you're planning to use the generated XMI with some older programs later, you may need to specify XMI version 1 by adding -x 1.
For me, this did not work immediately, saying that I am missing ../../data/xmlschema.rng. Not sure why this happened, but if you get a similar error, you can download it from here and place it into the data folder right under your PEAR directory.
This XMI can later be used with Enterprise Architect, ArgoUML and other XMI tools.

(Edit : This answer is an alternative for people that want to generate UML class diagram from a PHP project, it doesn't explains how to read XMI files)
Goal
I need to see a graphical representation of the class relationships,
possibly in varying depths and varying degrees of complexity. Also, it
would be nice if the classes in the diagram are clickable. I do not
necessarily need to generate documentation.
If your goal was to generate a class diagram from a PHP project, I found a better solution than use PHP_UML. What you probably want is BoUML, with this software, you can select a PHP project folder and reverse engineering it. Then create a class diagram. When you drag&drop the class on it, the relations are there unlike AlgoUML (If I'm not wrong). XMI files are no longer useful in this case.

Related

How to prevent PHP namespace conflicts (pre-bundled packages)

Let's assume we have a PHP project with dependencies A and B each depending on PHP library X, but in a different version.
Usually, one would use a PHP dependency manager such as composer which would either resolve this conflict by including X in a version compatible to both A and B or display an error if the conflict cannot be resolved.
Now, many PHP applications allow their users to install plugins simply by uploading pre-bundled packages and extracting them to a specific plugin directory.
If A and B were such pre-bundled plugins and both would bring their own version of library X, we might run into problems since no dependency manager is available to select a compatible X for us or display an error in case there is none.
To prevent any such conflicts caused by the inability of PHP to have library X being loaded twice with different version into the same namespace, we could put A's X and B's X into different namespaces (which might be hard to do automatically as we would need a PHP parser for that...).
My question is:
How would you solve this problem? Can you recommend this approach or is there a better solution?
There is no solution without changing the code. If two versions of ´\Vendor\AnyClass´ do exist in the filesystem, and code is executed to use them both, either an error appears because redeclaring that class is not allowed, or because the expected class is incompatible. It will only work if the interface of the class is implemented the same, i.e. the two codes are compatible. The problem of compatibility is complicated if it isn't only that one class, but an entire tree of objects that may react badly to mixing classes from different versions, even though they offer a compatible interface.
Changing the namespace is changing the code. Who's responsible for that? I can think of some automatic code parser that would be able to add a specific namespace prefix for each plugin, but that task hasn't been done to my knowledge in PHP. The Java guys in my company made some remarks that such a problem has been solved there, but I have no details.
Also, it doubles your code base, and the duplicated code has to share only the one opcode cache you have.
I know that the core developers of Wordpress are still struggling with this problem. There are some coded suggestions of how to use Composer for dependency management (i.e. plugins and their dependencies), but I don't think they made enough progress for now.
Essentially you have two choices: 1. Create a code namespace prefixer, parse all the files belonging to a plugin (so the plugin author has to include his dependencies somehow), change the code, live with the code duplication, and see what awaits you when it comes to debugging. The downside is that no code outside of that plugin will be easily able to use the plugin code directly because that would mean to know the created prefix. 2. Implement some form of dependency management, preferably using Composer, and don't change the namespaces.
Update: I consulted my Java co-workers again, and they basically made the same statement about Java that I made about PHP: You cannot have two different versions of a class under the same class name, and there is no "magic" even for Java but renaming the class to a different namespace.

Best Way to Install Zend Framework 2

I'm new to the Zend Framework but have used PHP in the past. I've gone through the basic tutorial provided by Zend, and understand a lot of it, but I'm fuzzy on the installation process. There seems to be many different ways to install, is that right? Here are the ways I've seen:
Download .zip file and manually extract
Use command line with composer.phar
Use command line with zftool
If someone could give a brief explanation of each of those above methods, how they differ, and which one is better, that would be great!
Also, two more quick questions on topic:
The tutorial mentions including Zend in your PHP include path. Why would you need to do this if the framework is included in the projects directory?
Is there a way to install the framework without the skeleton app?
Thanks in advance!
I'll only go about the 2nd set of questions:
You don't. You either have it inside your include path or inside your projects.
php composer.phare require zendframework/zendframework 2.2.*
Your first question is rather opinionated and it heavily depends on your workflow. To quote some song lyrics:
Sei ying there is no special move that is best, it all depends, any move could be best,
its up to you when the times right, to move correctly, accurately and with great speed...
tl/dr choose the method that seems most practical to your solution.
Try this website: http://www.packtpub.com/article/building-your-first-zend-framework-application
It shows how to install, add a virtual host and skeleton application and add modules to that application.
Happy learning
Use Zip if you dont have access to other methods (composer or git). With Zip you wont be able (easily) to upgrade or downgrade components.
composer is great because you can configure your needs. for example:
"require": {
"zendframework/zend-config": "2.2.*",
"zendframework/zend-http": "2.2.*"
},
More info: http://framework.zend.com/downloads/composer
Use Git if you wish to be on the edge (more hard to maintain versions)

What's difference between using cakephp console and using IDE to build the application?

I am a cakephp newbie and I would like to know what method you guys use to build your cakephp project. The tutorial I read is using cakephp console to bake application but the book I have use IDE to build the application. It seems console is more convenience because it can generate different projects name...Using IDE would require the developer to manually create all the folders...Thanks for the reply...
What I think you're not hearing enough of, in the answers so far, is that they're really two different tools with two different purposes. Cake's bake command line utility won't really create your application. It will create scaffolding for the parts of an application that you define. This is a great starting point, but that's all it is.
You'll use your IDE to flesh out the bits that make your application, well, an application.
Both tools are very, very useful so it's not really an either/or kind of answer. Although I like using the bake tool to get started, there really aren't that many folders you have to create if you chose the IDE path. Once you drop in the Cake code base, most of that stuff--even the app-centric bits--are waiting for you to fill them out.
I rarely use bake to create views and once I've baked a model or two, I'll often built others from scratch in my text editor. There's no "right" way; just understand what each gives you and use whichever best suits your workflow at a given point in time.
I use both methods, depending on the state of development of the project and/or database.
Often I will copy a controller, model and views and just search & replace the appropriate names.
If I have a lot of database defined, I'll use bake.
As for IDEs, after much pain, frustration and testing I have settled on NetBeans. I did use Komodo for a while when I was forced to work on Windows (Java ate my windows) but now I'm on Ubuntu & Macs Netbeans is powerful, quick and flexible. I still wouldn't touch Eclipse with someone else's, though.
You might be looking for something like ModelBaker. I haven't personally used it, but from what I can see it's a slick GUI on top of CakePHP.
FWIW, I've been using JetBrain's PHPStorm and loving it.

Hudson and PHP project release management

I'd like to ask about real life experiences with release management of PHP projects over Hudson CI server.
Our projects are separated into subprojects: frontends, framework, libraries. Everything is stored in our SVN as project of its own. Different frontends may depend on different versions of framework which itself depends on different versions of libraries.
So far we do release management by hand. We have one environment serving as test and production to avoid environment differences problems releasing the project. We tag each subproject in SVN with release number and checkout everything for testing accessible under test domain. Once we do testing and fix the bugs we tag new versions of everything in SVN as production and relink production domain to point to the new code. This manual process has its obvious problems and there is no way we are keeping it.
Under my research to move to automated solution I already installed Hudson and configured it for PHP projects (Phing, ppUnit, etc...) I am familiar with writing build scripts under Phing or Ant. I red all possible "the basics" stuff of setting up CI environment and preparing project and done that. What I did not find is an example of release management similar to what we do manually taking into account all the dependencies we have. Can you please point me out into a right direction?
I'm afraid there is no such complex thing readily available. We had to solve quite similar problem and we ended up using very similar configuration you were planning to use (or already using).
We have multiple application cores and then specific client modifications on top of that. All is stored in SVN. Additionally we use svn:externals to link Framework and other 3rd party libraries with the application.
All is done using Phing and although it took us some time, Phing helped a lot and I can really recommend it.
Client specific addons are fetched automatically using phing. Everything is configurable through build properties.
For database schema updates we are very happy with dbdeploy which is a part of Phing. Although we had to modify it slightly for our needs.
Additionally we added a support for creating pre-configured self-extracting Linux installer so the whole complicated process of creating a deployable package consists of calling one phing target and passing a correct build property file. To create those installers we use this simple technique (http://www.linuxjournal.com/node/1005818).
Again using Phing the created package is automatically uploaded to a target server, executed over SSH to do the deploy.
Then we use Hudson for automatically creating installer packages (in addition to automatically running phpunit tests and Selenium/Hmres tests) and storing them in a defined location/or as artifacts. Our support team can then grab the packages and do the production deployment themselves (our QA/Test environments are updated automatically by Hudson).
Additionally the code is automatically encoded and licensed using ZendGuard where necessary.
The brief description above is just to illustrate what can be achieved using Hudson, Phing, SVN and PHP. Full technical details would obviously be too long for this post but I would be happy to elaborate more somewhere else.

PHP package manager

does anyone know a package manager library for PHP (as e.g. apt or yum for linux distros) apart from PEAR? I'm working on a system which should include a package management system for module management. I managed to get a working solution using PEAR, but using the PEAR client for anything else than managing a PEAR installation is not really the optimal solution as it's not designed for that. I would have to modify/extend it (e.g. to implement actions on installation/upgrade or to move PEAR specific files like lockfiles away from the system root) and especially the CLI client code is quite messy and PHP4. So maybe someone has some suggestions
for an alternative PEAR client library which is easy to use and extend (the server side has some nice implementations like Pirum and pearhub)
for completely different package management systems written in PHP (ideally including dependency tracking and different channels)
for some general ideas how to implement such a PM system (yes, I'm still tinkering with the idea of implementing such a system from scratch)
I know that big systems like Magento and symfony use PEAR for their PM. Magento uses a hacked version of the original PEAR client (which I'd like to avoid), symfony's implementation seems quite integrated with the framework, but would be a good starting point to at least write the client from scratch. Anyway, if anybody has suggestions: please :)
There is Composer also.
Have you checked Maven for PHP? I've only used Maven in the context of Java applications, but it's certainly:
Easy to extend – it's really easy to implement Maven plugins
Manages dependencies – distinguishing compile, test and runtime dependencies (though the compile/runtime distintion doesn't make sense in PHP).
Repositories are trivial to put up – Apache with mod_dav will give you a working writable repository, but you also have Nexus.
Distinguishes snapshot from stable artifacts; allows several policies for when to check for new snapshot artifacts and from which repositories get each type.
And many – many – more things.
PEAR2/Pyrus was built for package management for arbitrary applications. I believe it was modeled after the apt/yum architectures.
Helgi - core PEAR member - covers some of it here - http://www.slideshare.net/helgith/pear2-pyrus-the-look-ahead but the documentation is pretty solid too: http://pear.php.net/manual/en/pyrus.extending.installation.php

Categories