struturizr-php/structurizr-php

此包已被弃用,不再维护。作者建议使用structurizr-php/structurizr-php包。

PHP版的Structurizr

0.4.0 2024-04-30 07:54 UTC

README

Minimum PHP Version Latest Stable Version Tests Total Downloads License

此仓库是Java版的Structurizr的移植。所有关于创建C4的荣誉当然归Simon Brown所有,这个库只是简单地将其他语言中已经存在的代码进行了移植。

如何使用

安装

composer require structurizr-php/structurizr-php

快速示例

以下PHP代码示例可用于创建一个软件架构模型和相关联的视图,描述用户使用软件系统。

<?php 

$workspace = new Workspace(
    $id = (string)\getenv('STRUCTURIZR_WORKSPACE_ID'),
    $name = 'Getting Started',
    $description = 'This is a model of my software system. by structurizr-php/structurizr-php'
);
$workspace->getModel()->setEnterprise(new Enterprise('Structurizr PHP'));
$person = $workspace->getModel()->addPerson(
    $name = 'User',
    $description = 'A user of my software system.',
    Location::internal()
);
$softwareSystem = $workspace->getModel()->addSoftwareSystem(
    $name = 'Software System',
    $description = 'My software system.',
    Location::internal()
);
$person->usesSoftwareSystem($softwareSystem, 'Uses', 'Http');

$contextView = $workspace->getViews()->createSystemContextView($softwareSystem, 'System Context', 'system01', 'An example of a System Context diagram.');
$contextView->addAllElements();
$contextView->setAutomaticLayout(true);

$styles = $workspace->getViews()->getConfiguration()->getStyles();

$styles->addElementStyle(Tags::SOFTWARE_SYSTEM)->background("#1168bd")->color('#ffffff');
$styles->addElementStyle(Tags::PERSON)->background("#08427b")->color('#ffffff')->shape(Shape::person());

$client = new Client(
    new Credentials((string) \getenv('STRUCTURIZR_API_KEY'), (string) \getenv('STRUCTURIZR_API_SECRET')),
    new UrlMap('https://api.structurizr.com'),
    new Psr18Client(),
    new SymfonyRequestFactory(),
    new Logger('structurizr', [new StreamHandler('php://stdout')])
);
$client->put($workspace);

然后可以将视图导出,以多种方式可视化;例如,PlantUML、Structurizr和Graphviz。

Views can be exported and visualised in many ways; e.g. PlantUML, Structurizr and Graphviz

更多示例

在社交中招聘

在社交中招聘 - 项目示例

Structurizr工作区

系统景观

System Landscape System Landscape Key

容器

Container Container Key

大银行有限公司

System Landscape System Context Contianer Components Dynamic Development Deployment Live Deployment