将条件包装到函数中还是根本不在序列图中表示它?
Wrap conditional into a function or not represent it at all in a sequence diagram?
我有这个 PHP 控制器 class(属于 Symfony2 包):
class ReptoolController extends PageController
{
// ...
private function _get($request, $action, $case)
{
$app_id = $this->getRequested('app_id');
if( ( $repappConfig = $this->getDoctrine()->getRepository('PDOneBundle:RepappConfig')->findOneBy(array("app_id"=>$app_id))) )
{
$current_timestamp = new \DateTime(date('Y-m-d'));
if($repappConfig->getExpireDate())
$expire_date = $repappConfig->getExpireDate()->getTimestamp();
else
{
$temp = $current_timestamp;
$temp->modify("+7 day");
$temp->format("Y-m-d");
$expire_date = $temp->getTimestamp();
}
if($expire_date < $current_timestamp->getTimestamp())
{
$response = new \stdClass();
$response->status = FormUtilities::RESPONSE_STATUS_BAD;
$controller_response = new Response( json_encode($response) );
$controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
return $controller_response;
}
}
switch($case)
{
// ...
case FormUtilities::CASE_BRAND_CUSTOM_MESSAGES:
return $this->getBrandCustomMessages($request, $action, $case);
break;
// ...
default:
$response = new \stdClass();
$response->status = FormUtilities::RESPONSE_STATUS_BAD;
$controller_response = new Response( json_encode($response) );
$controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
return $controller_response;
break;
}
}
// ...
private function getBrandCustomMessages($request, $action, $case)
{
$id = $this->getRequested('app_id');
$reptool_records = $this->getRequestedSync();
$response = new \stdClass();
$response->status = FormUtilities::RESPONSE_STATUS_BAD;
$repappConfig = new RepappConfig();
$repappConfig = $this->getDoctrine()->getRepository('PDOneBundle:RepappConfig')->findOneBy(array("app_id"=>$id));
$project_id = $repappConfig->getProjectId();
$brand_table = $this->getDoctrine()->getRepository('PDOneBundle:Brand')->findBy(array("project"=>$project_id));
if($brand_table)
{
foreach($brand_table as $bt)
{
$brand_id = $bt->getID();
$brandCustomMessages = new BrandCustomMessages();
if( $brandCustomMessages = $this->getDoctrine()->getRepository('PDOneBundle:BrandCustomMessages')->findBy(array("brand_id"=>$brand_id) ))
{
$sync = array();
foreach ($brandCustomMessages as $brandCustomMessage)
{
$response->status = FormUtilities::RESPONSE_STATUS_VALID;
$brandCustMess = new PDOneResponse(
$brandCustomMessage->getID(),
strtotime($brandCustomMessage->getModifiedAt()->format("Y-m-d H:i:s"))
);
$brandCustMess->id = $brandCustomMessage->getID();
$brandCustMess->message_text = $brandCustomMessage->getMessageText();
$brandCustMess->message_code = $brandCustomMessage->getMessageCode();
$brandCustMess->brand_id = (int)$brandCustomMessage->getBrandId();
$reptool_records = $brandCustMess->setRecordStatus($reptool_records);
// ADD BACKEND RECORD TO SYNC
if($brandCustMess->status != FormUtilities::RESPONSE_STATUS_OK ) $sync[] = $brandCustMess;
}
// COMPOSITE SYNC WITH REPTOOL RECORDS
$sync = PDOneResponse::compositeSync($sync, $reptool_records);
$response->sync = $sync;
}
}
}
$controller_response = new Response( json_encode($response) );
$controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
return $controller_response;
}
// ...
我需要为来自参与者 PDOneApp
的流程构建一个序列图 (SD)(这是一个 iPad 应用程序向该控制器发出 get|set
请求)。这就是我在 SD Version1, SD Version 2:
中所做的
版本 1
版本 2
关于上面的图我有以下的疑惑,也以上面的代码为例:
哪张图是正确的?
实体的调用(意思是图表中的表示):RepappConfig
和 Brand
是正确的吗?在代码中,此调用是从方法 getBrandCustomMessages()
中进行的,我直接从控制器 ReptoolController
中获取它们,这让我认为这是错误的。如果是这种情况,应该如何表示?
我知道 SD 并不是要按原样表示代码,但是,您如何表示函数的条件?也许我可以将条件包装在一个函数中并从 getBrandCustomMessages()
中调用该函数,这是正确的方法吗?这个疑惑你有什么推荐给我的?
正如您将在函数中看到的那样,最后一个 return 是一个 Response 对象,那部分在图表上是正确的吗?或者该行应该用 return 标签划线?
任何人都可以帮助完成此图并理解 UML SD 的 conditional
部分吗?
您的第二张图表正确显示了对 getBrandCustomMessages
的内部调用。
如果你真的想显示 if
然后使用片段 (http://www.uml-diagrams.org/sequence-diagrams-combined-fragment.html)。您可以将片段分成单个分区(if/else 或大小写;任何合适的)。
最后的响应不应发送给实体,而应作为 return 消息(来自内部调用之后)发送给参与者。这可能是您想要展示的内容。
我有这个 PHP 控制器 class(属于 Symfony2 包):
class ReptoolController extends PageController
{
// ...
private function _get($request, $action, $case)
{
$app_id = $this->getRequested('app_id');
if( ( $repappConfig = $this->getDoctrine()->getRepository('PDOneBundle:RepappConfig')->findOneBy(array("app_id"=>$app_id))) )
{
$current_timestamp = new \DateTime(date('Y-m-d'));
if($repappConfig->getExpireDate())
$expire_date = $repappConfig->getExpireDate()->getTimestamp();
else
{
$temp = $current_timestamp;
$temp->modify("+7 day");
$temp->format("Y-m-d");
$expire_date = $temp->getTimestamp();
}
if($expire_date < $current_timestamp->getTimestamp())
{
$response = new \stdClass();
$response->status = FormUtilities::RESPONSE_STATUS_BAD;
$controller_response = new Response( json_encode($response) );
$controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
return $controller_response;
}
}
switch($case)
{
// ...
case FormUtilities::CASE_BRAND_CUSTOM_MESSAGES:
return $this->getBrandCustomMessages($request, $action, $case);
break;
// ...
default:
$response = new \stdClass();
$response->status = FormUtilities::RESPONSE_STATUS_BAD;
$controller_response = new Response( json_encode($response) );
$controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
return $controller_response;
break;
}
}
// ...
private function getBrandCustomMessages($request, $action, $case)
{
$id = $this->getRequested('app_id');
$reptool_records = $this->getRequestedSync();
$response = new \stdClass();
$response->status = FormUtilities::RESPONSE_STATUS_BAD;
$repappConfig = new RepappConfig();
$repappConfig = $this->getDoctrine()->getRepository('PDOneBundle:RepappConfig')->findOneBy(array("app_id"=>$id));
$project_id = $repappConfig->getProjectId();
$brand_table = $this->getDoctrine()->getRepository('PDOneBundle:Brand')->findBy(array("project"=>$project_id));
if($brand_table)
{
foreach($brand_table as $bt)
{
$brand_id = $bt->getID();
$brandCustomMessages = new BrandCustomMessages();
if( $brandCustomMessages = $this->getDoctrine()->getRepository('PDOneBundle:BrandCustomMessages')->findBy(array("brand_id"=>$brand_id) ))
{
$sync = array();
foreach ($brandCustomMessages as $brandCustomMessage)
{
$response->status = FormUtilities::RESPONSE_STATUS_VALID;
$brandCustMess = new PDOneResponse(
$brandCustomMessage->getID(),
strtotime($brandCustomMessage->getModifiedAt()->format("Y-m-d H:i:s"))
);
$brandCustMess->id = $brandCustomMessage->getID();
$brandCustMess->message_text = $brandCustomMessage->getMessageText();
$brandCustMess->message_code = $brandCustomMessage->getMessageCode();
$brandCustMess->brand_id = (int)$brandCustomMessage->getBrandId();
$reptool_records = $brandCustMess->setRecordStatus($reptool_records);
// ADD BACKEND RECORD TO SYNC
if($brandCustMess->status != FormUtilities::RESPONSE_STATUS_OK ) $sync[] = $brandCustMess;
}
// COMPOSITE SYNC WITH REPTOOL RECORDS
$sync = PDOneResponse::compositeSync($sync, $reptool_records);
$response->sync = $sync;
}
}
}
$controller_response = new Response( json_encode($response) );
$controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
return $controller_response;
}
// ...
我需要为来自参与者 PDOneApp
的流程构建一个序列图 (SD)(这是一个 iPad 应用程序向该控制器发出 get|set
请求)。这就是我在 SD Version1, SD Version 2:
版本 1
版本 2
关于上面的图我有以下的疑惑,也以上面的代码为例:
哪张图是正确的?
实体的调用(意思是图表中的表示):
RepappConfig
和Brand
是正确的吗?在代码中,此调用是从方法getBrandCustomMessages()
中进行的,我直接从控制器ReptoolController
中获取它们,这让我认为这是错误的。如果是这种情况,应该如何表示?我知道 SD 并不是要按原样表示代码,但是,您如何表示函数的条件?也许我可以将条件包装在一个函数中并从
getBrandCustomMessages()
中调用该函数,这是正确的方法吗?这个疑惑你有什么推荐给我的?正如您将在函数中看到的那样,最后一个 return 是一个 Response 对象,那部分在图表上是正确的吗?或者该行应该用 return 标签划线?
任何人都可以帮助完成此图并理解 UML SD 的 conditional
部分吗?
您的第二张图表正确显示了对 getBrandCustomMessages
的内部调用。
如果你真的想显示 if
然后使用片段 (http://www.uml-diagrams.org/sequence-diagrams-combined-fragment.html)。您可以将片段分成单个分区(if/else 或大小写;任何合适的)。
最后的响应不应发送给实体,而应作为 return 消息(来自内部调用之后)发送给参与者。这可能是您想要展示的内容。