将条件包装到函数中还是根本不在序列图中表示它?

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

关于上面的图我有以下的疑惑,也以上面的代码为例:

任何人都可以帮助完成此图并理解 UML SD 的 conditional 部分吗?

您的第二张图表正确显示了对 getBrandCustomMessages 的内部调用。

如果你真的想显示 if 然后使用片段 (http://www.uml-diagrams.org/sequence-diagrams-combined-fragment.html)。您可以将片段分成单个分区(if/else 或大小写;任何合适的)。

最后的响应不应发送给实体,而应作为 return 消息(来自内部调用之后)发送给参与者。这可能是您想要展示的内容。