Skip to content

Commit

Permalink
Merge pull request #2 from bpolaszek/ringcentral-support
Browse files Browse the repository at this point in the history
Add RingCentral/PSR7 factory
  • Loading branch information
bpolaszek authored May 31, 2020
2 parents e90b01a + db575fc commit a6fa791
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 6 deletions.
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@ script:
- mkdir -p build/logs && ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml

# League/Uri isolated factory test
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros ringcentral/psr7
- composer req --dev --prefer-dist league/uri:^5.0
- ./vendor/bin/phpunit tests/UriFactoryTest.php

# Zend Diactoros isolated ffactory test
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros ringcentral/psr7
- composer req --dev --prefer-dist zendframework/zend-diactoros
- ./vendor/bin/phpunit tests/UriFactoryTest.php

# Guzzle PSR-7 isolated ffactory test
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros ringcentral/psr7
- composer req --dev --prefer-dist guzzlehttp/psr7
- ./vendor/bin/phpunit tests/UriFactoryTest.php

# Nyholm PSR-7 isolated ffactory test
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros ringcentral/psr7
- composer req --dev --prefer-dist nyholm/psr7
- ./vendor/bin/phpunit tests/UriFactoryTest.php

# Nyholm PSR-7 isolated ffactory test
- composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 zendframework/zend-diactoros ringcentral/psr7
- composer req --dev --prefer-dist ringcentral/psr7
- ./vendor/bin/phpunit tests/UriFactoryTest.php

after_script:
- php vendor/bin/php-coveralls -v
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Supported libraries so far:
* `zendframework/zend-diactoros`
* `league/uri`
* `nyholm/psr7`
* `ringcentral/psr7`

## Usage

Expand Down Expand Up @@ -53,7 +54,7 @@ $uri = current_location(ZendDiactorosAdapter::factory());

## Canonicalizer

This library ships with an URL canonicalizer.
This library ships with an URL canonicalizer.

It is not a perfect one since your PSR-7 library may behave differently regarding special chars, but it should work most of the time.

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"nyholm/psr7": "^1.1",
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "~6.0|~7.0",
"ringcentral/psr7": "^1.3",
"squizlabs/php_codesniffer": "@stable",
"symfony/var-dumper": "^3.3",
"zendframework/zend-diactoros": "^1.6"
Expand All @@ -47,7 +48,8 @@
"league/uri": "URI manipulation Library",
"zendframework/zend-diactoros": "PSR-7 HTTP Message implementation",
"guzzlehttp/psr7": "PSR-7 HTTP message library",
"nyholm/psr7": "PSR-7 HTTP message library"
"nyholm/psr7": "PSR-7 HTTP message library",
"ringcentral/psr7": "PSR-7 HTTP message library"
},
"config": {
"sort-packages": true
Expand Down
38 changes: 38 additions & 0 deletions src/Adapter/RingCentralAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace BenTools\UriFactory\Adapter;

use BenTools\UriFactory\UriFactoryInterface;
use RingCentral\Psr7\Uri;
use Psr\Http\Message\UriInterface;

final class RingCentralAdapter implements AdapterInterface
{
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('\RingCentral\Psr7\Uri');
}
}
2 changes: 2 additions & 0 deletions src/UriFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use BenTools\UriFactory\Adapter\GuzzleAdapter;
use BenTools\UriFactory\Adapter\LeagueUriAdapter;
use BenTools\UriFactory\Adapter\NyholmAdapter;
use BenTools\UriFactory\Adapter\RingCentralAdapter;
use BenTools\UriFactory\Adapter\ZendDiactorosAdapter;
use Psr\Http\Message\UriInterface;

Expand Down Expand Up @@ -35,6 +36,7 @@ private function getDefaultAdapters()
GuzzleAdapter::class,
ZendDiactorosAdapter::class,
LeagueUriAdapter::class,
RingCentralAdapter::class,
];
}

Expand Down
39 changes: 39 additions & 0 deletions tests/Adapter/RingCentralAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace BenTools\UriFactory\Tests\Adapter;

use BenTools\UriFactory\Adapter\RingCentralAdapter;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface;
use function BenTools\UriFactory\Helper\current_location;

class RingCentralAdapterTest extends TestCase
{

public function testClassCheck()
{
$this->assertEquals(class_exists('RingCentral\Psr7\Uri'), RingCentralAdapter::isInstalled());
}

public function testFactory()
{
$factory = RingCentralAdapter::factory();
$this->assertInstanceOf(RingCentralAdapter::class, $factory);
}

public function testUri()
{
$factory = RingCentralAdapter::factory();
$uri = $factory->createUri('http://www.example.net');
$this->assertInstanceOf(UriInterface::class, $uri);
}

public function testInFactory()
{
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['REQUEST_URI'] = '/foo/bar?foo=bar&baz=bat';
$uri = current_location(RingCentralAdapter::factory());
$this->assertInstanceOf('RingCentral\Psr7\Uri', $uri);
unset($_SERVER['REQUEST_URI'], $_SERVER['HTTP_HOST']);
}
}

0 comments on commit a6fa791

Please sign in to comment.