/**
  * @param RequestHandlerInterface $handler
  * @param RequestDto $dto
  * @return bool
  */
 public function shouldExecute(RequestHandlerInterface $handler, RequestDto $dto)
 {
     $section = $this->config->getSection('custom');
     if (empty($section)) {
         return true;
     }
     $dtoChannel = $dto->getChannel();
     if (null === $dtoChannel) {
         return true;
     }
     $handlerId = $handler->getId();
     $handlerConfig = $this->config->getEntry('custom.' . $handlerId);
     if (empty($handlerConfig)) {
         return false;
     }
     $dtoChannelType = $dtoChannel[0];
     if ('D' === $dtoChannelType) {
         return Ar::get($handlerConfig, 'dm') ?: true;
     }
     if ('C' === $dtoChannelType) {
         $dtoChannelInfo = $this->slackApi->channelsInfo($dtoChannel);
         $dtoChannelName = '#' . Ar::get($dtoChannelInfo, 'channel.name');
     } else {
         $dtoChannelInfo = $this->slackApi->groupsInfo($dtoChannel);
         $dtoChannelName = Ar::get($dtoChannelInfo, 'group.name');
     }
     $defaultBehavior = $this->config->getEntry('custom.' . $handlerId . '.default');
     $handlerChannels = $this->config->getEntry('custom.' . $handlerId . '.channels');
     if (empty($handlerChannels)) {
         return 'allow' === $defaultBehavior ? true : false;
     }
     $handlerChannelConfig = $this->config->getSectionFromArray('custom.' . $handlerId . '.channels', 'name=' . $dtoChannelName);
     if (empty($handlerChannelConfig)) {
         return 'allow' === $defaultBehavior ? true : false;
     }
     $this->params = Ar::get($handlerChannelConfig, 'params') ?: [];
     return true;
 }
示例#2
0
 /** @test */
 public function shouldReturnEmptyArrayOnNonExistentSection()
 {
     $config = new Config($this->parserMock, $this->loader);
     $config->loadData('tests/data/config-test.yml');
     $this->assertEquals([], $config->getSection('non-existent-section'));
 }