コード例 #1
0
ファイル: Config.php プロジェクト: humweb/slackpipe
 public static function factory($filename, $eager = false)
 {
     if ($config = Asserts::hasCustomConfig($filename)) {
         return new $config($filename, $eager);
     }
     return new static($filename, $eager);
 }
コード例 #2
0
ファイル: Provider.php プロジェクト: humweb/slackpipe
 public function post()
 {
     $content = $this->readInput();
     $client = new ApiClient($this->token);
     $payload = new ChatPostMessagePayload();
     $payload->setChannel($this->options->get('channel', '#general'));
     $payload->setUsername($this->options->get('user', 'SlackPipe Bot'));
     if (!Asserts::isEmbedUrl($content) && !Asserts::isImage($content)) {
         $payload->setText("```" . PHP_EOL . $content . '```');
     } else {
         $payload->setUnfurlLinks(true);
         $payload->setText($content);
     }
     return $this->getResponse($client->send($payload));
 }
コード例 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $provider = $input->getArgument('provider');
     $baseDir = $_SERVER['HOME'] . DIRECTORY_SEPARATOR . '.slackpipe';
     /** @var ConfigInterface $config */
     $config = Config::factory($provider);
     // Custom Handler
     if ($class = Asserts::hasCustomSetup($provider)) {
         $command = new $class($this, $config);
         if (method_exists($command, 'remove')) {
             $command->remove($input, $output);
         }
     } else {
         $configPath = $config->filePath();
         if ($config->exists()) {
             unlink($configPath);
             $output->writeln('Config removed: ' . $configPath);
         } else {
             $output->writeln('Config not found.');
         }
     }
 }
コード例 #4
0
ファイル: ConfigSetCommand.php プロジェクト: humweb/slackpipe
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $provider = $input->getArgument('provider');
     $baseDir = $_SERVER['HOME'] . DIRECTORY_SEPARATOR . '.slackpipe';
     if (!is_dir($_SERVER['HOME'] . DIRECTORY_SEPARATOR . '.slackpipe')) {
         mkdir($baseDir);
     }
     $config = Config::factory($provider);
     // Custom Handler
     if ($class = Asserts::hasCustomSetup($provider)) {
         $command = new $class($this, $config);
         $command->handle($input, $output);
     } else {
         $helper = $this->getHelper('question');
         $question = new Question('Please enter your token: ', false);
         $token = $helper->ask($input, $output, $question);
         if ($config->write(['token' => $token]) !== false) {
             $output->writeln('Token written to file: ' . $config->filePath());
         } else {
             $output->writeln('Nothing written..');
         }
     }
 }