導入

導入 – 使用目的と簡単な使用例

説明

PHP_UML は、 リバースエンジニアリングやドキュメント作成のためのツールです。

PHP のファイルやディレクトリをパースし、 パースしたコードに対応する XMI ファイルを生成します。

XMI は OMG の標準規格で、 XML を用いてメタデータ情報を交換します。 一般的に、UML のモデルをやりとりするためのフォーマットとして用いられています。 UML を扱うソフトウェアの多くが、XML ファイルのインポートやエクスポートに対応しています。

機能

PhpDocumentor と同様、 PHP_UML は PHP のクラスやインターフェイス、 プロパティそして関数をパースすることができます。 また、ドキュメントブロックのインラインコメントから @package@var@param といった情報を取得します。

  • @param および @var からは、パラメータやプロパティの型についての情報を取得します。 @package からは、パッケージの階層構造を取得します。

PHP コードのドキュメントをきちんと書けば書くほど、 より正確な XMI ファイルができあがるというわけです。

現時点では、UML/XMI の標準規格には 1.4 および 2.1 のふたつのバージョンがあります。 PHP_UML は、どちらのバージョンの XMI でも生成することができます。 しかし、使用する UML ツールによっては生成した XMI ファイルをうまく扱えない可能性があることに注意しましょう。 たとえば、UML artifact (ソースファイル) とそこで定義されている論理要素のリンクは UML バージョン 2 でしか扱えません。

単一のファイル test.php のパースと XMI ファイルの生成

<?php
require_once 'PHP/UML.php';

$uml = new PHP_UML();   
$uml->parseFile('test.php'); 
$uml->generateXMI(1);             // UML のバージョン番号 (1 あるいは 2)
$uml->saveXMI('test.xmi');
?>

UML はオブジェクト指向の標準規格なので、 PHP_UML はグローバル関数やグローバル定数といった "手続き型" の要素は一切無視することに注意しましょう。

PHP_UML (Previous) How to run PHP_UML from the command line? (Next)
Last updated: Wed, 16 Apr 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

Note by: fjas@free.fr
Thanks for your message.
I know you sent it a while ago, but I'm just reading it, sorry.

It is true that some of the things I wrote about XMI and UML are ambiguous, and I have cleared a little bit the documentation about PHP_UML accordingly (it should be published soon).
Thanks for your remarks.

I quite agree with you that PHP lacks type hinting for class properties (as well as for function returns). Since it is already possible to specify a type for the function parameters in PHP, it would be very coherent to allow it for the class properties and constants too.

BTW, you have suggested to make PHP_UML aware of annotations, in order to compensate this lack, but it's already a feature of PHP_UML (PHP_UML can read the properties types through the @var annotation)

Baptiste Autin
Note by: darren@webel.com.au
Thanks for your work on this, I am very interested in this project. I formerly worked for a major UML tool vendor, and use PHP and Drupal CMS for some web work, however the lack of graphical engineering and UML support in PHP is a big issue for me, especially because I am very used to UML-driven Java and XML Schema engineering.

Firstly however some clarifications. You wrote:

"Your UML/XMI code might be interpreted differently by the modeling tool you are going to use along with PHP_UML. This is particularly true for the version 2 of UML/XMI. For instance, the Eclipse plug-ins (EMF, Papyrus) only accept a particular flavour of XMI, called ecore, which is only partly compatible with the one you will get with PHP_UML."

You seem to be equating XMI with UML (and eCore in EMF with XMI), which is getting the cart before the horse. XMI is able to represent various metam metamodels, as described well here:

http://xml.sys-con.com/node/40066
XMI: The OMG's XML MetaData Interchange Standard

"The MOF standard selects a subset of UML that's appropriate for modeling metadata. This subset is called the MOF Core."

"the technology-neutral nature of the MOF Core made it relatively easy to produce a mapping from the MOF Core's elements to XML so that, given a metamodel, a Document Type Definition (DTD) could be generated. This DTD can be used to stream models that conform to the metamodel.
..
The generated DTD defines XML elements for each element of the metamodel."

"Several specific XMI DTDs have been standardized by the OMG. Each was produced by feeding an MOF-compliant metamodel into an XMI DTD generator. .. The UML DTD is the most widely used XMI DTD."

To call Ecore XMI files "a particular flavour of XMI" is not quite right. Please visit:

http://wiki.eclipse.org/index.php/EMF/FAQ#What_is_the_relationship_of_OMGTM_MOFTM_to_the_EMF_Ecore_model.3F

Also, concerning Papyrus (from http://wiki.eclipse.org/MDT/Papyrus):

" this project will provide the glue around valuable UML and SysML diagram editors (GMF-based or not) and other MDE tools. It will also offer support for UML and SysML profiling mechanisms."

Ok, so to the PHP_UML tool. I gave it a spin on a very simple PHP web application (for bulk migration and admin of subscription data for the Drupal Simplenews module), and then imported it into MagicDraw UML. The results is available here:

http://www.webel.com.au/php/uml

Because PHP does not support typed Properties it is very difficult to manage the Relationships between Classes (even with your handy 'mixed' DataType). The process shown requires so much manual intervention (I've used Dependencies and Usages to indicate where Associations could be) that the benefits of obtaining the UML representation are greatly undermined.

I find it unfortunate that (according to these minutes by these minutes by Derick Rethans from a PHP Developer meeting from Nov 2005) it was apparently decided that type-hinting would not be introduced for properties in future version of PHP:

"5.8 Type-hinted properties and return values
Issue: PHP only supports type hinted arguments and not for return values or properties.

Discussion:

We quickly agreed that we don't need type-hinted properties, as it would cause problems when they are assigned to other variables and it's just generally not-PHP style."

"We do not allow type-hinted properties as it's not the PHP way."

http://www.php.net/~derick/meeting-notes.html#type-hinted-properties-and-return-values

The lack of associative graphical engineering for PHP is enough to force me to stick with Java for most of my work (while I do use PHP for some web work).

One solution might be to use annotations to indicate type, which your PHP_UML tool could then interpret in strongly typed UML Properties.

Dr Darren Kelly (Webel IT)