Git Product home page Git Product logo

staruml-php's Introduction

PHP Extension for StarUML

This extension for StarUML(http://staruml.io) support to generate PHP code from UML model. Install this extension from Extension Manager of StarUML.

Based on https://github.com/staruml/staruml-java

PHP Code Generation

  1. Click the menu (Tools > PHP > Generate Code...)
  2. Select a base model (or package) that will be generated to PHP.
  3. Select a folder where generated PHP source files will be placed.

Belows are the rules to convert from UML model elements to PHP source codes.

UMLPackage

  • converted to PHP Namespace (as a folder).

UMLClass

  • converted to PHP Class. (as a separate .php file)
  • visibility to one of modifiers public, protected, private and none.
  • isAbstract property to abstract modifier.
  • Default constructor is generated.
  • All contained types (UMLClass, UMLInterface, UMLEnumeration) are generated as inner type definition.
  • Documentation property to PHPDoc comment.

UMLAttribute

  • converted to PHP Field.
  • visibility property to one of modifiers public, protected, private and none.
  • name property to field identifier.
  • multiplicity property to array type.
  • isStatic property to static modifier.
  • defaultValue property to initial value.
  • Documentation property to PHPDoc comment.

UMLOperation

  • converted to PHP Methods.
  • visibility property to one of modifiers public, protected, private and none.
  • name property to method identifier.
  • isAbstract property to abstract modifier.
  • isStatic property to static modifier.
  • UMLParameter to PHP Method Parameters.
  • UMLParameter's name property to parameter identifier.
  • Documentation property to PHPDoc comment.

UMLInterface

  • converted to PHP Interface. (as a separate .php file)
  • visibility property to one of modifiers public, protected, private and none.
  • Documentation property to PHPDoc comment.

UMLEnumeration

  • converted to PHP Class. (as a separate .php file)
  • visibility property to one of modifiers public, protected, private and none.
  • UMLEnumerationLiteral to literals of enum.

UMLAssociationEnd

  • converted to PHP Field.
  • visibility property to one of modifiers public, protected, private and none.
  • name property to field identifier.
  • defaultValue property to initial value.
  • Documentation property to PHPDoc comment.

UMLGeneralization

  • converted to PHP Extends (extends).
  • Allowed only for UMLClass to UMLClass, and UMLInterface to UMLInterface.

UMLInterfaceRealization

  • converted to PHP Implements (implements).
  • Allowed only for UMLClass to UMLInterface.

Licensed under the MIT license (see LICENSE file).

staruml-php's People

Contributors

nahakiole avatar niklauslee avatar ricardopedias avatar tekreme73 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

staruml-php's Issues

Default value for parameter is not set

Default value for operation parameters are not set after code generation
Operation parameters can't have a default value, as it'll not be set after code generation

Attach the .mdj file
.mdj files are not supported which is why I embed two screenshots

To Reproduce
Steps to reproduce the behavior:

  1. Create a class diagram
  2. Create a class
  3. Add an operation to the class
  4. Add a parameter to the operation
  5. Click on the parameter to configure
  6. Go under "Properties"
  7. Write down a type related value under "defaultValue"

Expected behavior

  1. Code should be generated
  2. Parameter has a default value

Actual behavior

  1. Parameter has no default value

Screenshots
Bildschirmfoto 2019-03-28 um 23 02 30
Bildschirmfoto 2019-03-28 um 23 02 52

Type hints not working correctly?

Type hints don't get the class names but instead [object Object]. Is this a bug, or am I doing something wrong?

Here's an example.

Class diagram:

+-----------------------+
| SynchronizerInterface |
+-----------------------+
| +synchronize()        |
+-----------------------+
+---------------------------------------------------------------+
|                         Synchronizer                          |
+---------------------------------------------------------------+
| -synchronizers: SynchronizerInterface[0..*]                   |
+---------------------------------------------------------------+
| +__construct(synchronizers: SynchronizerInterface[0..*] = []) |
| +add(synchronizer: SynchronizerInterface)                     |
+---------------------------------------------------------------+

Generated PHP code of the SynchronizerInterface interface and Synchronizer implementation:

interface SynchronizerInterface
{

    /**
     * 
     */
    public function synchronize();

}

class Synchronizer implements SynchronizerInterface
{

    /** @var [object Object][] */
    private array $synchronizers;

    /**
     * @param [object Object][] $synchronizers
     */
    public function __construct([object Object] $synchronizers = [])
    {
        // TODO implement here
    }

    /**
     * @param [object Object] $synchronizer
     */
    public function add([object Object] $synchronizer)
    {
        // TODO implement here
    }

    /**
     * 
     */
    public function synchronize()
    {
        // TODO implement here
    }

}

Type-hint arguments and return types

Could you add (or direct me) to how I can generate code with 7.1 type hints?

function myFunction( int $integer ): string
{
    return "{$integer}";
}

Property "readOnly" won't generate to a class constant

Attribute property: "readOnly" won't convert to const
With StarUML you can create--of course--attributes. Some of them may be constants so there is an option to mark them as such. This property is called readOnly.

Attach the .mdj file
.mdj files are not supported which is why I created two sceenshots.

To Reproduce
Steps to reproduce the behavior:

  1. Create a class diagram
  2. Create a class
  3. Create an attribute
  4. Click on the attribute to configure
  5. Go under "Properties"
  6. Click "isReadOnly" to mark it as a class constant
  7. Go under Tools > PHP and click on "Generate code"

Expected behavior

  1. Code should be generated
  2. The generated attribute should be a class constant variable

Actual behavior

  1. The readOnly property gets ignored and the generated attribute is a normal class variable.

Screenshots
Bildschirmfoto 2019-03-28 um 22 53 18
Bildschirmfoto 2019-03-28 um 22 53 53

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.