Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,336 @@
<?php
/**
* PHP_UML (PHP_UML_Output_Xmi_AbstractBuilder)
*
* PHP version 5
*
* @category PHP
* @package PHP_UML
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version SVN: $Revision: 166 $
* @link http://pear.php.net/package/PHP_UML
* @since $Date: 2011-09-07 23:20:01 +0200 (mer., 07 sept. 2011) $
*/
/**
* Abstract class to generate UML elements in XMI code.
*
* To deal with the two different versions of XMI (1.4 and 2.1), you must use one of
* the two specialized versions:
* PHP_UML_Output_Xmi_BuilderImpl1, or PHP_UML_Output_Xmi_BuilderImpl2
*
* @category PHP
* @package PHP_UML
* @subpackage Output
* @subpackage Xmi
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
*/
abstract class PHP_UML_Output_Xmi_AbstractBuilder implements PHP_UML_Output_Xmi_Builder
{
const EXPORTER_NAME = 'PEAR\PHP_UML';
const PHP_FILE = 'PHP File';
static protected $allStereotypes = array('File', self::PHP_FILE);
static protected $allExtensions = array(''=>'File', 'php'=>self::PHP_FILE);
protected $xmiVersion = 2;
protected $encoding = 'iso-8859-1';
protected $logicalView = true;
protected $deploymentView = false;
protected $componentView = false;
protected $stereotypes = false;
/**
* Sets the XML encoding
*
* @param string $encoding Encoding
*/
public function setEncoding($encoding)
{
$this->encoding = $encoding;
}
/**
* Enables the inclusion of a logical view in the serialized model
*
* @param boolean $value True/False
*/
public function setLogicalView($value)
{
$this->logicalView = $value;
}
/**
* Enables the inclusion of a deployment view in the serialized model
*
* @param boolean $value True/False
*/
public function setDeploymentView($value)
{
$this->deploymentView = $value;
}
/**
* Enables the inclusion of a component view in the serialized model
*
* @param boolean $value True/False
*/
public function setComponentView($value)
{
$this->componentView = $value;
}
/**
* Enables the inclusion of the stereotypes in the serialized model
*
* @param boolean $value True/False
*/
public function setStereotypes($value)
{
$this->stereotypes = $value;
}
/**
* Generates an ID for an element. A partial identifier can be provided
* (used for classes and their idrefs)
*
* @param string $prefix Prefix
*
* @return string ID
*/
static protected function getUID($prefix = null)
{
if (is_null($prefix))
return PHP_UML_SimpleUID::getUID();
else
return md5(self::EXPORTER_NAME.'#'.$prefix);
}
/**
* Gets an XML header for the XMI file
*
* @return string
*/
protected function getXmlHeader()
{
return '<?xml version="1.0" encoding="'.$this->encoding.'"?>';
}
/**
* Factory method. Retrieves a proper implementation class,
* matching the XMI version.
*
* @param float $version XMI version
*
* @return PHP_UML_Output_Xmi_Builder An XMI builder object
*/
static function getInstance($version)
{
if ($version < 2)
return new PHP_UML_Output_Xmi_BuilderImpl1();
else
return new PHP_UML_Output_Xmi_BuilderImpl2();
}
/**
* Get all packages, recursively, with all the objects they contain
* Initially called by generateXmi() on the root package
*
* @param PHP_UML_Metamodel_Package $package Base package
*
* @return string XMI code
*/
protected function getAllPackages(PHP_UML_Metamodel_Package $package)
{
$str = $this->getPackageOpen($package);
$str .= $this->getNamespaceOpen();
$str .= $this->getOwnedElements($package);
foreach ($package->nestedPackage as $pkg)
$str .= $this->getAllPackages($pkg, false);
$str .= $this->getNamespaceClose();
$str .= $this->getPackageClose();
return $str;
}
/**
* Get the different types owned by a package
*
* @param PHP_UML_Metamodel_Package $package Package to get the types of
*
* @return string XMI code
*/
protected function getOwnedElements(PHP_UML_Metamodel_Package $package)
{
$str = '';
foreach ($package->ownedType as &$elt) {
switch(get_class($elt)) {
case 'PHP_UML_Metamodel_Interface':
$str .= $this->getInterface($elt);
break;
case 'PHP_UML_Metamodel_Datatype':
$str .= $this->getDatatype($elt);
break;
case 'PHP_UML_Metamodel_Artifact':
$str .= $this->getArtifact($elt, $elt->manifested);
break;
default:
$str .= $this->getClass($elt);
}
}
// we will finally not use this since it leads to unvalid XMI:
/*foreach ($package->ownedOperation as &$elt) {
$str .= $this->getOperation($elt);
}
foreach ($package->ownedAttribute as &$elt) {
$str .= $this->getProperty($elt);
}*/
return $str;
}
/**
* Get all components, with its provided classes
* PHP_UML considers each logical package as a component, and each owned class
* as a provided class.
*
* @param PHP_UML_Metamodel_Package $package Package to map to a component
*
* @return string XMI code
*/
protected function getAllComponents(PHP_UML_Metamodel_Package $package)
{
$str = '';
$cv = new PHP_UML_Metamodel_Package;
$cv->id = self::getUID();
$cv->name = $package->name;
$classes = array();
foreach ($package->ownedType as &$elt) {
$classes[] = $elt;
}
$str .= $this->getComponentOpen($cv, $classes, array());
foreach ($package->nestedPackage as $pkg)
$str .= $this->getAllComponents($pkg);
$str .= $this->getComponentClose();
return $str;
}
/**
* Return the full serialized XMI metamodel of a given Superstructure.
*
* @param PHP_UML_Metamodel_Superstructure $structure Full metamodel
*
* @return PHP_UML_Output_XmiDocument The serialized metamodel, as an XmiDocument
*
*/
public function getXmiDocument(PHP_UML_Metamodel_Superstructure $structure)
{
if (empty($structure) || empty($structure->packages)) {
throw new PHP_UML_Exception('No model given');
}
$xmi = $this->getXmlHeader();
$xmi .= $this->getXmiHeaderOpen();
$_root = $structure->packages;
$xmi .= $this->getModelOpen($_root);
$xmi .= $this->getNamespaceOpen();
if ($this->logicalView) {
$xmi .= $this->addLogicalView($_root);
}
if ($this->componentView) {
$xmi .= $this->addComponentView($_root);
}
if ($this->deploymentView) {
$xmi .= $this->addDeploymentView($structure->deploymentPackages);
}
$xmi .= $this->getNamespaceClose();
$xmi .= $this->getModelClose();
if ($this->stereotypes) { // = XML metadata only for the moment
$xmi .= $this->addStereotypeInstances($structure);
}
$xmi .= $this->getXmiHeaderClose();
if (strcasecmp($this->encoding, 'utf-8')==0) {
$xmi = utf8_encode($xmi);
}
$xmiDocument = new PHP_UML_Output_XmiDocument($xmi);
return $xmiDocument;
}
/**
* Return the logical view of the model
*
* @param PHP_UML_Metamodel_Package $package Package
*/
private function addLogicalView(PHP_UML_Metamodel_Package $package)
{
$xmi = $this->getStereotypes();
$xmi .= $this->getOwnedElements($package);
foreach ($package->nestedPackage as $pkg)
$xmi .= $this->getAllPackages($pkg, false);
return $xmi;
}
/**
* Return a component view of the logical system
*
* @param PHP_UML_Metamodel_Package $package Root package to browse into
*/
private function addComponentView(PHP_UML_Metamodel_Package $package)
{
return $this->getAllComponents($package);
}
/**
* Return a deployment view of the scanned files.
* A file is viewed as an artifact (artifacts exist from UML 1.4)
* Filesystem's folders are treated as packages.
* TODO: use a package-tree, like with logical packages
*
* @param PHP_UML_Metamodel_Package $package The root deployment package
*/
private function addDeploymentView(PHP_UML_Metamodel_Package $package)
{
return $this->getAllPackages($package);
}
/**
* Return the instances of stereotypes
* At the current time, there are only XML metadata, not real UML stereotypes
*
* @param PHP_UML_Metamodel_Superstructure $structure Metamodel
*/
private function addStereotypeInstances(PHP_UML_Metamodel_Superstructure $structure)
{
$xmi = '';
foreach ($structure->stereotypes as $s) {
$xmi .= $this->getStereotypeInstance($s);
}
return $xmi;
}
}
?>

View File

@@ -0,0 +1,251 @@
<?php
/**
* PHP_UML (interface PHP_UML_Output_Xmi_Builder)
*
* PHP version 5
*
* @category PHP
* @package PHP_UML
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version SVN: $Revision: 138 $
* @link http://pear.php.net/package/PHP_UML
* @since $Date: 2009-12-13 04:23:11 +0100 (dim., 13 déc. 2009) $
*/
/**
* Interface for the XMI generation
*
* @category PHP
* @package PHP_UML
* @subpackage Output
* @subpackage Xmi
*/
interface PHP_UML_Output_Xmi_Builder
{
/**
* Retrievesthe XMI header
*
* @return string XMI code
*/
function getXmiHeaderOpen();
/**
* Closing tag for the XMI header
*
* @return string XMI code
*/
function getXmiHeaderClose();
/**
* Retrieves the opening tag for a model
*
* @param string $model Root package
*
* @return string XMI code
*/
function getModelOpen(PHP_UML_Metamodel_Package $model);
/**
* Retrieves the closing tag of a model
*
* @return string XMI code
*/
function getModelClose();
/**
* Retrieves the opening tag for a package
*
* @param PHP_UML_Metamodel_Package $package Package to insert
*
* @return string XMI code
*/
function getPackageOpen(PHP_UML_Metamodel_Package $package);
/**
* Retrieves the closing tag of a package
*
* @return string XMI code
*/
function getPackageClose();
/**
* Retrieves the opening namespace tag (XMI 1 only)
*
* @return string XMI code
*/
function getNamespaceOpen();
/**
* Retrieves the closing namespace tag (XMI 1 only)
*
* @return string XMI code
*/
function getNamespaceClose();
/**
* Retrieves the opening tag for a sub-system (XMI 1), or a component (XMI 2)
*
* @param PHP_UML_Metamodel_Package $package Package to code as a subsystem
*
* @return string XMI code
*/
public function getSubsystemOpen(PHP_UML_Metamodel_Package $package);
/**
* Retrieves the closing tag for a subsystem / component
*
* @return string XMI code
*/
function getSubsystemClose();
/**
* Retrieves the necessary stereotypes
*
* @return string XMI code
*/
function getStereotypes();
/**
* Retrieves the XMI code for a given stereotype
*
* @param PHP_UML_Metamodel_Stereotype $s Stereotype
*/
function getStereotypeInstance(PHP_UML_Metamodel_Stereotype $s);
/**
* Retrieves the XMI declarations of the main PHP types
*
* @param PHP_UML_Datatype $type Datatype
*
* @return string XMI code
*/
function getDatatype(PHP_UML_Metamodel_Datatype $type);
/**
* Retrieves the XMI code for a class
*
* @param PHP_UML_Metamodel_Class $class Class
*
* @return string XMI code
*/
function getClass(PHP_UML_Metamodel_Class $class);
/**
* Retrieves the XMI code for an interface
*
* @param PHP_UML_Metamodel_Interface $interface Class
*
* @return string XMI code
*/
function getInterface(PHP_UML_Metamodel_Interface $interface);
/**
* Retrieves the XMI code for an operation
*
* @param PHP_UML_Metamodel_Operation $operation Operation
*
* @return string XMI code
*/
function getOperation(PHP_UML_Metamodel_Operation $operation);
/**
* Retrieves the XMI code for the paramater of an operation
*
* @param PHP_UML_Metamodel_Parameter $parameter Parameter
*
* @return string XMI code
*/
function getParameter(PHP_UML_Metamodel_Parameter $parameter);
/**
* Retrieves the XMI code for an artifact
*
* @param PHP_UML_Metamodel_Artifact $file File to add as an artifact
* @param array &$mf Manifested elements
* (array of PHP_UML_Metamodel_Class)
*
* @return string XMI code
*/
function getArtifact(PHP_UML_Metamodel_Artifact $file, &$mf = array());
/**
* Retrieves the XMI code for a component
*
* @param PHP_UML_Metamodel_Package $package Package to add as a component
* @param array $provided Set of providing classes
* @param array $required Set of required classes (TODO)
*
* @return string XMI code
*/
function getComponentOpen(PHP_UML_Metamodel_Package $package, array $provided, array $required);
/**
* Retieves the closing tag for a component
*
* @return string XMI code
*/
function getComponentClose();
/**
* Retrieves the XMI code for a classifier (datatype, class, interface)
* Required by getParameter(). Adds the default value (if any)
*
* @param PHP_UML_Metamodel_TypedElement $parameter Element (datatype, class..)
*
* @return string XMI code
*/
function getParameterType(PHP_UML_Metamodel_TypedElement $parameter);
/**
* Retrieves the XMI code for all the realization (= interface implementations)
* of a given element
*
* @param PHP_UML_Metamodel_Class $client Child element
*
* @return string XMI code
*/
function getRealizations(PHP_UML_Metamodel_Class $client);
/**
* Retrieves the XMI code for all the inherited classes of a given element
*
* @param PHP_UML_Metamodel_Type $client Child element
*
* @return mixed In XMI 1.x, this returns an array, because XMI 1 needs two
* declarations: the child element must be defined as "generalizable", in
* addition to the generalization relationship. In XMI 2, only the relationship
* is necessary, which is returned as a string.
*/
function getGeneralizations(PHP_UML_Metamodel_Type $client);
/**
* Adds a description/comment to a model element
* The description is given through a stereotype instance
*
* @param PHP_UML_Metamodel_Stereotype $s A stereotype object
* @param string $annotatedElement The commented element
*
* @return string XMI code
*/
function getComment(PHP_UML_Metamodel_Stereotype $s, $annotatedElement='');
/**
* Retrieves the XMI code for a UML2 profile.
*
* @return string XMI code
*/
function getProfile();
/**
* Retrieves the metadata related to a given tag
*
* @param PHP_UML_Metamodel_Tag $tag Tag
*
* @return string XMI code
*/
public function getMetadata(PHP_UML_Metamodel_Tag $tag);
}
?>

View File

@@ -0,0 +1,417 @@
<?php
/**
* PHP_UML (PHP_UML_Output_Xmi_BuilderImpl1)
*
* PHP version 5
*
* @category PHP
* @package PHP_UML
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version SVN: $Revision: 174 $
* @link http://pear.php.net/package/PHP_UML
* @since $Date: 2011-09-15 03:17:32 +0200 (jeu., 15 sept. 2011) $
*/
/**
* Implementation class to create XMI in version 1
*
* See the interface PHP_UML_Output_Xmi_Builder for the comments
*
* @category PHP
* @package PHP_UML
* @subpackage Output
* @subpackage Xmi
* @see PHP_UML_Output_Xmi_Builder
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
*/
class PHP_UML_Output_Xmi_BuilderImpl1 extends PHP_UML_Output_Xmi_AbstractBuilder
{
const XMI_VERSION = '1.2';
const UML_VERSION = '1.4';
const DEFAULT_CLASSIFIER_ATT = ' visibility="public" isAbstract="false"
isSpecification="false" isRoot="false" isLeaf="false" ';
public function getXmiHeaderOpen()
{
return '<XMI xmi.version="'.self::XMI_VERSION.'"
xmlns:UML="http://www.omg.org/spec/UML/1.4">
<XMI.header>
<XMI.documentation>
<XMI.exporter>'.self::EXPORTER_NAME.'</XMI.exporter>
</XMI.documentation>
<XMI.metamodel XMI.name="UML" XMI.version="'.self::XMI_VERSION.'" />
</XMI.header>
<XMI.content>';
}
public function getXmiHeaderClose()
{
return '</XMI.content></XMI>';
}
public function getModelOpen(PHP_UML_Metamodel_Package $model)
{
return '<UML:Model name="'.$model->name.'" xmi.id="'.$model->id.'" '.
self::DEFAULT_CLASSIFIER_ATT.'>';
}
public function getStereotypes()
{
$str = '';
foreach (self::$allStereotypes as $item)
$str .= '<UML:Stereotype xmi.id="'.self::getUID('stereotype_'.$item).'"
name="'.$item.'" '.self::DEFAULT_CLASSIFIER_ATT.' />';
$str .= '<UML:Stereotype xmi.id="'.self::getUID('stereotype_realize').'"
name="realize" '.self::DEFAULT_CLASSIFIER_ATT.'>
<UML:Stereotype.baseClass>Abstraction</UML:Stereotype.baseClass>
</UML:Stereotype>';
$str .= $this->getTagDefinition('documentation');
return $str;
}
public function getStereotypeInstance(PHP_UML_Metamodel_Stereotype $s)
{
return '';
}
public function getMetadata(PHP_UML_Metamodel_Tag $tag)
{
return '<'.$tag->name.'>'.$tag->value.'</'.$tag->name.'>';
}
public function getModelClose()
{
return '</UML:Model>';
}
public function getPackageOpen(PHP_UML_Metamodel_Package $package)
{
$str = '<UML:Package xmi.id="'.$package->id.'" name="'.$package->name.'">';
if (isset($package->description)) {
$str .= $this->getComment($package->description);
}
return $str;
}
public function getNamespaceOpen()
{
return '<UML:Namespace.ownedElement>';
}
public function getPackageClose()
{
return '</UML:Package>';
}
public function getNamespaceClose()
{
return '</UML:Namespace.ownedElement>';
}
public function getSubsystemOpen(PHP_UML_Metamodel_Package $package)
{
return '<UML:Subsystem name="'.$package->name.'" xmi.id="'.
$package->id.'" isInstantiable="false"><UML:Namespace.ownedElement>';
}
public function getSubsystemClose()
{
return '</UML:Namespace.ownedElement></UML:Subsystem>';
}
public function getDatatype(PHP_UML_Metamodel_Datatype $type)
{
$str = '<UML:DataType xmi.id="'.$type->id.'"'.
' name="'.$type->name.'" visibility="public" isRoot="false" '.
' isLeaf="false" isAbstract="false">';
if (isset($class->description))
$str .= $this->getComment($class->description);
return $str.'</UML:DataType>';
}
public function getClass(PHP_UML_Metamodel_Class $class)
{
$str = '<UML:Class name="'.$class->name.'" xmi.id="'.
$class->id.'" visibility="package"
isAbstract="'.($class->isAbstract?'true':'false').'">';
list($generalizable, $generalization) = $this->getGeneralizations($class);
$str .= $generalizable;
$str .= '<UML:Classifier.feature>';
foreach ($class->ownedAttribute as &$property) {
$str .= $this->getProperty($property);
}
foreach ($class->ownedOperation as &$operation) {
$str .= $this->getOperation($operation);
}
$str .= '</UML:Classifier.feature>';
if (isset($class->description))
$str .= $this->getComment($class->description);
$str .= '</UML:Class>';
return $str.$generalization.$this->getRealizations($class);
}
public function getInterface(PHP_UML_Metamodel_Interface $interface)
{
$str = '<UML:Interface name="'.$interface->name.'"'.
' xmi.id="'.$interface->id.'"'.
' visibility="package" isAbstract="true">';
list($generalizable, $generalization) = $this->getGeneralizations($interface);
$str .= $generalizable;
$str .= '<UML:Classifier.feature>';
foreach ($interface->ownedOperation as &$operation)
$str .= $this->getOperation($operation);
$str .= '</UML:Classifier.feature>';
if (isset($interface->description))
$str .= $this->getComment($interface->description);
$str .= '</UML:Interface>';
return $str.$generalization;
}
public function getGeneralizations(PHP_UML_Metamodel_Type $client)
{
$str = '';
$generalizable = '';
$generalization = '';
foreach ($client->superClass as &$gclass) {
if (is_object($gclass)) {
$id = self::getUID();
$generalizable .= '<UML:GeneralizableElement.generalization>
<UML:Generalization xmi.idref="'.$id.'"/>
</UML:GeneralizableElement.generalization>';
$generalization .= '<UML:Generalization xmi.id="'.$id.'">
<UML:Generalization.child><UML:Class xmi.idref="'.
$client->id.
'" /></UML:Generalization.child>
<UML:Generalization.parent><UML:Class xmi.idref="'.
$gclass->id.'"/>
</UML:Generalization.parent></UML:Generalization>';
}
}
return array($generalizable, $generalization);
}
public function getRealizations(PHP_UML_Metamodel_Class $client)
{
$str = '';
foreach ($client->implements as &$rclass) {
if (is_object($rclass)) {
$str .= '<UML:Abstraction '.
'xmi.id="'.self::getUID().'" isSpecification="false">'.
'<UML:ModelElement.stereotype><UML:Stereotype xmi.idref="'.
self::getUID('stereotype_realize').'"/>'.
'</UML:ModelElement.stereotype>'.
'<UML:Dependency.client><UML:Class xmi.idref="'.
$client->id.
'"/></UML:Dependency.client>'.
'<UML:Dependency.supplier><UML:Interface xmi.idref="'.
$rclass->id.'"/>'.
'</UML:Dependency.supplier></UML:Abstraction>';
}
}
return $str;
}
public function getProperty(PHP_UML_Metamodel_Property $property)
{
$str = '<UML:Attribute xmi.id="'.$property->id.'"'.
' name="'.$property->name.'" '.
' visibility="'.$property->visibility.'" ';
if (!$property->isInstantiable) {
$str .= ' isStatic="true" ownerScope="classifier"';
} else {
$str .= ' ownerScope="instance"';
}
if ($property->isReadOnly)
$str .= ' changeability="frozen" isReadOnly="true" ';
$str .= '>';
$str .= self::getStructuralFeatureType($property);
if (isset($property->description))
$str .= $this->getComment($property->description);
$str .= '</UML:Attribute>';
return $str;
}
public function getOperation(PHP_UML_Metamodel_Operation $operation)
{
$str = '<UML:Operation xmi.id="'.$operation->id.'"'.
' name="'.$operation->name.'"'.
' visibility="'.$operation->visibility.'"';
if (!$operation->isInstantiable)
$str .= ' isStatic="true"';
if ($operation->isAbstract)
$str .= ' isAbstract="true"';
$str .= ' isQuery="false" concurrency="sequential">'.
'<UML:BehavioralFeature.parameter>';
foreach ($operation->ownedParameter as &$parameter) {
$str .= $this->getParameter($parameter);
}
$str .= '</UML:BehavioralFeature.parameter>';
if (isset($operation->description))
$str .= $this->getComment($operation->description);
$str .= '</UML:Operation>';
return $str;
}
public function getParameter(PHP_UML_Metamodel_Parameter $parameter)
{
return '<UML:Parameter xmi.id="'.$parameter->id.'" '.
' name="'.$parameter->name.'"'.
' kind="'.$parameter->direction.'">'.
$this->getParameterType($parameter).
'</UML:Parameter>';
}
public function getParameterType(PHP_UML_Metamodel_TypedElement $parameter)
{
$str = '';
$id = self::getUID();
// Exception to MOF : a PHP class can have the name of a datatype
if (isset($parameter->type->id)) {
$str .= '<UML:Parameter.type>'.
'<UML:DataType xmi.idref="'.$parameter->type->id.
'"/></UML:Parameter.type>';
}
if ($parameter->default!='') {
$str .= '<UML:Parameter.defaultValue>'.
'<UML:Expression xmi.id="'.$id.'"'.
' body="'.htmlspecialchars($parameter->default, ENT_QUOTES).'" />'.
'</UML:Parameter.defaultValue>';
}
return $str;
}
public function getArtifact(PHP_UML_Metamodel_Artifact $file, &$mf = array())
{
return '<UML:Artifact '.
' xmi.id="'.$file->id.'"'.
' name="'.basename(htmlspecialchars($file->name)).'">'.
'<UML:ModelElement.stereotype>'.
'<UML:Stereotype xmi.idref="'.self::getUID('stereotype_'.self::PHP_FILE).'"/>'.
'</UML:ModelElement.stereotype>'.
'</UML:Artifact>';
}
public function getComponentOpen(PHP_UML_Metamodel_Package $package, array $provided, array $required)
{
return self::getSubsystemOpen($package);
}
public function getComponentClose()
{
return self::getSubsystemClose();
}
public function getComment(PHP_UML_Metamodel_Stereotype $s, $annotatedElement='')
{
$tag = PHP_UML_Metamodel_Helper::getStereotypeTag($s, 'description');
if(!is_null($tag))
return $this->getTaggedValue($tag->value, self::getUID('Tag_documentation'));
else
return '';
}
public function getTaggedValue($value, $tag)
{
return '<UML:ModelElement.taggedValue>'.
'<UML:TaggedValue xmi.id="'.self::getUID().'" visibility="public">'.
'<UML:TaggedValue.dataValue>'.htmlspecialchars($value).'</UML:TaggedValue.dataValue>'.
'<UML:TaggedValue.type>'.
'<UML:TagDefinition xmi.idref="'.$tag.'"/>'.
'</UML:TaggedValue.type>'.
'</UML:TaggedValue>'.
'</UML:ModelElement.taggedValue>';
}
public function getTagDefinition($name)
{
return '<UML:TagDefinition xmi.id="'.self::getUID('Tag_'.$name).'" '.
'name="'.$name.'" isSpecification="false" tagType="string">
<UML:TagDefinition.multiplicity>
<UML:Multiplicity xmi.id="'.self::getUID('TagMultiplicity_'.$name).'">
<UML:Multiplicity.range>
<UML:MultiplicityRange xmi.id="'.self::getUID('TagMultiRange_'.$name).'"
lower="0" upper="1"/>
</UML:Multiplicity.range>
</UML:Multiplicity>
</UML:TagDefinition.multiplicity>
</UML:TagDefinition>';
}
public function getProfile()
{
}
/**
* Get the structural type of an element (XMI 1.x)
*
* @param PHP_UML_TypedElement $element Element
*
* @return string XMI code
*/
static protected function getStructuralFeatureType(PHP_UML_Metamodel_TypedElement $element)
{
$str = '';
$id = self::getUID();
if (!is_object($element->type))
return '';
if (get_class($element->type)=='PHP_UML_Metamodel_Class') {
$str .= '<UML:StructuralFeature.type>'.
'<UML:DataType xmi.idref="'.$element->type->id.
'"/></UML:StructuralFeature.type>';
} elseif (get_class($element->type)=='PHP_UML_Metamodel_Datatype') {
$str .= '<UML:StructuralFeature.type>'.
'<UML:DataType xmi.idref="'.$element->type->id.
'"/></UML:StructuralFeature.type>';
}
if ($element->default!='') {
$str .= '<UML:Attribute.initialValue>'.
'<UML:Expression xmi.id="'.$id.'"'.
' body="'.htmlspecialchars($element->default, ENT_QUOTES).'" />'.
'</UML:Attribute.initialValue>';
}
return $str;
}
}
?>

View File

@@ -0,0 +1,388 @@
<?php
/**
* PHP_UML (PHP_UML_Output_Xmi_BuilderImpl2)
*
* PHP version 5
*
* @category PHP
* @package PHP_UML
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version SVN: $Revision: 174 $
* @link http://pear.php.net/package/PHP_UML
* @since $Date: 2011-09-15 03:17:32 +0200 (jeu., 15 sept. 2011) $
*/
/**
* Implementation class to create XMI in version 2
*
* See the interface PHP_UML_Output_Xmi_Builder for the comments.
*
* @category PHP
* @package PHP_UML
* @subpackage Output
* @subpackage Xmi
* @see PHP_UML_Output_Xmi_Builder
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
*/
class PHP_UML_Output_Xmi_BuilderImpl2 extends PHP_UML_Output_Xmi_AbstractBuilder
{
const XMI_VERSION = '2.1';
const UML_VERSION = '2.1.2';
const DEFAULT_CLASSIFIER_ATT = ' visibility="public" isAbstract="false" ';
/**
* PHP_UML UML Profile (TODO)
* @var string
*/
public $profile = '';
public function getXmiHeaderOpen()
{
return '<xmi:XMI xmi:version="'.self::XMI_VERSION.'"
xmlns:uml="http://schema.omg.org/spec/UML/'.self::UML_VERSION.'"
xmlns:xmi="http://schema.omg.org/spec/XMI/'.self::XMI_VERSION.'"
xmlns:php="http://schemas/phpdoc/'.self::getUID().'">
<xmi:Documentation exporter="'.self::EXPORTER_NAME.'"/>';
}
public function getModelOpen(PHP_UML_Metamodel_Package $model)
{
return '<uml:Model xmi:type="uml:Model" name="'.$model->name.'"
xmi:id="'.$model->id.'" '.self::DEFAULT_CLASSIFIER_ATT.'>';
}
public function getModelClose()
{
return '</uml:Model>';
}
public function getXmiHeaderClose()
{
return '</xmi:XMI>';
}
public function getPackageOpen(PHP_UML_Metamodel_Package $package)
{
$str = '<packagedElement xmi:type="uml:Package" xmi:id="'.$package->id.
'" name="'.$package->name.'">';
if (isset($package->description)) {
$str .= $this->getComment($package->description, $package->id);
}
return $str;
}
public function getPackageClose()
{
return '</packagedElement>';
}
public function getNamespaceOpen()
{
return '';
}
public function getNamespaceClose()
{
return '';
}
public function getDatatype(PHP_UML_Metamodel_Datatype $type)
{
$str = '<packagedElement xmi:type="uml:DataType"'.
' xmi:id="'.$type->id.'"'.
' name="'.$type->name.'">';
if (isset($type->description))
$str .= $this->getComment($type->description, $type->id);
return $str.'</packagedElement>';
}
public function getSubsystemOpen(PHP_UML_Metamodel_Package $package)
{
return '<packagedElement xmi:type="uml:Component" xmi:id="'.
$package->id.'" name="'.$package->name.
'" '.self::DEFAULT_CLASSIFIER_ATT.'>';
}
public function getSubsystemClose()
{
return '</packagedElement>';
}
public function getClass(PHP_UML_Metamodel_Class $class)
{
$strRealization = '';
$str = '<packagedElement xmi:type="uml:Class" name="'.$class->name.'" xmi:id="'.
$class->id.'" visibility="package"
isAbstract="'.($class->isAbstract?'true':'false').'">';
$str .= $this->getGeneralizations($class);
$strRealization .= $this->getRealizations($class);
foreach ($class->ownedAttribute as &$property)
$str .= $this->getProperty($property);
foreach ($class->ownedOperation as &$operation)
$str .= $this->getOperation($operation);
if (isset($class->description))
$str .= $this->getComment($class->description, $class->id);
$str .= '</packagedElement>';
return $str.$strRealization;
}
public function getInterface(PHP_UML_Metamodel_Interface $interface)
{
$str = '<packagedElement xmi:type="uml:Interface" '.
' name="'.$interface->name.'" xmi:id="'.$interface->id.'"'.
' visibility="package" isAbstract="true">';
foreach ($interface->ownedOperation as &$operation)
$str .= $this->getOperation($operation);
$str .= $this->getGeneralizations($interface);
if (isset($interface->description))
$str .= $this->getComment($interface->description, $interface->id);
$str .= '</packagedElement>';
return $str;
}
public function getRealizations(PHP_UML_Metamodel_Class $client)
{
$str = '';
foreach ($client->implements as &$rclass) {
if (is_object($rclass)) {
$str .= '<packagedElement xmi:type="uml:Realization" '.
'xmi:id="'.self::getUID().'" '.
'client="'.$client->id.'" '.
'supplier="'.$rclass->id.'" '.
'realizingClassifier="'.$rclass->id.'"/>';
}
}
return $str;
}
public function getGeneralizations(PHP_UML_Metamodel_Type $client)
{
$str = '';
foreach ($client->superClass as &$gclass) {
if (is_object($gclass)) {
$str .= '<generalization xmi:type="uml:Generalization" '.
'xmi:id="'.self::getUID().'" '.
'general="'.$gclass->id.'"/> ';
}
}
return $str;
}
public function getProperty(PHP_UML_Metamodel_Property $property)
{
$str = '<ownedAttribute xmi:type="uml:Property"'.
' name="'.$property->name.'"'.
' xmi:id="'.$property->id.'"'.
' visibility="'.$property->visibility.'" ';
if (!$property->isInstantiable)
$str .= ' isStatic="true"';
if ($property->isReadOnly)
$str .= ' isReadOnly="true" ';
$str .= '>'.$this->getParameterType($property);
if (isset($property->description))
$str .= $this->getComment($property->description, $property->id);
$str .= '</ownedAttribute>';
return $str;
}
public function getOperation(PHP_UML_Metamodel_Operation $operation)
{
$str = '<ownedOperation xmi:id="'.$operation->id.'"
name="'.$operation->name.'" visibility="'.$operation->visibility.'" ';
if (!$operation->isInstantiable)
$str .= ' isStatic="true"';
if ($operation->isAbstract)
$str .= ' isAbstract="true"';
$str .= '>';
foreach ($operation->ownedParameter as &$parameter) {
$str .= $this->getParameter($parameter);
}
if (isset($operation->description))
$str .= $this->getComment($operation->description, $operation->id);
$str .= '</ownedOperation>';
return $str;
}
public function getParameter(PHP_UML_Metamodel_Parameter $parameter)
{
return '<ownedParameter xmi:id="'.$parameter->id.'" '.
'name="'.$parameter->name.'" direction="'.$parameter->direction.'">'.
$this->getParameterType($parameter).
'</ownedParameter>';
}
public function getParameterType(PHP_UML_Metamodel_TypedElement $parameter)
{
$str = '';
$id = self::getUID();
if (isset($parameter->type->id))
$str = '<type xmi:idref="'.$parameter->type->id.'"/>';
if ($parameter->default!='')
$str .= '<defaultValue xmi:type="uml:LiteralString" xmi:id="'.$id.'"'.
' value="'.htmlspecialchars($parameter->default, ENT_QUOTES).'" />';
return $str;
}
public function getArtifact(PHP_UML_Metamodel_Artifact $file, &$mf = array())
{
$id = $file->id;
$file = htmlspecialchars($file->name);
$name = basename($file);
$str = '
<packagedElement xmi:type="uml:Artifact"'.
' xmi:id="'.$id.'"'.
' name="'.$name.'" '.
' stereotype="'.self::getUID('stereotype_'.self::PHP_FILE).'" '.
self::DEFAULT_CLASSIFIER_ATT.' >';
foreach ($mf as $class) {
if ($class instanceof PHP_UML_Metamodel_Classifier) {
$id_supplier = $class->id;
$str .= self::getManifestation($id, $id_supplier, 'source');
}
}
$str .= '</packagedElement>';
return $str;
}
public function getComponentOpen(PHP_UML_Metamodel_Package $package, array $provided, array $required)
{
$str = '
<packagedElement xmi:type="uml:Component"'.
' xmi:id="'.$package->id.'"'.
' name="'.$package->name.'" '.
self::DEFAULT_CLASSIFIER_ATT.' >';
foreach ($provided as $c) {
switch (get_class($c)) {
case 'PHP_UML_Metamodel_Interface':
case 'PHP_UML_Metamodel_Class':
$id = self::getUID('CV_provided_'.$c->name);
$id_provided = $c->id;
$str .= '<provided xmi:id="'.$id.'" xmi:idref="'.$id_provided.
'" name="'.$c->name.'"/>';
}
}
foreach ($required as $c) {
$id = self::getUID('CV_required_'.$c->name);
$id_provided = $c->id;
$str .= '<required xmi:id="'.$id.'" xmi:idref="'.$id_provided.'" name="'.$c->name.'"/>';
}
return $str;
}
public function getComponentClose()
{
return '</packagedElement>';
}
/**
* Formates a Profile adapted to PHP_UML.
*
* TODO. Experimental.
*
* @return string XMI Code
*/
public function getProfile()
{
return file_get_contents('../Metamodel/phpdoc.profile.xmi').
'<profileApplication xmi:type="uml:ProfileApplication" xmi:id="'.self::getUID().'">'.
'<appliedProfile xmi:idref="PHP_UML_phpdoc_1"/>'.
'</profileApplication>';
}
public function getComment(PHP_UML_Metamodel_Stereotype $s, $annotatedElement='')
{
$tag = PHP_UML_Metamodel_Helper::getStereotypeTag($s, 'description');
if(!is_null($tag))
return '<ownedComment xmi:type="uml:Comment"
xmi:id="'.self::getUID().'" annotatedElement="'.$annotatedElement.
'"><body>'.htmlspecialchars($tag->value).'</body></ownedComment>';
else
return '';
}
public function getStereotypes()
{
return '';
}
/**
* Gets all the elements contained in a stereotype
* Note: the property "documentation" is not discarded (we will have
* it as an "ownedComent" tag, instead; see getComment())
*
* @param PHP_UML_Metamodel_Stereotype $s Stereotype
*
* @return string
*/
public function getStereotypeInstance(PHP_UML_Metamodel_Stereotype $s)
{
$str = '';
foreach ($s->ownedAttribute as $tag) {
if($tag->value!='' && $tag->name!='description')
$str .= $this->getMetadata($tag);
}
if ($str!='')
return '<'.$s->profile.':'.$s->name.
' base_Element="'.$s->element->id.'">'.
$str.'</'.$s->profile.':'.$s->name.'>';
else
return '';
}
public function getMetadata(PHP_UML_Metamodel_Tag $tag)
{
return '<'.$tag->name.'>'.htmlspecialchars($tag->value).'</'.$tag->name.'>';
}
/**
* Generates a manifestation element (= the link between a class and the
* artifact where the class is defined)
*
* @param string $client Name of the client
* @param string $supplier Name of the supplier
* @param string $name Name of the relation
*
* @return string XMI code
*/
public function getManifestation($client, $supplier, $name)
{
return '<manifestation xmi:type="uml:Manifestation" '.
'xmi:id="'.self::getUID().'" '.
'client="'.$client.'" supplier="'.$supplier.'" '.
'utilizedElement="'.$supplier.'" name="'.$name.'"/>';
}
}
?>

View File

@@ -0,0 +1,247 @@
<?php
/**
* PHP_UML
*
* PHP version 5
*
* @category PHP
* @package PHP_UML
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version SVN: $Revision: 176 $
* @link http://pear.php.net/package/PHP_UML
* @since $Date: 2011-09-19 00:03:11 +0200 (lun., 19 sept. 2011) $
*/
/**
* This class generates the XMI from a UML model (PHP_UML_Metamodel)
*
* @category PHP
* @package PHP_UML
* @subpackage Output
* @subpackage Xmi
* @author Baptiste Autin <ohlesbeauxjours@yahoo.fr>
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
*/
class PHP_UML_Output_Xmi_Exporter extends PHP_UML_Output_ExporterAPI
{
/**
* Reference to an XmiDocument object. Such an object is needed by the export()
* method of Xmi_Exporter and its subclasses (unlike the ExporterAPI implementations,
* which work on the metamodel directly, and don't need to know anything about XMI).
*
* @var PHP_UML_Output_XmiDocument
*/
protected $xmiDocument;
/**
* Default XMI version used for serialization. Note that all XSL-based
* exporters will generate XMI with the default xmiVersion and encoding.
*
* @var float
*/
protected $xmiVersion = 2;
/**
* Default XML encoding of the XMI document.
*
* @var string
*/
protected $encoding = 'iso-8859-1';
/**
* A logical view is included in the model by default.
*
* @var boolean
*/
protected $logicalView = true;
/**
* A deployment view is not included in the model by default.
*
* @var boolean
*/
protected $deploymentView = false;
/**
* A component view is not included in the model by default.
*
* @var boolean
*/
protected $componentView = false;
/**
* Stereotypes are not included in the model by default.
*
* @var boolean
*/
protected $stereotypes = false;
/**
* Setter for the XML encoding
*
* @param string $encoding Encoding
*/
public function setEncoding($encoding)
{
$this->encoding = $encoding;
}
/**
* Setter for the XMI version
*
* @param float $version XMI version
*/
public function setXmiVersion($version)
{
$this->xmiVersion = $version;
}
/**
* Enables the inclusion of a logical view in the serialized model
*
* @param boolean $value True/False
*/
public function setLogicalView($value)
{
$this->logicalView = $value;
}
/**
* Enables the inclusion of a deployment view in the serialized model
*
* @param boolean $value True/False
*/
public function setDeploymentView($value)
{
$this->deploymentView = $value;
}
/**
* Enables the inclusion of a component view in the serialized model
*
* @param boolean $value True/False
*/
public function setComponentView($value)
{
$this->componentView = $value;
}
/**
* Enables the inclusion of the stereotypes in the serialized model
* If true, all the stereotypes related to the UML model (currently, these
* data correspond to the PHP docblocks) will be added to the XMI model.
*
* @param boolean $value True/False
*/
public function setStereotypes($value)
{
$this->stereotypes = $value;
}
/**
* Setter for the XmiDocument
*
* @param PHP_UML_Output_XmiDocument $xmiDocument XMI Document
*/
public function setXmiDocument(PHP_UML_Output_XmiDocument $xmiDocument)
{
$this->xmiDocument = $xmiDocument;
}
/**
* Getter for the XmiDocument
*
* @return PHP_UML_Output_XmiDocument
*/
public function getXmiDocument()
{
return $this->xmiDocument;
}
public function export($outDir)
{
if (empty($this->structure))
throw new PHP_UML_Exception('No model given.');
//if (empty($this->xmiDocument)) {
$this->generateXmi();
//}
if ($outDir=='')
return $this->xmiDocument->dump();
else {
if (!is_dir($outDir))
$this->save($outDir);
else
{
$fileName = empty($this->structure->packages) ? 'undefined' : $this->structure->packages->name;
$this->save($outDir.DIRECTORY_SEPARATOR.$fileName.'.xmi');
}
}
}
/**
* Internal method to save the generated XMI to a file.
* Use export() instead if you need to save from outside the Exporter object.
*
* @param string $outputFile Filename
*/
protected function save($outputFile)
{
if ($ptr = fopen($outputFile, 'w+')) {
fwrite($ptr, $this->xmiDocument->dump());
fclose($ptr);
} else {
throw new PHP_UML_Exception(
'File '.$outputFile.' could not be created.'
);
}
}
/**
* Serialize the metamodel (contained in the property $structure) into XMI code
*
* It is not necessary to call this method before calling export();
*/
public function generateXmi()
{
$builder = $this->getXmiBuilder();
$this->xmiDocument = $builder->getXmiDocument($this->structure);
}
/**
* Getter for the XMI factory
*
* @return PHP_UML_Output_Xmi_Builder An XMI builder object
*/
protected function getXmiBuilder()
{
$builder = PHP_UML_Output_Xmi_AbstractBuilder::getInstance($this->xmiVersion);
$builder->setEncoding($this->encoding);
$builder->setLogicalView($this->logicalView);
$builder->setComponentView($this->componentView);
$builder->setDeploymentView($this->deploymentView);
$builder->setStereotypes($this->stereotypes);
return $builder;
}
/**
* Read the content of an existing XMI file.
* If the file is UML/XMI 1, a conversion to version 2 is automatically applied.
*
* @param string $filepath Filename
*/
public function loadXmi($filepath)
{
if (empty($this->xmiDocument)) {
$this->xmiDocument = new PHP_UML_Output_XmiDocument();
}
$this->xmiDocument->load($filepath);
}
}
?>