导图 1
News
  Adapter
    Query
      Persistence
        NewsCache
        NewsDb
      NewsRowCacheQuery
    INewsAdapter
      extends
        IOperatAbleAdapter
        IEnableAbleAdapter
        ITopAbleAdapter
      method
        public function fetchOne($id, array $includeList = array()) : News;
        public function fetchList(array $ids, array $includeList = array()) : array;
        public function filter(
array $filter = array(),
array $sort = array(),
int $offset = 0,
int $size = 0
) : array;
    NewsDataBaseAdapter
      implements
        INewsAdapter
      use
        OperatAbleAdapterTrait
        EnableAbleAdapterTrait
        TopAbleAdapterTrait
      parameter
        $translator
        $rowCacheQuery
      method
        protected function getTranslator() : NewsDbTranslator
        protected function getRowCacheQuery() : NewsRowCacheQuery
        public function update(News $news, array $keys=array()) : bool
  Command
    AddNewsCommand
      parameter
        $title
          public
          string
        $source
          public
          string
        $image
          public
          array
        $attachments
          public
          array
        $content
          public
          string
        $category
          public
          int
          0
        $crewId
          public
          int
        $id
          public
          int
          0
    EditNewsCommand
      parameter
        $title
          public
          string
        $source
          public
          string
        $image
          public
          array
        $attachments
          public
          array
        $content
          public
          string
        $id
          public
          int
          0
    EnableNewsCommand
      extends
        EnableCommand
    DisableNewsCommand
      extends
        DisableCommand
    TopNewsCommand
      extends
        TopCommand
    CancelTopNewsCommand
      extends
        CancelTopCommand
  CommandHandler
    AddNewsCommandHandler
      parameter
        $news
          public
        $crewRepository
          public
      method
        protected function getNews() : News
        protected function getCrewRepository() : CrewRepository
        protected function fetcCrew(int $id) : Crew
        public function execute(ICommand $command)
          $news = $this->getNews();
          $crew = $this->fetchCrew($command->crewId);
          $news->setTitle($command->title)
          $news->setSource($command->source)
          $news->setImage($command->image)
          $news->setAttachments($command->attachments)
          $news->setContent($command->content)
          $news->setCategory($command->category)
          $news->setCrew($crew)
          if ($news->add())
            true
              $command->id = $news->getId();
              return true;
            false
              return false
    EditNewsCommandHandler
      parameter
        $newsRepository
          public
      method
        protected function getRepository() : NewsRepository
        protected function fetchNews(int $id) : News
          return $this->getRepository()->fetchOne($id)
        public function execute(ICommand $command)
          $news = $this->fetchNews($command->id)
          $news->setTitle($command->title)
          $news->setSource($command->source)
          $news->setImage($command->image)
          $news->setAttachments($command->attachments)
          $news->setContent($command->content)
          return $news->edit()
    EnableNewsCommandHandler
      extends
        EnableCommandHandler
      parameter
        $repository
          public
      method
        protected function getRepository() : NewsRepository
        protected function fetchIEnableObject($id) : IEnableAble
    DisableNewsCommandHandler
      extends
        DisableCommandHandler
      parameter
        $repository
          public
      method
        protected function getRepository() : NewsRepository
        protected function fetchIEnableObject($id) : IEnableAble
    TopNewsCommandHandler
      extends
        TopCommandHandler
      parameter
        $repository
          public
      method
        protected function getRepository() : NewsRepository
        protected function fetchITopObject($id) : ITopAble
    CancelTopeNewsCommandHandler
      extends
        CancelTopCommandHandler
      parameter
        $repository
          public
      method
        protected function getRepository() : NewsRepository
        protected function fetchITopObject($id) : ITopAble
  Model
    implements
      IObject
      IOperatAble
      IEnableAble
      ITopAble
    use
      Object
      OperatAbleTrait
      EnableAbleTrait
      TopAbleTrait
    parameter
      $id
        private
        int
      $title
        private
        string
        标题
      $source
        private
        string
        新闻来源
      $image
        private
        array
        新闻图片
      $attachments
        private
        array
        新闻附件
      $content
        private
        string
        新闻内容
      $description
        private
        string
        新闻简介
      $category
        private
        int
        新闻分类
      $status
        private
        int
        状态
      $stick
        private
        int
        置顶状态
      $crew
        private
        Crew
        发布人
      $repository
        private
    method
      proteced function getRepository()
      public function addAction() : bool
      public function editAction() : bool
  Controller
    FetchController
      parameter
        $newsRepository
      method
        protected function getNewsRepository() : NewsRepository
        punblic function fetchOne(int $id)
          $category = $this->getRepository()->fetchOne($id)
          if (!$category instanceof INull)
            true
              $this->renderView(new NewsView($category));
              return true;
            false
              $this->displayError();
              return false;
        punblic function fetchList(string $ids)
          $ids = explode(',', $ids);
          $categoryList = $this->getRepository()->fetchList($ids)
          if (!empty($categoryList))
            true
              $this->renderView(new NewsView($categoryList));
              return true;
            false
              $this->displayError();
              return false;
        public function filter()
          list($filter, $sort, $curpage, $perpage) = $this->formatParameters();
          list($categoryList, $count) = $this->getRepository()-->filter(
$filter,
$sort,
($curpage-1)*$perpage,
$perpage
);
          if ($count > 0)
            true
              $view = new NewsView($categoryList);
              $view->pagination(
'news',
$this->getRequest()->get(),
$count,
$perpage,
$curpage
);
              $this->renderView($view);
              return true;
            false
              $this->displayError();
              return false;
    OperationController
      parameter
        $repository
        $commandBus
        $commonInputWidgetRules
        $newsInputWidgetRules
      method
        protected function getCommonInputWidgetRules() : CommonInputWidgetRules
        protected function getRepository() : NewsRepository
        protected function getCommandBus() : CommandBus
        protected function getNewsInputWidgetRules() : NewsInputWidgetRules
        public function add()
          $data = $this->getRequest()->post('data');
          $relationships = $data['relationships'];
          $title = $data['attributes']['title'];
          $source = $data['attributes']['source'];
          $image = $data['attributes']['image'];
          $attachments = $data['attributes']['attachments'];
          $content = $data['attributes']['content'];
          $category = $data['attributes']['category'];
          $crewId = $relationships['crew']['data'][0]['id']
          if ($this->validateAddScenario($title, $source, $image, $attachments, $content,$category)
            true
              $command = new AddNews($title, $source, $image, $attachments, $content, $category, $crewId)
              if($this->getCommandBus()->send($command))
                true
                  $news = $this->getRepository()->fetchOne($command->id)
                  if ($news instanceof News)
                    true
                      $this->getResponse()->setStatusCode(201);
                      $this->render(new NewsView($news));
                      return true;
                    false
                      $this->displayError();
                      return false;
                false
                  $this->displayError();
                  return false;
            false
              $this->displayError();
              return false;
        private function validateAddScenario($title, $source, $image, $attachments, $content,$category) : bool
          return $this->getCommonInputWidgetRules()->title($title)
          && $this->getCommonInputWidgetRules()->source($source)
          && $this->getCommonInputWidgetRules()->image($image)
          && $this->getCommonInputWidgetRules()->attachments($attachments)
          && $this->getCommonInputWidgetRules()->content($content)
          && $this->getNewsInputWidgetRules()->category($category)
        public function edit(int $id)
          $data = $this->getRequest()->patch('data');
          $title = $data['attributes']['title'];
          $source = $data['attributes']['source'];
          $image = $data['attributes']['image'];
          $attachments = $data['attributes']['attachments'];
          $content = $data['attributes']['content'];
          if ($this->validateEditScenario($title, $source, $image, $attachments, $content)
            true
              $command = new EditNews($title, $source, $image, $attachments,$content, $id)
              if($this->getCommandBus()->send($command))
                true
                  $category = $this->getRepository()->fetchOne($command->id)
                  if ($category instanceof News)
                    true
                      $this->getResponse()->setStatusCode(201);
                      $this->render(new NewsView($category));
                      return true;
                    false
                      $this->displayError();
                      return false;
                false
                  $this->displayError();
                  return false;
            false
              $this->displayError();
              return false;
        private function validateEditScenario($title, $source, $image, $attachments, $content) : bool
          return $this->getCommonInputWidgetRules()->title($title)
          && $this->getCommonInputWidgetRules()->source($source)
          && $this->getCommonInputWidgetRules()->image($image)
          && $this->getCommonInputWidgetRules()->attachments($attachments)
          && $this->getCommonInputWidgetRules()->content($content)
    TopController
      parameter
        $repository
        $commandBus
      method
        protected function getRepository() : NewsRepository
        protected function getCommandBus() : CommandBus
        public function top(int $id)
          $command = new TopNewsCommand($id);
          if ($this->getCommandBus()->send($command))
            true
              $news = $this->getRepository()->fetchOne($id)
              if ($news instanceof News)
                true
                  $this->render(new NewsView($news));
                  return true;
                false
                  $this->displayError();
                  return false;
            false
              $this->displayError();
              return false;
        public function cancelTop(int $id)
          $command = new CancelTopNewsCommand($id);
          if ($this->getCommandBus()->send($command))
            true
              $news = $this->getRepository()->fetchOne($id)
              if ($news instanceof News)
                true
                  $this->render(new NewsView($news));
                  return true;
                false
                  $this->displayError();
                  return false;
            false
              $this->displayError();
              return false;
    EnableController
      parameter
        $repository
        $commandBus
      method
        protected function getRepository() : NewsRepository
        protected function getCommandBus() : CommandBus
        public function enable(int $id)
          $command = new EnableNewsCommand($id);
          if ($this->getCommandBus()->send($command))
            true
              $news = $this->getRepository()->fetchOne($id)
              if ($news instanceof News)
                true
                  $this->render(new NewsView($news));
                  return true;
                false
                  $this->displayError();
                  return false;
            false
              $this->displayError();
              return false;
        public function disable(int $id)
          $command = new DisableNewsCommand($id);
          if ($this->getCommandBus()->send($command))
            true
              $news = $this->getRepository()->fetchOne($id)
              if ($news instanceof News)
                true
                  $this->render(new NewsView($news));
                  return true;
                false
                  $this->displayError();
                  return false;
            false
              $this->displayError();
              return false;
  Repository
    NewsRepository
      implements
        INewsAdapter
      use
        OperatAbleRepositoryTrait
        EnableAbleRepositoryTrait
        TopAbleRepositoryTrait
      parameter
        $adapter
      method
        public function setAdapter(INewsAdapter $adapter)
        private function getAdapter() : INewsAdapter
        public function fetchOne($id, array $includeList = array()) : News
        public function getList(array $ids, array $includeList = array()) : array
        public function filter(
array $filter = array(),
array $sort = array(),
int $offset = 0,
int $size = 20
) : array