pax_global_header 0000666 0000000 0000000 00000000064 13576444125 0014525 g ustar 00root root 0000000 0000000 52 comment=47f55860678a9e202206047bc02767556d298106
link-util-1.1.0/ 0000775 0000000 0000000 00000000000 13576444125 0013434 5 ustar 00root root 0000000 0000000 link-util-1.1.0/.editorconfig 0000664 0000000 0000000 00000000417 13576444125 0016113 0 ustar 00root root 0000000 0000000 ; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
link-util-1.1.0/LICENSE.md 0000664 0000000 0000000 00000002151 13576444125 0015037 0 ustar 00root root 0000000 0000000 # The MIT License (MIT)
Copyright (c) 2016 :author_name <:author_email>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
link-util-1.1.0/README.md 0000664 0000000 0000000 00000000465 13576444125 0014720 0 ustar 00root root 0000000 0000000 PSR Http Link Utilities
=======================
This repository includes common utilities to assist with implementing [PSR-13](http://www.php-fig.org/psr/psr-13/).
Note that it is not intended as a complete PSR-13 implementation, only a partial implementation
to make writing other implementations easier.
link-util-1.1.0/composer.json 0000664 0000000 0000000 00000001531 13576444125 0016156 0 ustar 00root root 0000000 0000000 {
"name": "fig/link-util",
"description": "Common utility implementations for HTTP links",
"keywords": ["psr", "psr-13", "http", "http-link", "link", "rest"],
"license": "MIT",
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"require": {
"php": ">=5.5.0",
"psr/link": "~1.0@dev"
},
"require-dev": {
"phpunit/phpunit": "^5.1",
"squizlabs/php_codesniffer": "^2.3.1"
},
"provide": {
"psr/link-implementation": "1.0"
},
"autoload": {
"psr-4": {
"Fig\\Link\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Fig\\Link\\Test\\": "test/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
link-util-1.1.0/phpcs.xml 0000664 0000000 0000000 00000001062 13576444125 0015272 0 ustar 00root root 0000000 0000000
PSR-2 coding standards
src
test
link-util-1.1.0/rebuild-rels.php 0000664 0000000 0000000 00000013132 13576444125 0016536 0 ustar 00root root 0000000 0000000 compile($records(), $out);
}
class Records
{
/**
* Loads the XML object from the remote source.
*
* IANA requires a valid User-Agent string for all requests, and non-curl stream options for PHP seem to all
* fail at sending a User-Agent, even when told to. So we use the ugly way.
*/
protected function getXml(): \SimpleXMLElement
{
$ch = curl_init(REGISTRY_FILE);
curl_setopt($ch, CURLOPT_USERAGENT, 'php-fig/fig-utils');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
return simplexml_load_string($xml);
}
/**
* Fetches the records for the relation registry.
*
* @return iterable<\SimpleXMLElement>
*/
public function __invoke()
{
foreach ($this->getXml()->registry->children() as $element) {
if ($element->getName() == 'record') {
yield $element;
}
}
}
}
/**
* Compiles a list of SimpleXmlElements to a Relations interface.
*/
class RegistryCompiler
{
/**
* Writes a Relations index class based on the provided records.
*
* @param iterable<\SimpleXMLElement> $records
* An iterable of SimpleXml elements from the Link Relations XML file.
* @param $stream
* An open file stream to which to write the generated code.
* @param string $class
* The name of the interface to produce.
* @param string $namespace
* The namespace of the interface to generate.
*/
public function compile(iterable $records, $stream, string $class = 'Relations', string $namespace = 'Fig\\Link') : void
{
fwrite($stream, $this->createPreamble($class, $namespace));
foreach ($records as $record) {
$item = $this->createEntry($record);
fwrite($stream, $item);
}
fwrite($stream, $this->createClosing());
}
/**
* Processes a SimpleXml record into a constant definition.
*
* @param \SimpleXMLElement $record
* The record to process.
* @return string
*/
protected function createEntry(\SimpleXMLElement $record) : string
{
$value = (string)$record->value;
$name = $this->buildName($value);
$description = $this->rewrap((string)$record->description);
$note = $this->rewrap((string)$record->note);
$seeUri = $this->xrefLink($record->spec->xref);
if ($note) {
return <<