Пример #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)));
 }
Пример #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()));
 }
Пример #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)));
     })));
 }
Пример #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);
 }
Пример #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));
 }
Пример #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']);
 }
Пример #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());
 }
Пример #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()));
 }
Пример #9
0
 protected function parseValues(SetInterface $values)
 {
     return Url::fromString($values->current());
 }
Пример #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))));
 }