Esempio n. 1
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)));
     })));
 }
Esempio n. 2
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;
 }
Esempio n. 3
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);
     });
 }
Esempio n. 4
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));
     });
 }