php-plantumlwriter icon indicating copy to clipboard operation
php-plantumlwriter copied to clipboard

PHP Trait support

Open pjordaan opened this issue 10 years ago • 2 comments

First of all, I like the php plantuml writer. Works better than I expected.

One thing I did notice is how it worked on traits that were introduced in PHP 5.4. They do show up as regular classes with no dependencies. It would be nice to see what classes use what traits (or traits using other traits).

pjordaan avatar Dec 03 '14 08:12 pjordaan

Hm. I've been thinking about this as well but I'm not sure how to represent traits in uml.

Currently this code

<?php

trait traitAlpha
{
    function traitMethodOne()
    {
    }

    function traitMethodTwo()
    {
    }
}

trait traitBeta
{
    function traitMethodThree()
    {
    }
}

class aClassUsingATrait
{
    use traitAlpha, traitBeta {
        traitAlpha::traitMethodTwo as traitMethodRenamed;
    }
}

Will result in this UML:

@startuml
abstract class traitAlpha {
    +traitMethodOne()
    +traitMethodTwo()
}
abstract class traitBeta {
    +traitMethodThree()
}
class aClassUsingATrait {
}
@enduml

trait

There are some discussions on how to display traits in uml:

  • http://programmers.stackexchange.com/questions/215968/is-there-a-representation-for-mixins-or-traits-on-uml
  • http://stackoverflow.com/questions/2690249/how-do-i-represent-a-mixin-role-trait-with-uml-properly

Any suggestions on how the php code above should be rendered in uml?

davidfuhr avatar Dec 05 '14 09:12 davidfuhr

I think the multiple inheritance with a << trait >> marker (or something similar) is the simplest solution, but it is indeed interesting to think how it should be shown. I'm not sure how you would display the insteadof operator thing (besides renames, it can also change it's accessibility)

pjordaan avatar Dec 09 '14 11:12 pjordaan