导图 1
ServiceCategory-OA-uml
  Adapter
    ServiceCategoryRestfulAdapter.class.php
      extends
        GuzzleAdapter
      implements
        IServiceCategoryAdapter
      use
        AsyncFetchAbleRestfulAdapterTrait
        FetchAbleRestfulAdapterTrait
      parameter
        $translator
          private
        $resource
          private
        const SCENARIOS = [
        'CREDIT_SERVICE_AGENCY_LIST'=>[
        'fields'=>[]
        ],
        'CREDIT_SERVICE_AGENCY_FETCH_ONE'=>[
        'fields'=>['']
        ],
        ];
      method
        public function __construct()
          parent::__construct(
          Core::$container->get('services.backend.url')
          );
          $this->translator = new ServiceCategoryRestfulTranslator();
          $this->resource = 'serviceCategories';
          $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 NullServiceCategory());
        public function add(ServiceCategory $serviceCategory) : bool
          $data = $this->getTranslator()->objectToArray(
$serviceCategory,
array('name', 'parentId')
);
          $this->post(
$this->getResource(),
$data
);
          if ($this->isSuccess())
            $this->translateToObject($creditServiceAgency);
            return true;
          return false;
        public function edit(ServiceCategory $serviceCategory) : bool
          $data = $this->getTranslator()->objectToArray(
$serviceCategory,
array('name', 'parentId')
);
          $this->patch(
$this->getResource().'/'.$serviceCategory->getId(),
$data
);
          if ($this->isSuccess())
            $this->translateToObject($serviceCategory);
            return true;
          return false;
    IServiceCategoryAdapter.class.php
      extends
        IFetchAbleAdapter
        IAsyncAdapter
  Command
    AddServiceCategoryCommand.class.php
      extends
        OperationCommand
    EditServiceCategoryCommand.class.php
      extends
        OperationCommand
    OperationCommand.class.php
      implements
        ICommand
      parameter
        $name
          public
        $parentId
          public
        $id
          public
      method
        public function __construct(
string $name,
int $parentId = 0,
int $id = 0
)
          $this->name = $name;
          $this->parentId = $parentId;
          $this->id = $id;
  CommandHandler
    AddServiceCategoryCommandHandler.class.php
      implements
        ICommandHandler
        ILogable
      parameter
        $serviceCategory
          private
      method
        public function __construct()
          $this->serviceCategory = new ServiceCategory();
        public function __destruct()
          unset($this->serviceCategory);
        protected function getServiceCategory() : ServiceCategory
          return $this->serviceCategory;
        public function execute(ICommand $command)
          return $this->executeAction($command);
        protected function executeAction($command)
          if (!($command instanceof AddServiceCategoryCommand))
            throw new \InvalidArgumentException;
          $serviceCategory = $this->getServiceCategory();
          $serviceCategory->setName($command->name);
          $serviceCategory->setParentId($command->parentId);
          return $serviceCategory->add();
        public function getLog() : Log
          return new Log(
          ILogable::OPERATION['OPERATION_ADD'],
          ILogable::CATEGORY['SERVICE_CATEGORY'],
          $this->getServiceCategory()->getId(),
          $this->getServiceCategory()->getName()
          );
    EditServiceCategoryCommandHandler.class.php
      implements
        ICommandHandler
        ILogable
      parameter
        $repository
          private
        $serviceCategory
          private
      method
        public function __construct()
          $this->repository = new ServiceCategoryRepository();
          $this->serviceCategory = new NullServiceCategory();
        public function __destruct()
          unset($this->repository);
          unset($this->serviceCategory);
        protected function getRepository() : ServiceCategoryRepository
          return $this->repository;
        protected function getServiceCategory() : ServiceCategory
          return $this->serviceCategory;
        protected function fetchServiceCategory($id) : ServiceCategory
          return $this->getRepository()->fetchOne($id);
        public function execute(ICommand $command)
          return $this->executeAction($command);
        protected function executeAction($command)
          if (!($command instanceof EditServiceCategoryCommand))
            throw new \InvalidArgumentException;
          $this->serviceCategory = $this->fetchServiceCategory($command->id);
          $serviceCategory->setName($command->name);
          $serviceCategory->setParentId($command->parentId);
          return $serviceCategory->edit();
        public function getLog() : Log
          return new Log(
          ILogable::OPERATION['OPERATION_EDIT'],
          ILogable::CATEGORY['SERVICE_CATEGORY'],
          $this->getServiceCategory()->getId(),
          $this->getServiceCategory()->getName()
          );
    ServiceCategoryCommandHandler.class.php
      implements
        ICommandHandlerFactory
      parameter
        const MAPS = array(
        'ServiceCategory\Command\ServiceCategory\AddServiceCategoryCommand'=>
        'ServiceCategory\CommandHandler\ServiceCategory\AddServiceCategoryCommandHandler',
        'ServiceCategory\Command\ServiceCategory\EditServiceCategoryCommand'=>
        'ServiceCategory\CommandHandler\ServiceCategory\EditServiceCategoryCommandHandler'
        );
      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();
  Controller
    ServiceCategoryControllerTrait.class.php
      parameter
        $repository
          private
        $isInitialization = false
          private
      method
        private function initialization()
          $this->isInitialization = true;
          $this->repository = new ServiceCategoryRepository();
        private function judgeInitialization()
          if (!$this->isInitialization)
            $this->initialization();
        public function serviceCategoryList()
          $this->judgeInitialization();
          list($filter, $sort) = $this->serviceCategoryFilterFormatChange();
          list($count, $serviceCategoryList) = $this->repository
          ->scenario(ServiceCategoryRepository::SERVICE_CATEGORY_LIST)
          ->search($filter, $sort, DEFAULT_PAGE, MAX_SIZE);
          unset($count);
          return $serviceCategoryList;
        protected function serviceCategoryFilterFormatChange()
          $sort = ['-id'];
          $filter = [];
          return [$filter, $sort];
    FetchController.class.php
      extends
        Controller
      implements
        IFetchAbleController
      use
        FetchControllerTrait
      parameter
        $repository
        $serviceCategory
      method
        public function __construct()
          parent::__construct();
          $this->repository = new ServiceCategoryRepository();
          $this->serviceCategory = new ServiceCategory();
        public function __destruct()
          parent::__destruct();
          unset($this->repository);
          unset($this->serviceCategory);
        protected function getRepository() : ServiceCategoryRepository
          return $this->repository;
        protected function getServiceCategory() : ServiceCategory
          return $this->serviceCategory;
        protected function filterAction()
          $sort = $this->getRequest()->get('sort', array());
          $search = $this->getRequest()->get('search', array());
          list($size, $page) = $this->getPageAndSize();
          list($filter, $sort) = $this->filterFormatChange($sort, $search);
          $serviceCategoryList = array();
          list($count, $serviceCategoryList) =
          $this->getRepository()
          ->scenario(ServiceCategoryRepository::LIST_MODEL_UN)
          ->search($filter, $sort, $page, $size);
          $this->getResponse()->view(new ServiceCategoryListView($serviceCategoryList, $count))->render();
          return true;
        protected function filterFormatChange($sort, $search)
          $sort = ['-updateTime'];
          $filter = array();
          if (!empty($search[0]))
            $filter['name'] = $search[0];
          return [$filter, $sort];
        protected function fetchOneAction(int $id)
          if (empty($id))
            Core::setLastError(RESOURCE_NOT_EXIST);
            return false;
          $serviceCategory = $this->getRepository()
          ->scenario(ServiceCategoryRepository::FETCH_ONE_MODEL_UN)
          ->fetchOne($id);
          if ($serviceCategory instanceof INull)
            Core::setLastError(RESOURCE_NOT_EXIST);
            return false;
          $this->getResponse()->view(new ServiceCategoryView($serviceCategory))->render();
          return true;
    OperationController.class.php
      extends
        Controller
      implements
        IOperatAbleController
      use
        OperatControllerTrait
      parameter
        $commandBus
          private
        $serviceCategoryInputWidgetRules
          private
        $repository
          private
      method
        public function __construct()
          parent::__construct();
          $this->commandBus = new CommandBus(new ServiceCategoryCommandHandlerFactory());
          $this->serviceCategoryInputWidgetRules = new ServiceCategoryInputWidgetRules();
          $this->repository = new ServiceCategoryRepository();
        protected function getCommandBus() : CommandBus
          return $this->commandBus;
        protected function getServiceCategoryInputWidgetRules() : ServiceCategoryInputWidgetRules
          return $this->serviceCategoryInputWidgetRules;
        protected function getRepository() : ServiceCategoryRepository
          return $this->repository;
        protected function addView() : bool
          Core::setLastError(ROUTE_NOT_EXIST);
          $this->displayError();
          return false;
        protected function addAction()
          $request = $this->getRequest();
          $name = $request->post('name', '');
          $parentId = $request->post('parentId', 0);
          if ($this->validateScenario($name))
            $command = new AddServiceCategoryCommand($name, $parentId)
            if ($this->getCommandBus()->send($command))
              $this->displaySuccess();
              return true;
          $this->displayError();
          return false;
        protected function validateScenario($name) : bool
          return $this->getServiceCategoryInputWidgetRules()->name($name);
        protected function editView(int $id) : bool
          $serviceCategory = $this->getRepository()
          ->scenario(ServiceCategoryRepository::FETCH_ONE_MODEL_UN)
          ->fetchOne($id);
          if ($serviceCategory instanceof INull)
            Core::setLastError(RESOURCE_NOT_EXIST);
            return false;
          $this->getResponse()->view(new ServiceCategoryView($serviceCategory))->render();
          return true;
        protected function editAction(int $id)
          $request = $this->getRequest();
          $name = $request->post('name', '');
          $parentId = $request->post('parentId', 0);
          if ($this->validateScenario($name))
            $command = new EditServiceCategoryCommand($name, $parentId)
            if ($this->getCommandBus()->send($command))
              $this->displaySuccess();
              return true;
          $this->displayError();
          return false;
  Model
    ServiceCategory.class.php
      implements
        IOperatAble
        IObject
      use
        OperatAbleTrait
        Object
      parameter
        const STATUS_NORMAL = 0;
        const STATUS_DELETE = -2;
        $id
        $name
        $parentId
        $repository
      method
        public function __construct(int $id = 0)
          $this->id = !empty($id) ? $id : 0;
          $this->name = '';
          $this->parentId = !empty($parentId) ? $id : 0;
          $this->statusTime = 0;
          $this->createTime = 0;
          $this->updateTime = 0;
          $this->status = self::STATUS_NORMAL;
          $this->repository = new ServiceCategoryRepository();
        public function __destruct()
          unset($this->id);
          unset($this->name);
          unset($this->parentId);
          unset($this->statusTime);
          unset($this->createTime);
          unset($this->updateTime);
          unset($this->status);
          unset($this->repository);
        protected function getRepository() : ServiceCategoryRepository
          return $this->repository;
        protected function getIOperatAbleRepository() : ServiceCategoryRepository
          return $this->getRepository();
    NullServiceCategory.class.php
      extends
        ServiceCategory
      implements
        INull
      parameter
        private static $instance;
      method
        public static function &getInstance()
          if (!self::$instance instanceof self)
            self::$instance = new self();
          return self::$instance;
        public function add() : bool
          return $this->resourceNotExist();
        public function edit() : bool
          return $this->resourceNotExist();
        private function resourceNotExist() : bool
          Core::setLastError(RESOURCE_NOT_EXIST);
          return false;
  Repository
    ServiceCategoryRepository.class.php
      implements
        IServiceCategoryAdapter
      use
        FetchRepositoryTrait
        AsyncRepositoryTrait
      parameter
        $adapter
        const LIST_MODEL_UN = 'SERVICE_CATEGORY_LIST';
        const FETCH_ONE_MODEL_UN = 'SERVICE_CATEGORY_FETCH_ONE';
      method
        public function __construct()
          $this->adapter = new ServiceCategoryRestfulAdapter();
        protected function getAdapter()
          return $this->adapter;
        public function scenario($scenario)
          $this->getAdapter()->scenario($scenario);
          return $this;
        public function add(ServiceCategory $serviceCategory) : bool
          return $this->getAdapter()->add($serviceCategory);
        public function edit(ServiceCategory $serviceCategory) : bool
          return $this->getAdapter()->edit($serviceCategory);
  Translator
    ServiceCategoryRestfulTranslator.class.php
      extends
        Translator
      use
        RestfulTranslatorTrait
      method
        public function arrayToObject(array $expression, $serviceCategory = null)
          if (empty($expression))
            return new NullServiceCategory();
          if ($serviceCategory == null)
            $serviceCategory = new ServiceCategory();
          $data = $expression['data'];
          $id = $data['id'];
          $serviceCategory->setId($id);
          $attributes = isset($data['attributes']) ? $data['attributes'] : '';
          if (isset($attributes['name']))
            $serviceCategory->setName($attributes['name']);
          if (isset($attributes['parentId']))
            $serviceCategory->setParentId($attributes['parentId']);
          if (isset($attributes['createTime']))
            $serviceCategory->setCreateTime($attributes['createTime']);
          if (isset($attributes['updateTime']))
            $serviceCategory->setUpdateTime($attributes['updateTime']);
          if (isset($attributes['status']))
            $serviceCategory->setStatus($attributes['status']);
          if (isset($attributes['statusTime']))
            $serviceCategory->setStatusTime($attributes['statusTime']);
          return $serviceCategory;
        public function objectToArray($serviceCategory, array $keys = array())
          if (!$serviceCategory instanceof ServiceCategory)
            return array();
          if (empty($keys))
            $keys = array('id', 'name', 'parentId');
          $expression = array('data'=>array('type'=>'serviceCategories'));
          if (in_array('id', $keys))
            $expression['data']['id'] = $serviceCategory->getId();
          $attributes = array();
          if (in_array('name', $keys))
            $attributes['name'] = $serviceCategory->getName();
          if (in_array('parentId', $keys))
            $attributes['parentId'] = $serviceCategory->getParentId();
          $expression['data']['attributes'] = $attributes;
          return $expression;
    ServiceCategoryTranslator.class.php
      extends
        Translator
      method
        public function arrayToObject(array $expression, $serviceCategory = null)
          unset($serviceCategory);
          unset($expression);
          return new NullServiceCategory();
        public function arrayToObjects(array $expression) : array
          unset($expression);
          return array();
        public function objectToArray($serviceCategory, array $keys = array())
          if (!$serviceCategory instanceof ServiceCategory)
            return array();
          if (empty($keys))
            $keys = array('id', 'name', 'parentId', 'createTime', 'updateTime', 'status');
          $expression = array();
          if (in_array('id', $keys))
            $expression['id'] = marmot_encode($serviceCategory->getId());
          if (in_array('name', $keys))
            $expression['name'] = $serviceCategory->getName();
          if (in_array('parentId', $keys))
            $expression['parentId'] = $serviceCategory->getParentId();
          if (in_array('status', $keys))
            $expression['status'] = $serviceCategory->getStatus();
          if (in_array('createTime', $keys))
            $expression['createTime'] = $serviceCategory->getCreateTime();
          if (in_array('updateTime', $keys))
            $expression['updateTime'] = $serviceCategory->getUpdateTime();
          return $expression;