Skip to content

Implement httplug #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .puli/GeneratedPuliFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Puli;

use Puli\Discovery\Api\Discovery;
use Puli\Discovery\Binding\Initializer\ResourceBindingInitializer;
use Puli\Discovery\KeyValueStoreDiscovery;
use Puli\Manager\Api\Server\ServerCollection;
use Puli\Repository\Api\ResourceRepository;
use Puli\Repository\PathMappingRepository;
use Puli\UrlGenerator\Api\UrlGenerator;
use Puli\UrlGenerator\DiscoveryUrlGenerator;
use RuntimeException;
use Webmozart\KeyValueStore\JsonFileStore;

/**
* Creates Puli's core services.
*
* This class was auto-generated by Puli.
*
* IMPORTANT: Before modifying the code below, set the "factory.auto-generate"
* configuration key to false:
*
* $ puli config factory.auto-generate false
*
* Otherwise any modifications will be overwritten!
*/
class GeneratedPuliFactory
{
/**
* Creates the resource repository.
*
* @return ResourceRepository The created resource repository.
*/
public function createRepository()
{
if (!interface_exists('Puli\Repository\Api\ResourceRepository')) {
throw new RuntimeException('Please install puli/repository to create ResourceRepository instances.');
}

$store = new JsonFileStore(__DIR__.'/path-mappings.json', true);
$repo = new PathMappingRepository($store, __DIR__.'/..');

return $repo;
}

/**
* Creates the resource discovery.
*
* @param ResourceRepository $repo The resource repository to read from.
*
* @return Discovery The created discovery.
*/
public function createDiscovery(ResourceRepository $repo)
{
if (!interface_exists('Puli\Discovery\Api\Discovery')) {
throw new RuntimeException('Please install puli/discovery to create Discovery instances.');
}

$store = new JsonFileStore(__DIR__.'/bindings.json', true);
$discovery = new KeyValueStoreDiscovery($store, array(
new ResourceBindingInitializer($repo),
));

return $discovery;
}

/**
* Creates the URL generator.
*
* @param Discovery $discovery The discovery to read from.
*
* @return UrlGenerator The created URL generator.
*/
public function createUrlGenerator(Discovery $discovery)
{
if (!interface_exists('Puli\UrlGenerator\Api\UrlGenerator')) {
throw new RuntimeException('Please install puli/url-generator to create UrlGenerator instances.');
}

$generator = new DiscoveryUrlGenerator($discovery, array());

return $generator;
}
}
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@
],
"require": {
"php": ">=5.4.0",
"egeloen/http-adapter": "~0.8|~1.0",
"igorw/get-in": "~1.0"
"igorw/get-in": "~1.0",
"psr/http-message-implementation": "^1.0",
"php-http/client-implementation": "^1.0",
"php-http/message-factory": "^1.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it miss the require on php-httplug, even if it's included by the client implementation, its the direct package that it is linked too.

},
"require-dev": {
"geoip2/geoip2": "~2.0",
"symfony/stopwatch": "~2.5"
"symfony/stopwatch": "~2.5",
"php-http/discovery": "^0.6.4",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use discovery on 0.7 a lot of dependencies has been removed

"php-http/mock-client": "^0.1.1"
},
"suggest": {
"ext-geoip": "Enabling the geoip extension allows you to use the MaxMindProvider.",
"geoip/geoip": "If you are going to use the MaxMindBinaryProvider (conflict with geoip extension).",
"geoip2/geoip2": "If you are going to use the GeoIP2DatabaseProvider.",
"symfony/stopwatch": "If you want to use the TimedGeocoder"
},
"minimum-stability": "beta",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be removed, httplug is now in a stable version :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly no, because the discovery depends on puli which is in beta state currently 😢

"autoload": {
"psr-0": { "Geocoder": "src/" }
},
Expand Down
216 changes: 216 additions & 0 deletions puli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"version": "1.0",
"name": "willdurand/geocoder",
"config": {
"bootstrap-file": "vendor/autoload.php"
},
"packages": {
"geoip2/geoip2": {
"install-path": "vendor/geoip2/geoip2",
"installer": "composer",
"env": "dev"
},
"guzzlehttp/guzzle": {
"install-path": "vendor/guzzlehttp/guzzle",
"installer": "composer",
"env": "dev"
},
"guzzlehttp/promises": {
"install-path": "vendor/guzzlehttp/promises",
"installer": "composer",
"env": "dev"
},
"guzzlehttp/psr7": {
"install-path": "vendor/guzzlehttp/psr7",
"installer": "composer",
"env": "dev"
},
"igorw/get-in": {
"install-path": "vendor/igorw/get-in",
"installer": "composer"
},
"justinrainbow/json-schema": {
"install-path": "vendor/justinrainbow/json-schema",
"installer": "composer",
"env": "dev"
},
"maxmind-db/reader": {
"install-path": "vendor/maxmind-db/reader",
"installer": "composer",
"env": "dev"
},
"maxmind/web-service-common": {
"install-path": "vendor/maxmind/web-service-common",
"installer": "composer",
"env": "dev"
},
"padraic/humbug_get_contents": {
"install-path": "vendor/padraic/humbug_get_contents",
"installer": "composer",
"env": "dev"
},
"padraic/phar-updater": {
"install-path": "vendor/padraic/phar-updater",
"installer": "composer",
"env": "dev"
},
"php-http/client-common": {
"install-path": "vendor/php-http/client-common",
"installer": "composer",
"env": "dev"
},
"php-http/curl-client": {
"install-path": "vendor/php-http/curl-client",
"installer": "composer",
"env": "dev"
},
"php-http/discovery": {
"install-path": "vendor/php-http/discovery",
"installer": "composer",
"env": "dev"
},
"php-http/guzzle6-adapter": {
"install-path": "vendor/php-http/guzzle6-adapter",
"installer": "composer",
"env": "dev"
},
"php-http/httplug": {
"install-path": "vendor/php-http/httplug",
"installer": "composer",
"env": "dev"
},
"php-http/message-factory": {
"install-path": "vendor/php-http/message-factory",
"installer": "composer"
},
"php-http/mock-client": {
"install-path": "vendor/php-http/mock-client",
"installer": "composer",
"env": "dev"
},
"php-http/promise": {
"install-path": "vendor/php-http/promise",
"installer": "composer",
"env": "dev"
},
"psr/http-message": {
"install-path": "vendor/psr/http-message",
"installer": "composer"
},
"psr/log": {
"install-path": "vendor/psr/log",
"installer": "composer",
"env": "dev"
},
"puli/cli": {
"install-path": "vendor/puli/cli",
"installer": "composer",
"env": "dev"
},
"puli/composer-plugin": {
"install-path": "vendor/puli/composer-plugin",
"installer": "composer",
"env": "dev"
},
"puli/discovery": {
"install-path": "vendor/puli/discovery",
"installer": "composer",
"env": "dev"
},
"puli/manager": {
"install-path": "vendor/puli/manager",
"installer": "composer",
"env": "dev"
},
"puli/repository": {
"install-path": "vendor/puli/repository",
"installer": "composer",
"env": "dev"
},
"puli/url-generator": {
"install-path": "vendor/puli/url-generator",
"installer": "composer",
"env": "dev"
},
"ramsey/uuid": {
"install-path": "vendor/ramsey/uuid",
"installer": "composer",
"env": "dev"
},
"seld/jsonlint": {
"install-path": "vendor/seld/jsonlint",
"installer": "composer",
"env": "dev"
},
"symfony/console": {
"install-path": "vendor/symfony/console",
"installer": "composer",
"env": "dev"
},
"symfony/event-dispatcher": {
"install-path": "vendor/symfony/event-dispatcher",
"installer": "composer",
"env": "dev"
},
"symfony/filesystem": {
"install-path": "vendor/symfony/filesystem",
"installer": "composer",
"env": "dev"
},
"symfony/polyfill-mbstring": {
"install-path": "vendor/symfony/polyfill-mbstring",
"installer": "composer",
"env": "dev"
},
"symfony/process": {
"install-path": "vendor/symfony/process",
"installer": "composer",
"env": "dev"
},
"symfony/stopwatch": {
"install-path": "vendor/symfony/stopwatch",
"installer": "composer",
"env": "dev"
},
"webmozart/assert": {
"install-path": "vendor/webmozart/assert",
"installer": "composer",
"env": "dev"
},
"webmozart/console": {
"install-path": "vendor/webmozart/console",
"installer": "composer",
"env": "dev"
},
"webmozart/expression": {
"install-path": "vendor/webmozart/expression",
"installer": "composer",
"env": "dev"
},
"webmozart/glob": {
"install-path": "vendor/webmozart/glob",
"installer": "composer",
"env": "dev"
},
"webmozart/json": {
"install-path": "vendor/webmozart/json",
"installer": "composer",
"env": "dev"
},
"webmozart/key-value-store": {
"install-path": "vendor/webmozart/key-value-store",
"installer": "composer",
"env": "dev"
},
"webmozart/path-util": {
"install-path": "vendor/webmozart/path-util",
"installer": "composer",
"env": "dev"
},
"zendframework/zend-diactoros": {
"install-path": "vendor/zendframework/zend-diactoros",
"installer": "composer",
"env": "dev"
}
}
}
22 changes: 13 additions & 9 deletions src/Geocoder/Provider/AbstractHttpProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,39 @@

namespace Geocoder\Provider;

use Ivory\HttpAdapter\HttpAdapterInterface;
use Http\Client\HttpClient;
use Http\Message\MessageFactory;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;

/**
* @author William Durand <[email protected]>
*/
class AbstractHttpProvider extends AbstractProvider
{
/**
* @var HttpAdapterInterface
* @var HttpClient
*/
private $adapter;
private $client;

/**
* @param HttpAdapterInterface $adapter An HTTP adapter
* @param HttpClient $client An HTTP adapter
*/
public function __construct(HttpAdapterInterface $adapter)
public function __construct(HttpClient $client = null, MessageFactory $factory = null)
{
parent::__construct();

$this->adapter = $adapter;
$this->client = $client ?: HttpClientDiscovery::find();
$this->factory = $factory ?: MessageFactoryDiscovery::find();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the way we have done this for not having discovery, is to put discovery in suggest package then on the constructor we check the existence of the DiscoveryClass, if it has not been found we throw a \LogicException with a specific error which will be in our documentation for easy googling on that, here is an example :

if (null === $responseFactory && !class_exists('\Http\Discovery\MessageFactoryDiscovery')) {
    throw new \LogicException('No response factory provided and no discovery service is present to guess it, maybe you need to install php-http/discovery package?');
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the discovery service at all, it brings many problems and puli as new dependency. Maybe we should wait for a stable release of the discovery service.

}

/**
* Returns the HTTP adapter.
*
* @return HttpAdapterInterface
* @return HttpClient
*/
public function getAdapter()
public function getHttpClient()
Copy link
Member

@Nyholm Nyholm Mar 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add public setters and protected getters. Otherwise we have to modify the constructors of every provider.

{
return $this->adapter;
return $this->client;
}
}
Loading