Skip to content

Sufir/php-plantuml-wrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

php-plantuml-wrap

Wrap for PlantUml on PHP. Quick generating UML diagrams.

Installing with composer

"require": {
	"sufir/php-plantuml-wrap": "dev-master"
},

Example 1

    $plantuml = new PlantUml();

	// Create new component diagram
    $diagram = $plantuml->createDiagram('component')
        ->setUmlNotation(Component::NOTATION_UML1);

	// Create diagram elements
    $firstComponent = $plantuml->createElement('component', 'component', 'First Component')
        ->setNote("A note can also be\non several lines", 'right');
    $da = $plantuml->createElement('component', 'interface', 'Data Access');
    $http = $plantuml->createElement('component', 'interface', 'HTTP')
        ->setNote("Web Service only");

	// Create relations
    $rel1 = $plantuml->createRelation($firstComponent, $da)
        ->setDirection(Relation::DIRECTION_LEFT);
    $rel2 = $plantuml->createRelation()
        ->setFrom($firstComponent)
        ->setTo($http, Relation::ARROW_ASSOCIATION)
        ->setDirection(Relation::DIRECTION_BOTTOM)
        ->setLineType(Relation::LINE_DOTTED);

	// Assembly diagram
    $diagram->addElement($firstComponent)
        ->addElement($da)
        ->addElement($http)
        ->addRelation($rel1)
        ->addRelation($rel2);

	// Render diagram
    echo $plantuml->convertDiagram($diagram);

Example 2

	$plantuml = new PlantUml();

	// Create new component diagram
    $diagram = $plantuml->createDiagram('component')
        ->setUmlNotation(Component::NOTATION_UML2);

    // Style for webservers
    $webserverSkin = $plantuml->createSkin()
        ->setBackgroundGradient('white', 'lightblue')
        ->setBorderColor('black');

    // Create elements stereotype https://en.wikipedia.org/wiki/Stereotype_(UML)
    $webserverStereotype = $plantuml->createStereotype('Web Server')
        ->setSkin($webserverSkin);

    // Create diagram elements
    $firstComponent = $plantuml->createElement('component', 'component', 'First Component')
        ->setNote("A note can also be\non several lines", 'right');
    $da = $plantuml->createElement('component', 'interface', 'Data Access');
    $http = $plantuml->createElement('component', 'interface', 'HTTP')
        ->setNote("Web Service only");
    $webserver1 = $plantuml->createElement('component', 'component', 'Apache')
        ->addStereotype($webserverStereotype);
    $webserver2 = $plantuml->createElement('component', 'component', 'Nginx')
        ->addStereotype($webserverStereotype);

    // Grouping components
    $webserversGroup = $plantuml->createElement('component', 'frame', 'Servers')
        ->addElement($webserver1)
        ->addElement($webserver2);

    // Create relations
    $rel1 = $plantuml->createRelation($firstComponent, $da)
        ->setDirection(Relation::DIRECTION_LEFT);
    $rel2 = $plantuml->createRelation()
        ->setFrom($firstComponent)
        ->setTo($http, Relation::ARROW_EXTENSION)
        ->setLabel('Rel label...')
        ->setDirection(Relation::DIRECTION_BOTTOM)
        ->setLineType(Relation::LINE_DOTTED);
    $rel3 = $plantuml->createRelation()
        ->setFrom($http)
        ->setTo($webserver1, Relation::ARROW_ASSOCIATION)
        ->setDirection(Relation::DIRECTION_RIGHT)
        ->setColor('darkgreen');
    $rel4 = $plantuml->createRelation()
        ->setFrom($http)
        ->setTo($webserver2, Relation::ARROW_ASSOCIATION)
        ->setDirection(Relation::DIRECTION_RIGHT)
        ->setColor('darkgreen');

    // Assembly diagram
    $diagram->addElement($firstComponent)
        ->addElement($da)
        ->addElement($http)
        ->addElement($webserversGroup)
        ->addRelation($rel1)
        ->addRelation($rel2)
        ->addRelation($rel3)
        ->addRelation($rel4);

    // Render diagram
    echo $plantuml->convertDiagram($diagram);

About

Wrap for PlantUml on PHP. Quick generating UML diagrams.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages