Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 38938d8
Showing
18 changed files
with
565 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
filter: | ||
excluded_paths: [tests/*] | ||
checks: | ||
php: | ||
code_rating: true | ||
remove_extra_empty_lines: true | ||
remove_php_closing_tag: true | ||
remove_trailing_whitespace: true | ||
fix_use_statements: | ||
remove_unused: true | ||
preserve_multiple: false | ||
preserve_blanklines: true | ||
order_alphabetically: true | ||
fix_php_opening_tag: true | ||
fix_linefeed: true | ||
fix_line_ending: true | ||
fix_identation_4spaces: true | ||
fix_doc_comments: true | ||
tools: | ||
php_analyzer: true | ||
php_code_coverage: false | ||
php_code_sniffer: | ||
config: | ||
standard: PSR2 | ||
filter: | ||
paths: ['src'] | ||
php_loc: | ||
enabled: true | ||
excluded_dirs: [vendor, tests] | ||
php_cpd: | ||
enabled: true | ||
excluded_dirs: [vendor, tests] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
dist: xenial | ||
|
||
language: php | ||
|
||
php: | ||
- 7.1 | ||
- 7.2 | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --no-interaction --prefer-source --dev | ||
|
||
script: | ||
- ./vendor/bin/phpcs --standard=psr2 -n src/ | ||
- mkdir -p build/logs | ||
- ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml | ||
|
||
after_script: | ||
- php vendor/bin/coveralls -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Benoit POLASZEK | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[![Latest Stable Version](https://poser.pugx.org/bentools/uri-factory/v/stable)](https://packagist.org/packages/bentools/uri-factory) | ||
[![License](https://poser.pugx.org/bentools/uri-factory/license)](https://packagist.org/packages/bentools/uri-factory) | ||
[![Build Status](https://img.shields.io/travis/bpolaszek/uri-factory/master.svg?style=flat-square)](https://travis-ci.org/bpolaszek/uri-factory) | ||
[![Coverage Status](https://coveralls.io/repos/github/bpolaszek/uri-factory/badge.svg?branch=master)](https://coveralls.io/github/bpolaszek/uri-factory?branch=master) | ||
[![Quality Score](https://img.shields.io/scrutinizer/g/bpolaszek/uri-factory.svg?style=flat-square)](https://scrutinizer-ci.com/g/bpolaszek/uri-factory) | ||
[![Total Downloads](https://poser.pugx.org/bentools/uri-factory/downloads)](https://packagist.org/packages/bentools/uri-factory) | ||
|
||
# Uri Factory | ||
|
||
PSR-7 `UriInterface` factory bridge, with automatic discovery of existing libraries in your project: | ||
|
||
* `guzzlehttp/psr7` | ||
* `zendframework/zend-diactoros` | ||
* `league/uri` | ||
|
||
## Usage | ||
|
||
On any URL string: | ||
```php | ||
use function BenTools\UriFactory\Helper\uri; | ||
$uri = uri('http://www.example.net'); // Will convert to a Psr\Http\Message\UriInterface instance | ||
``` | ||
|
||
On current location: | ||
```php | ||
use function BenTools\UriFactory\Helper\request_uri; | ||
$uri = request_uri(); // Will convert the current location to a Psr\Http\Message\UriInterface instance | ||
``` | ||
|
||
## Installation | ||
|
||
PHP 7.1+ is required. | ||
|
||
> composer require bentools/uri-factory 1.0.x-dev | ||
## Tests | ||
|
||
> ./vendor/bin/phpunit | ||
## License | ||
|
||
MIT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "bentools/uri-factory", | ||
"description": "PSR-7 URI factory", | ||
"keywords": ["url", "uri", "psr-7", "psr7", "UriInterface", "factory"], | ||
"authors": [ | ||
{ | ||
"name": "Beno!t POLASZEK", | ||
"email": "bpolaszek@gmail.com", | ||
"homepage": "http://www.polaszek.fr", | ||
"role": "Developer" | ||
} | ||
], | ||
"type": "library", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.1", | ||
"psr/http-message": "^1.0" | ||
}, | ||
"require-dev": { | ||
"guzzlehttp/psr7": "^1.4", | ||
"league/uri": "^5.0", | ||
"phpunit/phpunit": "@stable", | ||
"satooshi/php-coveralls": "@stable", | ||
"squizlabs/php_codesniffer": "@stable", | ||
"symfony/var-dumper": "^3.3", | ||
"zendframework/zend-diactoros": "^1.6" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"BenTools\\UriFactory\\": "src" | ||
}, | ||
"files": [ | ||
"src/Helper/functions.php" | ||
] | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"BenTools\\UriFactory\\Tests\\": "tests" | ||
}, | ||
"files": [ | ||
"vendor/symfony/var-dumper/Resources/functions/dump.php" | ||
] | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
beStrictAboutOutputDuringTests="true" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
processIsolation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
verbose="true" | ||
> | ||
<testsuite> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace BenTools\UriFactory\Adapter; | ||
|
||
use BenTools\UriFactory\UriFactoryInterface; | ||
|
||
interface AdapterInterface extends UriFactoryInterface | ||
{ | ||
|
||
/** | ||
* Check if the dependency is installed or not. | ||
* | ||
* @return bool | ||
*/ | ||
public static function isInstalled(): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace BenTools\UriFactory\Adapter; | ||
|
||
use BenTools\UriFactory\UriFactoryInterface; | ||
use GuzzleHttp\Psr7\Uri; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
final class GuzzleAdapter implements AdapterInterface | ||
{ | ||
/** | ||
* GuzzleAdapter constructor. | ||
*/ | ||
protected function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createUri(string $uri): UriInterface | ||
{ | ||
return new Uri($uri); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function factory(): UriFactoryInterface | ||
{ | ||
return new self; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function isInstalled(): bool | ||
{ | ||
return class_exists('GuzzleHttp\Psr7\Uri'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace BenTools\UriFactory\Adapter; | ||
|
||
use BenTools\UriFactory\UriFactoryInterface; | ||
use League\Uri\Factory; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
final class LeagueUriAdapter implements AdapterInterface | ||
{ | ||
/** | ||
* @var Factory | ||
*/ | ||
private $factory; | ||
|
||
/** | ||
* LeagueUriAdapter constructor. | ||
* @param Factory $factory | ||
*/ | ||
protected function __construct(Factory $factory) | ||
{ | ||
$this->factory = $factory; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createUri(string $uri): UriInterface | ||
{ | ||
return $this->factory->create($uri); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function factory(Factory $factory = null): UriFactoryInterface | ||
{ | ||
return new self($factory ?? new Factory()); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function isInstalled(): bool | ||
{ | ||
return class_exists('League\Uri\Factory'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace BenTools\UriFactory\Adapter; | ||
|
||
use BenTools\UriFactory\UriFactoryInterface; | ||
use Psr\Http\Message\UriInterface; | ||
use Zend\Diactoros\Uri; | ||
|
||
final class ZendDiactorosAdapter implements AdapterInterface | ||
{ | ||
|
||
/** | ||
* ZendDiactorosAdapter constructor. | ||
*/ | ||
protected function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createUri(string $uri): UriInterface | ||
{ | ||
return new Uri($uri); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function factory(): UriFactoryInterface | ||
{ | ||
return new self; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function isInstalled(): bool | ||
{ | ||
return class_exists('Zend\Diactoros\Uri'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace BenTools\UriFactory\Helper; | ||
|
||
use BenTools\UriFactory\UriFactory; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
/** | ||
* @param string $uri | ||
* @return UriInterface | ||
*/ | ||
function uri(string $uri): UriInterface | ||
{ | ||
return UriFactory::factory()->createUri($uri); | ||
} | ||
|
||
/** | ||
* @return UriInterface | ||
* @throws \RuntimeException | ||
*/ | ||
function request_uri(): UriInterface | ||
{ | ||
return UriFactory::factory()->createFromRequestUri(); | ||
} |
Oops, something went wrong.