Пример #1
0
 public function upload(ApiClientInterface $client)
 {
     $payload = new FilesUploadPayload();
     if ($this->options->has('file')) {
         $filename = $this->getFileName($this->options->get('file'));
         $type = Utils::parseFileExtension($filename);
         $content = $this->readFile($filename);
     } else {
         $filename = $this->options->get('filename');
         $type = $this->options->get('type', Utils::parseFileExtension($filename));
         if (is_null($filename)) {
             $filename = Utils::rand() . '.' . $type;
         }
         $content = $this->readInput();
     }
     if ($this->options->has('filename')) {
         $filename = $this->options->get('filename');
     }
     if ($this->options->has('title')) {
         $payload->setTitle($this->options->get('title'));
     }
     $payload->setFileType($type);
     $payload->setChannels([$this->options->get('channel')]);
     $payload->setContent($content);
     $payload->setFilename($filename);
     return $this->getResponse($client->send($payload));
 }
Пример #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = AppConfig::factory('.slackpipe');
     $token = Utils::rand(32);
     if ($config->write(['app_key' => $token]) !== false) {
         $output->writeln('Token written to file: ' . $config->filePath());
     } else {
         $output->writeln('Nothing written..');
     }
 }
Пример #3
0
 /**
  * @param      $filename
  * @param      $data
  * @param null $type
  * @param      $cb
  *
  * @return mixed
  */
 protected function createTempUploadFile($filename, $data, $type = null, $cb)
 {
     $filename = !empty($filename) ? '-' . $filename : '';
     $type = !empty($type) ? '.' . $type : '';
     // Assemble temporary file path string
     $fn = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(Utils::rand(3) . time()) . $filename . $type;
     // Open file
     $handle = fopen($fn, "w");
     // Write file
     fwrite($handle, $data);
     fclose($handle);
     // Pass file to callback
     $response = $cb($fn);
     // Remove file
     unlink($fn);
     return $response;
 }