Exemplo n.º 1
0
 public function testGetsContents()
 {
     $handle = fopen('php://temp', 'w+');
     fwrite($handle, 'data');
     $stream = new Stream($handle);
     $this->assertEquals('', $stream->getContents());
     $stream->seek(0);
     $this->assertEquals('data', $stream->getContents());
     $this->assertEquals('', $stream->getContents());
 }
Exemplo n.º 2
0
 protected static function extractOriginalExceptionMessage(ClientException $exception)
 {
     self::$response = $exception->getResponse();
     self::$stream = self::$response->getBody();
     self::$content = self::$stream->getContents();
     if (!self::$content) {
         throw new InstagramServerException($exception->getMessage(), $exception->getCode(), $exception);
     }
     return json_decode(self::$content);
 }
Exemplo n.º 3
0
 /**
  * Return the contents of the file
  *
  * @return string
  */
 public function getContents()
 {
     // If an offset is provided
     if ($this->offset !== -1) {
         // Seek to the offset
         $this->stream->seek($this->offset);
     }
     // If a max length is provided
     if ($this->maxLength !== -1) {
         // Read from the offset till the maxLength
         return $this->stream->read($this->maxLength);
     }
     return $this->stream->getContents();
 }
Exemplo n.º 4
0
 /**
  * Get a File's Content.
  *
  * @param mixed $file File Location or Resource
  *
  * @return string File Contents
  */
 protected function getFileContents($file)
 {
     if (!is_resource($file)) {
         $file = fopen($file, 'r');
     }
     $stream = new Stream($file);
     $output = $stream->getContents();
     $stream->close();
     return $output;
 }
Exemplo n.º 5
0
 /**
  * Scopes: role_owner, role_admin
  *
  * @param string|resource $file
  * @return \Aikidesk\SDK\Instance\Contracts\ResponseInterface
  * @throws \Aikidesk\SDK\Instance\Exceptions\SDKValidationException
  */
 public function logo($file)
 {
     $input = [];
     if (is_string($file)) {
         $resource = fopen($file, 'r');
         $psr7Stream = new Stream($resource);
     } elseif (is_resource($file) and (get_resource_type($file) == 'file' or get_resource_type($file) == 'stream')) {
         $resource = $file;
         $psr7Stream = new Stream($resource);
     } else {
         throw new SDKValidationException('Logo is not file path nor file resource');
     }
     $fileContent = $psr7Stream->getContents();
     $fileType = pathinfo($psr7Stream->getMetadata('uri'), PATHINFO_EXTENSION);
     $fileName = pathinfo($psr7Stream->getMetadata('uri'), PATHINFO_FILENAME);
     $input['logo_img_s3key'] = 'data:image/' . $fileType . ';base64,' . base64_encode($fileContent) . ',' . $fileName;
     return $this->request->post('setting/theme', $input);
 }