示例#1
0
文件: Files.php 项目: innmind/http
 public function __construct(MapInterface $files)
 {
     if ((string) $files->keyType() !== 'string' || (string) $files->valueType() !== FileInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->files = $files;
 }
示例#2
0
 public function __construct(MapInterface $variables)
 {
     if ((string) $variables->keyType() !== 'string' || (string) $variables->valueType() !== 'scalar') {
         throw new InvalidArgumentException();
     }
     $this->variables = $variables;
 }
 public function __construct(MapInterface $verifiers)
 {
     if ((string) $verifiers->keyType() !== 'int' || (string) $verifiers->valueType() !== VerifierInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->verifiers = $verifiers;
 }
示例#4
0
文件: Query.php 项目: innmind/http
 public function __construct(MapInterface $parameters)
 {
     if ((string) $parameters->keyType() !== 'string' || (string) $parameters->valueType() !== ParameterInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->parameters = $parameters;
 }
示例#5
0
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$response->headers()->has('Content-Type') || !$response->headers()->get('Content-Type') instanceof ContentType) {
         return $attributes;
     }
     return $attributes->put(self::key(), new Attribute(self::key(), MediaType::fromString((string) $response->headers()->get('Content-Type')->values()->current()), $this->clock->now()->elapsedSince($start)->milliseconds()));
 }
示例#6
0
 /**
  * @param  RequestInterface $request
  * @param  MapInterface<string, AttributeInterface> $attributes
  * @param  UrlInterface $target
  */
 public function resolve(RequestInterface $request, MapInterface $attributes, UrlInterface $target) : UrlInterface
 {
     $base = $request->url();
     if ($attributes->contains(BaseParser::key())) {
         $base = $attributes->get(BaseParser::key())->content();
     }
     return Url::fromString($this->resolver->resolve((string) $base, (string) $target));
 }
示例#7
0
 public function __construct($identifier, MapInterface $cells)
 {
     if (!is_scalar($identifier) || (string) $cells->keyType() !== 'scalar' || (string) $cells->valueType() !== CellInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->identifier = $identifier;
     $this->cells = $cells;
 }
示例#8
0
 public function __construct(QueryInterface $query, MapInterface $variables)
 {
     if ((string) $variables->keyType() !== 'string' || (string) $variables->valueType() !== EntityInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->query = $query;
     $this->variables = $variables;
 }
示例#9
0
 public function __construct(string $name, MapInterface $properties)
 {
     if (empty($name) || (string) $properties->keyType() !== 'string' || (string) $properties->valueType() !== Property::class) {
         throw new InvalidArgumentException();
     }
     $this->name = $name;
     $this->properties = $properties;
 }
 public function __construct(MapInterface $errors)
 {
     if ((string) $errors->keyType() !== 'string' || (string) $errors->valueType() !== NormalizationException::class) {
         throw new InvalidArgumentException();
     }
     $this->errors = $errors;
     parent::__construct('The input resource is not normalizable');
 }
示例#11
0
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$response->headers()->has('Content-Type') || !($header = $response->headers()->get('Content-Type')) instanceof ContentType || !$header->values()->current()->parameters()->contains('charset')) {
         return $attributes;
     }
     return $attributes->put(self::key(), new Attribute(self::key(), $header->values()->current()->parameters()->get('charset')->value(), $this->clock->now()->elapsedSince($start)->milliseconds()));
 }
示例#12
0
 private function merge(MapInterface $http, MapInterface $html) : MapInterface
 {
     if (!$http->contains(HttpParser::key())) {
         return $html;
     }
     if (!$html->contains(HtmlParser::key())) {
         return $http;
     }
     return $http->put(self::key(), $http->get(HttpParser::key())->merge($html->get(HtmlParser::key())));
 }
示例#13
0
 public function __construct(string $name, MapInterface $attributes)
 {
     if (empty($name) || (string) $attributes->keyType() !== 'string' || (string) $attributes->valueType() !== AttributeInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->name = $name;
     $this->content = $attributes;
     $this->parsingTime = $attributes->reduce(0, function (int $parsingTime, string $name, AttributeInterface $attribute) : int {
         return $parsingTime += $attribute->parsingTime();
     });
 }
示例#14
0
 public function __construct(string $name, UrlInterface $url, Identity $identity, MapInterface $properties, MapInterface $metas, bool $rangeable)
 {
     if (empty($name) || (string) $properties->keyType() !== 'string' || (string) $properties->valueType() !== Property::class || (string) $metas->keyType() !== 'scalar' || (string) $metas->valueType() !== 'variable') {
         throw new InvalidArgumentException();
     }
     $this->name = $name;
     $this->url = $url;
     $this->identity = $identity;
     $this->properties = $properties;
     $this->metas = $metas;
     $this->rangeable = $rangeable;
 }
示例#15
0
 public function __construct(UrlInterface $url, MediaTypeInterface $mediaType, MapInterface $attributes, StreamInterface $content)
 {
     if ((string) $attributes->keyType() !== 'string' || (string) $attributes->valueType() !== AttributeInterface::class) {
         throw new InvalidArgumentException();
     }
     $name = basename((string) $url->path());
     $this->url = $url;
     $this->name = new Name(empty($name) ? 'index' : $name);
     $this->mediaType = $mediaType;
     $this->attributes = $attributes;
     $this->content = $content;
 }
示例#16
0
 public function __construct(ResourceDefinition $definition, MapInterface $properties)
 {
     if ((string) $properties->keyType() !== 'string' || (string) $properties->valueType() !== Property::class) {
         throw new InvalidArgumentException();
     }
     $this->definition = $definition;
     $this->properties = $properties;
     $this->properties->foreach(function (string $name, Property $property) {
         if (!$this->definition->properties()->contains($name)) {
             throw new InvalidArgumentException();
         }
     });
 }
示例#17
0
 private function fill(array $default, MapInterface $cells) : array
 {
     $line = $cells->reduce($default, function (array $carry, $column, CellInterface $cell) : array {
         $class = get_class($cell);
         if ($this->formatters->contains($class)) {
             $carry[$column] = $this->formatters->get($class)->format($cell);
         } else {
             $carry[$column] = (string) $cell;
         }
         return $carry;
     });
     return array_values($line);
 }
示例#18
0
 public function __construct(string $name, Identity $identity, MapInterface $properties, MapInterface $options, MapInterface $metas, Gateway $gateway, bool $rangeable, MapInterface $allowedLinks)
 {
     if ((string) $properties->keyType() !== 'string' || (string) $properties->valueType() !== Property::class || (string) $options->keyType() !== 'scalar' || (string) $options->valueType() !== 'variable' || (string) $metas->keyType() !== 'scalar' || (string) $metas->valueType() !== 'variable' || (string) $allowedLinks->keyType() !== 'string' || (string) $allowedLinks->valueType() !== 'string') {
         throw new InvalidArgumentException();
     }
     $this->name = $name;
     $this->identity = $identity;
     $this->properties = $properties;
     $this->options = $options;
     $this->metas = $metas;
     $this->gateway = $gateway;
     $this->rangeable = $rangeable;
     $this->allowedLinks = $allowedLinks;
 }
示例#19
0
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$response->headers()->has('Link') || !$response->headers()->get('Link') instanceof Link) {
         return $attributes;
     }
     $links = $response->headers()->get('Link')->values()->filter(function (LinkValue $value) : bool {
         return $value->relationship() === 'canonical';
     });
     if ($links->size() !== 1) {
         return $attributes;
     }
     return $attributes->put(self::key(), new Attribute(self::key(), $this->resolver->resolve($request, $attributes, $links->current()->url()), $this->clock->now()->elapsedSince($start)->milliseconds()));
 }
示例#20
0
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$response->headers()->has('Cache-Control')) {
         return $attributes;
     }
     $directives = $response->headers()->get('Cache-Control')->values()->filter(function (HeaderValueInterface $value) : bool {
         return $value instanceof SharedMaxAge;
     });
     if ($directives->size() !== 1) {
         return $attributes;
     }
     return $attributes->put(self::key(), new Attribute(self::key(), $this->clock->now()->goForward(new Second($directives->current()->age())), $this->clock->now()->elapsedSince($start)->milliseconds()));
 }
示例#21
0
 private function isImage(MapInterface $attributes) : bool
 {
     return $attributes->contains(ContentTypeParser::key()) && (new Image())->isSatisfiedBy($attributes->get(ContentTypeParser::key())->content());
 }