Ejemplo n.º 1
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'location') {
         throw new InvalidArgumentException();
     }
     return new Location(new LocationValue(Url::fromString((string) $value)));
 }
Ejemplo n.º 2
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'host') {
         throw new InvalidArgumentException();
     }
     $url = Url::fromString((string) $value);
     return new Host(new HostValue($url->authority()->host(), $url->authority()->port()));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function build(SetInterface $identities, ServerRequestInterface $request, HttpResource $definition, SpecificationInterface $specification = null, Range $range = null) : MapInterface
 {
     $map = new Map('string', HeaderInterface::class);
     if ($identities->size() === 0) {
         return $map;
     }
     $path = $request->url()->path();
     return $map->put('Link', new Link($identities->reduce(new Set(HeaderValueInterface::class), function (Set $carry, IdentityInterface $identity) use($path) : Set {
         return $carry->add(new LinkValue(Url::fromString(rtrim((string) $path, '/') . '/' . $identity), 'resource', new Map('string', ParameterInterface::class)));
     })));
 }
Ejemplo n.º 4
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'link') {
         throw new InvalidArgumentException();
     }
     $links = new Set(HeaderValueInterface::class);
     foreach ($value->split(',') as $link) {
         $matches = $link->trim()->getMatches('~^<(?<url>\\S+)>(?<params>(; ?\\w+=\\"?[\\w\\-.]+\\"?)+)?$~');
         $params = $this->buildParams($matches->hasKey('params') ? $matches->get('params') : new Str(''));
         $links = $links->add(new LinkValue(Url::fromString((string) $matches->get('url')), $params->contains('rel') ? $params->get('rel')->value() : 'related', $params->contains('rel') ? $params->remove('rel') : $params));
     }
     return new Link($links);
 }
Ejemplo n.º 5
0
 public function denormalize($data, $type, $format = null, array $context = []) : IdentityInterface
 {
     if (!$this->supportsDenormalization($data, $type, $format) || !isset($context['definition']) || !$context['definition'] instanceof HttpResource) {
         throw new LogicException();
     }
     $definition = $context['definition'];
     $headers = $data->headers();
     if (!$headers->has('Location') || !$headers->get('Location') instanceof Location) {
         throw new IdentityNotFoundException();
     }
     $header = $headers->get('Location')->values()->current();
     $header = Url::fromString((string) $header);
     return new Identity(call_user_func($this->resolveIdentity, $definition->url(), $header));
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function denormalize($definition, $class, $format = null, array $context = []) : HttpResource
 {
     if (!$this->supportsDenormalization($definition, $class) || !isset($context['name'])) {
         throw new LogicException();
     }
     $properties = new Map('string', Property::class);
     $metas = new Map('scalar', 'variable');
     foreach ($definition['properties'] as $name => $value) {
         $properties = $properties->put($name, $this->buildProperty($name, $value));
     }
     foreach ($definition['metas'] as $key => $value) {
         $metas = $metas->put($key, $value);
     }
     return new HttpResource($context['name'], Url::fromString($definition['url']), new Identity($definition['identity']), $properties, $metas, $definition['rangeable']);
 }
Ejemplo n.º 7
0
 public function make() : ServerRequestInterface
 {
     $protocol = (new Str($_SERVER['SERVER_PROTOCOL']))->getMatches('~HTTP/(?<major>\\d)\\.(?<minor>\\d)~');
     return new ServerRequest(Url::fromString($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), new Method($_SERVER['REQUEST_METHOD']), new ProtocolVersion((int) (string) $protocol['major'], (int) (string) $protocol['minor']), $this->headersFactory->make(), new Stream(fopen('php://input', 'r')), $this->environmentFactory->make(), $this->cookiesFactory->make(), $this->queryFactory->make(), $this->formFactory->make(), $this->filesFactory->make());
 }
Ejemplo n.º 8
0
 public function translate(RequestInterface $request) : Request
 {
     list($major, $minor) = explode('.', $request->getProtocolVersion());
     return new Request(Url::fromString((string) $request->getUri()), new Method(strtoupper($request->getMethod())), new ProtocolVersion((int) $major, (int) $minor), $this->translateHeaders($request->getHeaders()), new StringStream((string) $request->getBody()));
 }
Ejemplo n.º 9
0
 protected function parseValues(SetInterface $values)
 {
     return Url::fromString($values->current());
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function build(IdentityInterface $identity, ServerRequestInterface $request, HttpResource $definition, HttpResourceInterface $resource) : MapInterface
 {
     $map = new Map('string', HeaderInterface::class);
     return $map->put('Location', new Location(new LocationValue(Url::fromString(rtrim((string) $request->url()->path(), '/') . '/' . $identity))));
 }