导图 1
Service-OA-uml
  Adapter
    ServiceRestfulAdapter.class.php
      extends
        GuzzleAdapter
      implements
        IServiceAdapter
      use
        AsyncFetchAbleRestfulAdapterTrait
        FetchAbleRestfulAdapterTrait
      parameter
        $translator
          private
        $resource
          private
        const SCENARIOS = [
        'SERVICE_LIST'=>[
        'fields'=>[
        'services'=>'title,briefIntroduction,updateTime,status,category,enterprise',
        'categories'=>'name'
'enterprise'=>'name'
        ],
        'include'=>'category, enterprise'
        ],
        'SERVICE_FETCH_ONE'=>[
        'fields'=>[],
        'include'=>'category, enterprise'
        ]
        ];
      method
        public function __construct()
          parent::__construct(
          Core::$container->get('services.backend.url')
          );
          $this->translator = new ServiceRestfulTranslator();
          $this->resource = 'services';
          $this->scenario = array();
        protected function getTranslator() : Translator
          return $this->translator;
        protected function getResource() : string
          return $this->resource;
        public function scenario($scenario) : void
          $this->scenario = isset(self::SCENARIOS[$scenario]) ? self::SCENARIOS[$scenario] : array();
        public function fetchOne($id)
          return $this->fetchOneAction($id, new NullService());
    IServiceAdapter.class.php
      extends
        IFetchAbleAdapter
        IAsyncAdapter
    IUnAuditedServiceAdapter.class.php
      IApplyAbleAdapter
      IFetchAbleAdapter
    UnAuditedServiceRestfulAdapter.class.php
      extends
        GuzzleAdapter
      implements
        IUnAuditedServiceAdapter
      use
        FetchAbleRestfulAdapterTrait
        ApplyAbleRestfulAdapterTrait
      parameter
        $translator
          private
        $resource
          private
        const SCENARIOS = [
        'UNAUDITED_SERVICE_LIST'=>[
        'fields'=>[
        'services'=>'title,briefIntroduction,updateTime,status,category,enterprise, REJECTrEASON',
        'categories'=>'name'
'enterprise'=>'name'
        ],
        'include'=>'category, enterprise'
        ],
        'UNAUDITED_SERVICE_FETCH_ONE'=>[
        'fields'=>[],
        'include'=>'category, enterprise'
        ]
        ];
      method
        public function __construct()
          parent::__construct(
          Core::$container->get('services.backend.url')
          );
          $this->translator = new UnAuditedServiceRestfulTranslator();
          $this->resource = 'unAuditServices';
          $this->scenario = array();
        protected function getTranslator() : Translator
          return $this->translator;
        protected function getResource() : string
          return $this->resource;
        public function scenario($scenario) : void
          $this->scenario = isset(self::SCENARIOS[$scenario]) ? self::SCENARIOS[$scenario] : array();
        public function fetchOne($id)
          return $this->fetchOneAction($id, new NullUnAuditedService());
  Command
    ApproveServiceCommand.class.php
      extends
        ApproveCommand
      implements
        ICommand
    RejectServiceCommand.class.php
      extends
        RejectCommand
      implements
        ICommand
  CommandHandler
    ApproveServiceCommandHandler.class.php
      extends
        ApproveCommandHandler
      implements
        ICommandHandler
        ILogable
      parameter
        $repository
          private
        $approveAble
          protected
      method
        public function __construct()
          $this->repository = new UnAuditedServiceRepository();
          $this->approveAble = new NullUnAuditedService();
        public function __destruct()
          unset($this->repository);
          unset($this->approveAble);
        protected function getRepository() : UnAuditedServiceRepository
          return $this->repository;
        protected function getApproveAble() : IApplyAble
          return $this->approveAble;
        protected function fetchIApplyObject($id) : IApplyAble
          return $this->getRepository()
          ->scenario(UnAuditedServiceRepository::FETCH_ONE_MODEL_UN)->fetchOne($id);
        public function getLog() : Log
          return new Log(
          ILogable::OPERATION['OPERATION_APPROVE'],
          ILogable::CATEGORY['SERVICE'],
          $this->getApproveAble()->getId(),
          $this->getApproveAble()->getTitle()
          );
    ServiceCommandHandlerFactory.class.php
      implements
        ICommandHandlerFactory
      parameter
        const MAPS = array(
        'Service\Command\Service\ApproveServiceCommand'=>
        'Service\CommandHandler\Service\ApproveServiceCommandHandler',
        'Service\Command\Service\RejectServiceCommand'=>
        'Service\CommandHandler\Service\RejectServiceCommandHandler',
        );
      method
        public function getHandler(ICommand $command) : ICommandHandler
          $commandClass = get_class($command);
          $commandHandler = isset(self::MAPS[$commandClass]) ? self::MAPS[$commandClass] : '';
          return class_exists($commandHandler) ? new $commandHandler : new NullCommandHandler();
    RejectServiceCommandHandler.class.php
      extends
        RejectCommandHandler
      implements
        ICommandHandler
        ILogable
      parameter
        $repository
          private
        $rejectAble
          protected
      method
        public function __construct()
          $this->repository = new UnAuditedServiceRepository();
          $this->rejectAble = new NullUnAuditedService();
        public function __destruct()
          unset($this->repository);
          unset($this->rejectAble);
        protected function getRepository() : UnAuditedServiceRepository
          return $this->repository;
        protected function getRejectAble() : IApplyAble
          return $this->rejectAble;
        protected function fetchIApplyObject($id) : IApplyAble
          return $this->getRepository()
          ->scenario(UnAuditedServiceRepository::FETCH_ONE_MODEL_UN)->fetchOne($id);
        public function getLog() : Log
          return new Log(
          ILogable::OPERATION['OPERATION_REJECT'],
          ILogable::CATEGORY['SERVICE'],
          $this->getRejectAble()->getId(),
          $this->getRejectAble()->getTitle()
          );
  Controller
    FetchController.class.php
      extends
        Controller
      implements
        IFetchAbleController
      use
        FetchControllerTrait
      parameter
        $repository
          private
      method
        public function __construct()
          parent::__construct();
          $this->repository = new ServiceRepository();
        public function __destruct()
          parent::__destruct();
          unset($this->repository);
        protected function getRepository() : ServiceRepository
          return $this->repository;
        protected function filterAction()
          $sort = $this->getRequest()->get('sort', array());
          list($size,$page) = $this->getPageAndSize();
          list($filter, $sort) = $this->filterFormatChange($sort);
          $serviceList = array();
          list($count, $serviceList) =
          $this->getRepository()
          ->scenario(ServiceRepository::LIST_MODEL_UN)->search($filter, $sort, $page, $size);
          $this->getResponse()->view(new ServiceListView($serviceList, $count))->render();
          return true;
        protected function filterFormatChange($sort)
          $sort = ['-updateTime'];
          $filter = array();
          return [$filter, $sort];
        protected function fetchOneAction(int $id)
          unset($id);
          Core::setLastError(ROUTE_NOT_EXIST);
          return false;
    UnAuditedFetchController.class.php
      extends
        Controller
      implements
        implements
      use
        FetchControllerTrait
        UnAuditedFetchTrait
      parameter
        const SCENE = array(
        'PENDING' => 1,
        'REJECT' => 2
        );
        $repository
          private
      method
        public function __construct()
          parent::__construct();
          $this->repository = new UnAuditedServiceRepository();
        public function __destruct()
          parent::__destruct();
          unset($this->repository);
        protected function getRepository() : UnAuditedServiceRepository
          return $this->repository;
        protected function filterAction()
          $sort = $this->getRequest()->get('sort', array());
          $scene = $this->getRequest()->get('scene', '');
          $scene = marmot_decode($scene);
          if (!in_array($scene, self::SCENE))
            Core::setLastError(ROUTE_NOT_EXIST);
            return false;
          list($size,$page) = $this->getPageAndSize();
          list($filter, $sort) = $this->filterFormatChange($sort, $scene);
          $unAuditedList = array();
          list($count, $unAuditedList) =
          $this->getRepository()->scenario(UnAuditedServiceRepository::LIST_MODEL_UN)
          ->search($filter, $sort, $page, $size);
          $this->getResponse()->view(new UnAuditedServiceListView($unAuditedList, $count))->render();
          return true;
        protected function filterFormatChange($sort, $scene)
          $sort = ['-updateTime'];
          $filter = array();
          if ($scene == self::SCENE['PENDING'])
            $filter['status'] = IApplyAble::APPLY_STATUS['PENDING'];
          if ($scene == self::SCENE['REJECT'])
            $filter['status'] = IApplyAble::APPLY_STATUS['REJECT'];
          return [$filter, $sort];
        protected function fetchOneAction(int $id)
          unset($id);
          Core::setLastError(ROUTE_NOT_EXIST);
          return false;
    UnAuditedOperationController.class.php
      extends
        Controller
      implements
        IUnAuditedOperatAbleController
      use
        UnAuditedOperatControllerTrait
      parameter
        $commandBus
          private
        $repository
          private
      method
        public function __construct()
          parent::__construct();
          $this->commandBus = new CommandBus(new ServiceCommandHandlerFactory());
          $this->repository = new UnAuditedServiceRepository();
        public function __destruct()
          parent::__destruct();
          unset($this->commandBus);
        protected function getCommandBus() : CommandBus
          return $this->commandBus;
        protected function getRepository() : UnAuditedServiceRepository
          return $this->repository;
        protected function approveAction(int $id)
          return $this->getCommandBus()->send(new ApproveServiceCommand($id));
        protected function rejectAction(int $id)
          $reason = $this->getRequest()->post('reason', '');
          return $this->getCommandBus()->send(new RejectServiceCommand($id, $reason));
        protected function resubmitView(int $id)
          unset($id);
          Core::setLastError(ROUTE_NOT_EXIST);
          return false;
        protected function resubmitAction(int $id)
          unset($id);
          Core::setLastError(ROUTE_NOT_EXIST);
          return false;
  Model
    Service.class.php
      implements
        IObject
      use
        Object
      parameter
        const STATUS = array(
'NULL' => 0, //默认
'ONSALE' => 2, //在售
'OFFSTOCK'=>-2, //下架
);
        $id
          private
        $title
          private
        $number
          private
        $briefIntroduction
          private
        $images
          private
        $content
          private
        $validTill
          private
        $minPrice
          private
        $maxPrice
          private
        $price
          private
        $category
          private
        $enterprise
          private
        $volume
          private
        $attentionDegree
          private
        $reason
          private
      method
        public function __construct(int $id = 0)
          $this->id = !empty($id) ? $id : 0;
          $this->title = '';
          $this->number = 0;
          $this->briefIntroduction = '';
          $this->images = array();
          $this->content = '';
          $this->validTill = '';
          $this->minPrice = 0.00;
          $this->maxPrice = 0.00;
          $this->price = array();
          $this->category = new Category();
          $this->enterprise = new Enterprise();
          $this->volume = 0;
          $this->attentionDegree = 0;
          $this->reason = '';
          $this->statusTime = 0;
          $this->createTime = 0;
          $this->updateTime = 0;
          $this->status = self::STATUS['NULL'];
        public function setStatus(int $status) : void
          $this->status= in_array(
          $status,
          self::STATUS
          ) ? $status : self::STATUS['NULL'];
    NullService.class.php
      extends
        Service
      implements
        INull
      parameter
        private static $instance;
      method
        public static function &getInstance()
          if (!self::$instance instanceof self)
            self::$instance = new self();
          return self::$instance;
    UnAuditedService.class.php
      extends
        Service
      implements
        IApplyAble
      use
        ApplyAbleTrait
      parameter
        $unAuditedServiceRepository
      method
        public function __construct()
          parent::__construct();
          $this->applyStatus = self::APPLY_STATUS['PENDING'];
          $this->applyType = self::APPLY_TYPE['NULL'];
          $this->applyCrew = new Crew();
          $this->unAuditedServiceRepository = new UnAuditedServiceRepository();
        public function __destruct()
          parent::__destruct();
          unset($this->applyStatus);
          unset($this->applyType);
          unset($this->applyCrew);
          unset($this->applyUserGroup);
          unset($this->unAuditedServiceRepository()
        protected function getUnAuditedServiceRepository() : UnAuditedServiceRepository
          return $this->unAuditedServiceRepository;
        protected function getIApplyAbleAdapter() : IApplyAbleAdapter
          return $this->getUnAuditedServiceRepository();
    NullUnAuditedService.class.php
      extends
        UnAuditedService
      implements
        INull
      parameter
        private static $instance;
      method
        public static function &getInstance()
          if (!self::$instance instanceof self)
            self::$instance = new self();
          return self::$instance;
  Repository
    ServiceRepository.class.php
      implements
        IServiceAdapter
      use
        FetchRepositoryTrait
        AsyncRepositoryTrait
      parameter
        $adapter
          private
        const LIST_MODEL_UN = 'SERVICE_LIST';
        const FETCH_ONE_MODEL_UN = 'SERVICE_FETCH_ONE';
      method
        protected function getAdapter()
          return $this->adapter;
        public function scenario($scenario)
          $this->getAdapter()->scenario($scenario);
          return $this;
    UnAuditedServiceRepository.class.php
      implements
        IUnAuditedServiceAdapter
      use
        FetchRepositoryTrait
        ApplyAbleRepositoryTrait
      parameter
        const LIST_MODEL_UN = 'UNAUDITED_SERVICE_LIST';
        const FETCH_ONE_MODEL_UN = 'UNAUDITED_SERVICE_FETCH_ONE';
        $adapter;
          private
      method
        public function __construct()
          $this->adapter = new UnAuditedServiceRestfulAdapter();
        protected function getAdapter()
          return $this->adapter;
        public function scenario($scenario)
          $this->getAdapter()->scenario($scenario);
          return $this;
  Translator
    ServiceRestfulTranslator.class.php
      extends
        Translator
      use
        RestfulTranslatorTrait
      method
        protected function getCategoryRestfulTranslator() : CategoryRestfulTranslator
          return new CategoryRestfulTranslator();
        protected function getEnterpriseRestfulTranslator() : EnterpriseRestfulTranslator
          return new EnterpriseRestfulTranslator();
        public function arrayToObject(array $expression, $service = null)
          return $this->translateToObject($expression, $service);
        protected function translateToObject(array $expression, $service = null)
          if (empty($expression))
            return new NullService();
          if ($service == null)
            $service = new Service();
          $data = $expression['data'];
          $id = $data['id'];
          $service->setId($id);
          $attributes = isset($data['attributes']) ? $data['attributes'] : '';
          if (isset($attributes['title']))
            $service->setTitle($attributes['title']);
          if (isset($attributes['number']))
            $service->setNumber($attributes['number']);
          if (isset($attributes['briefIntroduction']))
            $service->setBriefIntroduction($attributes['briefIntroduction']);
          if (isset($attributes['images']))
            $service->setImages($attributes['images']);
          if (isset($attributes['content']))
            $service->setContent($attributes['content']);
          if (isset($attributes['validTill']))
            $service->setValidTill($attributes['validTill']);
          if (isset($attributes['minPrice']))
            $service->setMinPrice($attributes['minPrice']);
          if (isset($attributes['maxPrice']))
            $service->setMaxPrice($attributes['maxPrice']);
          if (isset($attributes['price']))
            $service->setPrice($attributes['price']);
          if (isset($attributes['volume']))
            $service->setVolume($attributes['volume']);
          if (isset($attributes['attentionDegree']))
            $service->setAttentionDegree($attributes['attentionDegree']);
          if (isset($attributes['rejectReason']))
            $service->setReason($attributes['rejectReason']);
          if (isset($attributes['createTime']))
            $service->setCreateTime($attributes['createTime']);
          if (isset($attributes['updateTime']))
            $service->setUpdateTime($attributes['updateTime']);
          if (isset($attributes['statusTime']))
            $service->setStatusTime($attributes['statusTime']);
          $relationships = isset($data['relationships']) ? $data['relationships'] : array();
          if (isset($expression['included']))
            $relationships = $this->relationship($expression['included'], $relationships);
          if (isset($relationships['category']['data']))
            $category = $this->changeArrayFormat($relationships['category']['data']);
            $service->setCategory($this->getCategoryRestfulTranslator()->arrayToObject($category));
          if (isset($relationships['enterprise']['data']))
            $enterprise = $this->changeArrayFormat($relationships['enterprise']['data']);
            $service->setEnterprise($this->getEnterpriseRestfulTranslator()->arrayToObject($enterprise));
          return $service;
        public function objectToArray($service, array $keys = array())
          if (!$service instanceof Service)
            return array();
          if (empty($keys))
            $keys = array('id', 'title', 'number', 'briefIntroduction', 'images', 'content', 'validTill', 'minPrice', 'maxPrice', 'price', 'volume', 'attentionDegree', 'reason', 'category', 'enterprise')
          $expression = array('data'=>array('type'=>'services'));
          if (in_array('id', $keys))
            $expression['data']['id'] = $service->getId();
          $attributes = array();
          if (in_array('title', $keys))
            $attributes['title'] = $service->getTitle();
          if (in_array('number', $keys))
            $attributes['number'] = $service->getNumber();
          if (in_array('briefIntroduction', $keys))
            $attributes['briefIntroduction'] = $service->getBriefIntroduction();
          if (in_array('images', $keys))
            $attributes['images'] = $service->getImages();
          if (in_array('content', $keys))
            $attributes['content'] = $service->getContent();
          if (in_array('validTill', $keys))
            $attributes['validTill'] = $service->getValidTill();
          if (in_array('minPrice', $keys))
            $attributes['minPrice'] = $service->getMinPrice();
          if (in_array('maxPrice', $keys))
            $attributes['maxPrice'] = $service->getMaxPrice();
          if (in_array('price', $keys))
            $attributes['price'] = $service->getPrice();
          if (in_array('volume', $keys))
            $attributes['volume'] = $service->getVolume();
          if (in_array('attentionDegree', $keys))
            $attributes['attentionDegree'] = $service->getAttentionDegree();
          if (in_array('reason', $keys))
            $attributes['rejectReason'] = $service->getReason();
          $expression['data']['attributes'] = $attributes;
          if (in_array('category', $keys))
            $expression['data']['relationships']['category']['data'] = array(
array(
'type' => 'categories',
'id' => $service->getCategory()->getId()
)
);
          if (in_array('entyerprise', $keys))
            $expression['data']['relationships']['enterprise']['data'] = array(
array(
'type' => 'enterprises',
'id' => $service->getEnterprise()->getId()
)
);
          return $expression;
    ServiceTranslator.class.php
      extends
        Translator
      method
        public function arrayToObject(array $expression, $service = null)
          unset($service);
          unset($expression);
          return new NullService();
        public function arrayToObjects(array $expression) : array
          unset($expression);
          return array();
        protected function getCategoryRestfulTranslator() : CategoryRestfulTranslator
          return new CategoryRestfulTranslator();
        protected function getEnterpriseRestfulTranslator() : EnterpriseRestfulTranslator
          return new EnterpriseRestfulTranslator();
        public function objectToArray($service, array $keys = array())
          if (!$service instanceof Service)
            return array();
          if (empty($keys))
            $keys = array('id', 'title', 'number', 'briefIntroduction', 'images', 'content', 'validTill', 'minPrice', 'maxPrice', 'price', 'volume', 'attentionDegree', 'reason', 'category'=>['id', 'name'], 'enterprise'=>['id', 'name']);
          $expression = array();
          if (in_array('id', $keys))
            $expression['id'] = marmot_encode($service->getId());
          if (in_array('title', $keys))
            $expression['title'] = $service->getTitle();
          if (in_array('number', $keys))
            $expression['number'] = $service->getNumber();
          if (in_array('briefIntroduction', $keys))
            $expression['briefIntroduction'] = $service->getBriefIntroduction();
          if (in_array('images', $keys))
            $expression['images'] = $service->getImages();
          if (in_array('content', $keys))
            $expression['content'] = $service->getContent();
          if (in_array('validTill', $keys))
            $expression['validTill'] = $service->getValidTill();
          if (in_array('minPrice', $keys))
            $expression['minPrice'] = $service->getMinPrice();
          if (in_array('maxPrice', $keys))
            $expression['maxPrice'] = $service->getMaxPrice();
          if (in_array('price', $keys))
            $expression['price'] = $service->getPrice();
          if (in_array('volume', $keys))
            $expression['volume'] = $service->getVolume();
          if (in_array('attentionDegree', $keys))
            $expression['attentionDegree'] = $service->getAttentionDegree();
          if (in_array('reason', $keys))
            $expression['reason'] = $service->getReason();
          if (in_array('createTime', $keys))
            $expression['createTime'] = $service->getCreateTime();
          if (in_array('updateTime', $keys))
            $expression['updateTime'] = $service->getUpdateTime();
          if (in_array('status', $keys))
            $expression['status'] = $service->getStatus();
          if (isset($keys['category']))
            $expression['category'] = $this->getCategoryTranslator()->objectToArray(
$service->getCategory(),
$keys['category']
);
          if (isset($keys['enterprise']))
            $expression['enterprise'] = $this->getEnterpriseTranslator()->objectToArray(
$service->getEnterprise(),
$keys['enterprise']
);
          return $expression;
    UnAuditedServiceRestfulTranslator.class.php
      extends
        ServiceRestfulTranslator
      use
        ApplyRestfulTranslatorTrait
      method
        public function arrayToObject(array $expression, $unAuditedService = null)
        protected function translateToObject(array $expression, $unAuditedService = null)
          if (empty($expression))
            return new NullUnAuditedService();
          if ($unAuditedService == null)
            $unAuditedService = new UnAuditedService();
          $unAuditedService = parent::translateToObject($expression, $unAuditedService);
          $unAuditedService = $this->applyTranslateToObject($expression, $unAuditedService);
          return $unAuditedService;
        public function objectToArray($unAuditedService, array $keys = array())
          if (!$unAuditedService instanceof UnAuditedService)
            return array();
          $service = parent::objectToArray($unAuditedService, $keys);
          $apply = $this->applyObjectToArray($unAuditedService, $keys);
          $expression = array_merge($service, $apply);
          $expression['data']['type'] = 'unAuditServices';
          return $expression;
    UnAuditedServiceTranslator.class.php
      extends
        ServiceTranslator
      use
        ApplyTranslatorTrait
      method
        public function arrayToObject(array $expression, $unAuditedService = null)
          unset($unAuditedService);
          unset($expression);
          return new NullUnAuditedService();
        public function arrayToObjects(array $expression) : array
          unset($expression);
          return array();
        public function objectToArray($unAuditedService, array $keys = array())
          if (!$unAuditedService instanceof UnAuditedService)
            return array();
          $service = parent::objectToArray($unAuditedService, $keys);
          $apply = $this->applyObjectToArray($unAuditedService);
          $unAuditedService = array_merge($service, $apply);
          return $unAuditedService;