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()); }
public function __construct(string $name, StreamInterface $content) { parent::__construct(basename($name, '.csv') . '.csv', $content, MediaType::fromString('text/csv')); }
/** * 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; }
/** * @expectedException Innmind\Filesystem\Exception\InvalidMediaTypeStringException */ public function testThrowWhenInvalidMediaTypeString() { MediaType::fromString('foo'); }
public function testMediaType() { $f = new File('foo', new StringStream('bar'), $mt = MediaType::fromString('application/json')); $this->assertSame($mt, $f->mediaType()); }