Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

21
vendor/fig/link-util/phpcs.xml vendored Normal file
View File

@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="PSR-2 coding standard">
<description>PSR-2 coding standards</description>
<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>
<!-- inherit rules from: -->
<rule ref="PSR2"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>

View File

@@ -0,0 +1,40 @@
<?php
namespace Fig\Link;
use Psr\Link\LinkInterface;
use Psr\Link\EvolvableLinkProviderInterface;
/**
* Class EvolvableLinkProviderTrait
*
* @implements EvolvableLinkProviderInterface
*/
trait EvolvableLinkProviderTrait
{
use LinkProviderTrait;
/**
* {@inheritdoc}
*/
public function withLink(LinkInterface $link)
{
$that = clone($this);
$splosh = spl_object_hash($link);
if (!array_key_exists($splosh, $that->links)) {
$that->links[$splosh] = $link;
}
return $that;
}
/**
* {@inheritdoc}
*/
public function withoutLink(LinkInterface $link)
{
$that = clone($this);
$splosh = spl_object_hash($link);
unset($that->links[$splosh]);
return $that;
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Fig\Link;
use Psr\Link\EvolvableLinkInterface;
/**
* Class EvolvableLinkTrait
*
* @implements EvolvableLinkInterface
*/
trait EvolvableLinkTrait
{
use LinkTrait;
/**
* {@inheritdoc}
*
* @return EvolvableLinkInterface
*/
public function withHref($href)
{
/** @var EvolvableLinkInterface $that */
$that = clone($this);
$that->href = $href;
$that->templated = ($this->hrefIsTemplated($href));
return $that;
}
/**
* {@inheritdoc}
*
* @return EvolvableLinkInterface
*/
public function withRel($rel)
{
/** @var EvolvableLinkInterface $that */
$that = clone($this);
$that->rel[$rel] = true;
return $that;
}
/**
* {@inheritdoc}
*
* @return EvolvableLinkInterface
*/
public function withoutRel($rel)
{
/** @var EvolvableLinkInterface $that */
$that = clone($this);
unset($that->rel[$rel]);
return $that;
}
/**
* {@inheritdoc}
*
* @return EvolvableLinkInterface
*/
public function withAttribute($attribute, $value)
{
/** @var EvolvableLinkInterface $that */
$that = clone($this);
$that->attributes[$attribute] = $value;
return $that;
}
/**
* {@inheritdoc}
*
* @return EvolvableLinkInterface
*/
public function withoutAttribute($attribute)
{
/** @var EvolvableLinkInterface $that */
$that = clone($this);
unset($that->attributes[$attribute]);
return $that;
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Fig\Link;
use Psr\Link\EvolvableLinkProviderInterface;
use Psr\Link\LinkInterface;
class GenericLinkProvider implements EvolvableLinkProviderInterface
{
use EvolvableLinkProviderTrait;
/**
* Constructs a new link provider.
*
* @param LinkInterface[] $links
* Optionally, specify an initial set of links for this provider.
* Note that the keys of the array will be ignored.
*/
public function __construct(array $links = [])
{
// This block will throw a type error if any item isn't a LinkInterface, by design.
array_filter($links, function (LinkInterface $item) {
return true;
});
$hashes = array_map('spl_object_hash', $links);
$this->links = array_combine($hashes, $links);
}
}

27
vendor/fig/link-util/src/Link.php vendored Normal file
View File

@@ -0,0 +1,27 @@
<?php
namespace Fig\Link;
use Psr\Link\EvolvableLinkInterface;
class Link implements EvolvableLinkInterface
{
use EvolvableLinkTrait;
/**
* Link constructor.
*
* @param string $rel
* A single relationship to include on this link.
* @param string $href
* An href for this link.
*/
public function __construct($rel = '', $href = '')
{
if ($rel) {
$this->rel[$rel] = true;
}
$this->href = $href;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Fig\Link;
use Psr\Link\LinkProviderInterface;
use Psr\Link\LinkInterface;
/**
* Class LinkProviderTrait
*
* @implements LinkProviderInterface
*/
trait LinkProviderTrait
{
/**
* An array of the links in this provider.
*
* The keys of the array MUST be the spl_object_hash() of the object being stored.
* That helps to ensure uniqueness.
*
* @var LinkInterface[]
*/
private $links = [];
/**
* {@inheritdoc}
*/
public function getLinks()
{
return $this->links;
}
/**
* {@inheritdoc}
*/
public function getLinksByRel($rel)
{
$filter = function (LinkInterface $link) use ($rel) {
return in_array($rel, $link->getRels());
};
return array_filter($this->links, $filter);
}
}

73
vendor/fig/link-util/src/LinkTrait.php vendored Normal file
View File

@@ -0,0 +1,73 @@
<?php
namespace Fig\Link;
use Psr\Link\LinkInterface;
/**
* Class LinkTrait
*
* @inherits LinkInterface
*/
trait LinkTrait
{
use TemplatedHrefTrait;
/**
*
*
* @var string
*/
private $href = '';
/**
* The set of rels on this link.
*
* Note: Because rels are an exclusive set, we use the keys of the array
* to store the rels that have been added, not the values. The values
* are simply boolean true. A rel is present if the key is set, false
* otherwise.
*
* @var string[]
*/
private $rel = [];
/**
*
*
* @var string
*/
private $attributes = [];
/**
* {@inheritdoc}
*/
public function getHref()
{
return $this->href;
}
/**
* {@inheritdoc}
*/
public function isTemplated()
{
return $this->hrefIsTemplated($this->href);
}
/**
* {@inheritdoc}
*/
public function getRels()
{
return array_keys($this->rel);
}
/**
* {@inheritdoc}
*/
public function getAttributes()
{
return $this->attributes;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Fig\Link;
trait TemplatedHrefTrait
{
/**
* Determines if an href is a templated link or not.
*
* @see https://tools.ietf.org/html/rfc6570
*
* @param string $href
* The href value to check.
*
* @return bool
* True if the specified href is a templated path, False otherwise.
*/
private function hrefIsTemplated($href)
{
return strpos($href, '{') !== false ||strpos($href, '}') !== false;
}
}