Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Store IANA's RNG files in the repository (#24)
Browse files Browse the repository at this point in the history
* rename function

* update readme

* rename function (#11) (#15)

* rename function

* update readme

* fixes #14 | added missing MisdirectedRequestException for error code 421 (#17)

* fixes #14, fixes #13  and added missing MisdirectedRequestException for error code 421

* Issue 16 (#20)

fixes #16

* Store IANA's RNG files in the repository

* Updated readme style | added CODE_OF_CONDUCT.md
  • Loading branch information
prisis authored Apr 14, 2017
1 parent 0d519a2 commit 8174673
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 34 deletions.
74 changes: 74 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [[email protected]](mailto:[email protected]). All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# http-status

[![Author](http://img.shields.io/badge/[email protected]?style=flat-square)](https://twitter.com/anolilab)
[![Total Downloads](https://img.shields.io/packagist/dt/narrowspark/http-status.svg?style=flat-square)](https://packagist.org/packages/narrowspark/http-status)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)

## Master

[![Build Status](https://img.shields.io/travis/narrowspark/http-status/master.svg?style=flat-square)](https://travis-ci.org/narrowspark/http-status)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/narrowspark/http-status.svg?style=flat-square)](https://scrutinizer-ci.com/g/narrowspark/http-status/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/narrowspark/http-status.svg?style=flat-square)](https://scrutinizer-ci.com/g/narrowspark/http-status)

## Install
<h2 align="center">Http Status</h2>
<h3 align="center">A package for working with HTTP statuses.</h3>
<p align="center">
<a href="https://github.com/narrowspark/http-status/releases"><img src="https://img.shields.io/packagist/v/narrowspark/http-status.svg?style=flat-square"></a>
<a href="https://php.net/"><img src="https://img.shields.io/badge/php-%5E7.0.0-8892BF.svg?style=flat-square"></a>
<a href="https://travis-ci.org/narrowspark/http-status"><img src="https://img.shields.io/travis/narrowspark/http-status/master.svg?style=flat-square"></a>
<a href="https://scrutinizer-ci.com/g/narrowspark/http-status/code-structure"><img src="https://img.shields.io/scrutinizer/coverage/g/narrowspark/http-status.svg?style=flat-square"></a>
<a href="https://scrutinizer-ci.com/g/narrowspark/http-status"><img src="https://img.shields.io/scrutinizer/g/narrowspark/http-status.svg?style=flat-square"></a>
<a href="https://packagist.org/packages/narrowspark/http-status"><img src="https://img.shields.io/packagist/dt/narrowspark/http-status.svg?style=flat-square"></a>
<a href="http://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>
</p>

Installation
------------

Via Composer

``` bash
```bash
$ composer require narrowspark/http-status
```

## Usage
Use
------------

``` php
use Narrowspark\HttpStatus\HttpStatus;
Expand Down Expand Up @@ -132,24 +134,27 @@ Code | Message | RFC
511 | Network Authentication Required | [RFC6585]
512-599 | *Unassigned* |

## Change log
Change log
------------

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Testing
Testing
------------

``` bash
$ vendor/bin/phpunit
```

## Contributing
Contributing
------------

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
If you would like to help take a look at the [list of issues](http://github.com/narrowspark/http-emitter/issues) and check our [Contributing](CONTRIBUTING.md) guild.

## Credits
> **Note:** Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
- [All Contributors](../../contributors)

## License
License
---------------

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
The Narrowspark http-emitter is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</php>

<testsuites>
<testsuite name="Narrowspark CS Config Test Suite">
<testsuite name="Narrowspark Http Status Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
Expand Down
39 changes: 29 additions & 10 deletions tests/HttpStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,34 +327,53 @@ public function testGetReasonExceptionAgainstIana($code, $reasonPhrase)
}
}

/**
* @link http://github.com/zendframework/zend-diactoros for the canonical source repository
*
* @author Fábio Pacheco
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/
public function ianaCodesReasonPhrasesProvider(): array
{
if (! in_array('https', stream_get_wrappers(), true)) {
$this->markTestSkipped('The "https" wrapper is not available');
}

$ianaHttpStatusCodes = new DOMDocument();
$ianaHttpStatusCodes->loadXML(file_get_contents('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml'));

$ianaCodesReasonPhrases = [];
libxml_set_streams_context(stream_context_create([
'http' => [
'method' => 'GET',
'timeout' => 30,
],
]));

$xpath = new DomXPath($ianaHttpStatusCodes);
$xpath->registerNamespace('ns', 'http://www.iana.org/assignments');
$ianaHttpStatusCodes->load('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml');

if (! $ianaHttpStatusCodes->relaxNGValidate(__DIR__ . '/schema/http-status-codes.rng')) {
self::fail('Invalid IANA\'s HTTP status code list.');
}

$ianaCodesReasonPhrases = [];
$xpath = new DomXPath($ianaHttpStatusCodes);
$xpath->registerNamespace('ns', 'http://www.iana.org/assignments');
$records = $xpath->query('//ns:record');

foreach ($records as $record) {
$value = $xpath->query('.//ns:value', $record)->item(0)->nodeValue;
$description = $xpath->query('.//ns:description', $record)->item(0)->nodeValue;

if ($description === 'Unassigned' | $description === '(Unused)') {
if (in_array($description, ['Unassigned', '(Unused)'], true)) {
continue;
}

$range = preg_match('/^([0-9]+)\s*\-\s*([0-9]+)$/', $value, $matches);

if (! $range) {
$ianaCodesReasonPhrases[] = [$value, $description];
} else {
if (preg_match('/^([0-9]+)\s*\-\s*([0-9]+)$/', $value, $matches)) {
for ($value = $matches[1]; $value <= $matches[2]; ++$value) {
$ianaCodesReasonPhrases[] = [$value, $description];
}
} else {
$ianaCodesReasonPhrases[] = [$value, $description];
}
}

Expand Down
31 changes: 31 additions & 0 deletions tests/schema/http-status-codes.rng
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version='1.0'?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
ns="http://www.iana.org/assignments">

<include href="iana-registry.rng"/>

<start>
<element name="registry">
<ref name="registryMeta"/>
<element name="registry">
<ref name="registryMeta"/>
<zeroOrMore>
<element name="record">
<optional>
<attribute name="date"><ref name="genericDate"/></attribute>
</optional>
<optional>
<attribute name="updated"><ref name="genericDate"/></attribute>
</optional>
<element name="value"><ref name="genericRange"/></element>
<element name="description"><text/></element>
<ref name="references"/>
</element>
</zeroOrMore>
</element>
<ref name="people"/>
</element>
</start>

</grammar>
Loading

0 comments on commit 8174673

Please sign in to comment.