Пример #1
0
 public function __construct(SetInterface $persisters)
 {
     if ((string) $persisters->type() !== PersisterInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->persisters = $persisters;
 }
 public function __construct(SetInterface $builders)
 {
     if ((string) $builders->type() !== CreateBuilderInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->builders = $builders;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function build(SetInterface $identities, ServerRequestInterface $request, HttpResource $definition, SpecificationInterface $specification = null, Range $range = null) : MapInterface
 {
     if ((string) $identities->type() !== IdentityInterface::class) {
         throw new InvalidArgumentException();
     }
     return $this->builders->reduce(new Map('string', HeaderInterface::class), function (MapInterface $carry, ListBuilderInterface $builder) use($identities, $request, $definition, $specification, $range) : MapInterface {
         return $carry->merge($builder->build($identities, $request, $definition, $specification, $range));
     });
 }
Пример #4
0
 /**
  * Removes from the underlying collection the last
  * element returned by this iterator (optional operation).
  * This method can be called only once per call to next().
  * The behavior of an iterator is unspecified if the underlying
  * collection is modified while the iteration is in progress in any
  * way other than by calling this method.
  * @return boolean
  */
 public function remove()
 {
     if ($this->canRemove) {
         $removed = $this->set->remove($this->array[$this->index--]);
         $this->array = $this->set->toArray();
         $this->canRemove = false;
     } else {
         throw new IllegalStateException();
     }
 }
Пример #5
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)));
     })));
 }
Пример #6
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 (!$definition->isRangeable()) {
         return $map;
     }
     $map = $map->put('Accept-Ranges', new AcceptRanges(new AcceptRangesValue('resources')));
     if (!$range instanceof Range) {
         return $map;
     }
     $length = $range->lastPosition() - $range->firstPosition();
     return $map->put('Content-Range', new ContentRange(new ContentRangeValue('resources', $range->firstPosition(), $last = $range->firstPosition() + $identities->size(), $identities->size() < $length ? $last : $last + $length)));
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function load(SetInterface $files) : MapInterface
 {
     if ((string) $files->type() !== 'string') {
         throw new InvalidArgumentException();
     }
     $config = (new Processor())->processConfiguration(new Configuration(), $files->reduce([], function (array $carry, string $file) {
         $carry[] = Yaml::parse(file_get_contents($file));
         return $carry;
     }));
     $directories = new Map('string', Directory::class);
     foreach ($config as $key => $value) {
         $directories = $directories->put($key, $this->loadDirectory($key, $value));
     }
     return $directories;
 }
Пример #8
0
 /**
  * @param SetInterface<UrlInterface> $urls
  *
  * @return SetInterface<UrlInterface>
  */
 public function __invoke(SetInterface $urls) : SetInterface
 {
     if ((string) $urls->type() !== UrlInterface::class) {
         throw new InvalidArgumentException();
     }
     return $urls->reduce(new Map('string', UrlInterface::class), function (Map $urls, UrlInterface $url) : Map {
         $string = (string) $url;
         if ($urls->contains($string)) {
             return $urls;
         }
         return $urls->put($string, $url);
     })->reduce(new Set(UrlInterface::class), function (Set $urls, string $string, UrlInterface $url) : Set {
         return $urls->add($url);
     });
 }
Пример #9
0
 protected function parseValues(SetInterface $values)
 {
     return $values->reduce(new Set(UrlInterface::class), function (Set $urls, string $url) : Set {
         return $urls->add(Url::fromString($url));
     });
 }