示例#1
0
 public function execute(RequestInterface $request) : HttpResource
 {
     $response = $this->transport->fulfill($request);
     $attributes = $this->parser->parse($request, $response, new Map('string', AttributeInterface::class));
     if ($attributes->contains('content_type')) {
         $mediaType = MediaType::fromString((string) $attributes->get('content_type')->content());
     } else {
         $mediaType = new NullMediaType();
     }
     return new HttpResource($request->url(), $mediaType, $attributes, $response->body());
 }
示例#2
0
 public function __construct(string $name, StreamInterface $content)
 {
     parent::__construct(basename($name, '.csv') . '.csv', $content, MediaType::fromString('text/csv'));
 }
示例#3
0
 /**
  * Open the file in the given folder
  *
  * @param string $folder
  * @param string $file
  *
  * @return FileInterface
  */
 private function open(string $folder, string $file) : FileInterface
 {
     $path = $folder . '/' . $file;
     if ($this->files->contains($path)) {
         return $this->files->get($path);
     }
     if (is_dir($path)) {
         $object = new Directory($file, (function ($folder) {
             $handle = opendir($folder);
             while (($name = readdir($handle)) !== false) {
                 (yield $this->open($folder, $name));
             }
             closedir($handle);
         })($path));
     } else {
         $object = new File($file, new LazyStream($path), MediaType::fromString(mime_content_type($path)));
     }
     $this->files = $this->files->put($path, $object);
     return $object;
 }
示例#4
0
 /**
  * @expectedException Innmind\Filesystem\Exception\InvalidMediaTypeStringException
  */
 public function testThrowWhenInvalidMediaTypeString()
 {
     MediaType::fromString('foo');
 }
示例#5
0
 public function testMediaType()
 {
     $f = new File('foo', new StringStream('bar'), $mt = MediaType::fromString('application/json'));
     $this->assertSame($mt, $f->mediaType());
 }