Skip to content

Require discovery 0.9 and do not handle Puli. #81

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

Merged
merged 5 commits into from
Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 1.1.1 - 2016-06-30

### Changed

- Removed Puli logic and require `php-http/discovery:0.9` which makes Puli optional.

## 1.1.0 - 2016-05-19

Expand Down
58 changes: 18 additions & 40 deletions DependencyInjection/Compiler/DiscoveryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace Http\HttplugBundle\DependencyInjection\Compiler;

use Http\Client\HttpClient;
use Http\HttplugBundle\HttplugFactory;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\StreamFactoryDiscovery;
use Http\Discovery\UriFactoryDiscovery;
use Http\Message\MessageFactory;
use Http\Message\StreamFactory;
use Http\Message\UriFactory;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Reference;

/**
* Adds fallback and discovery services.
Expand All @@ -31,55 +32,32 @@ final class DiscoveryPass implements CompilerPassInterface
'stream_factory' => StreamFactory::class,
];

/**
* Factories by type.
*
* @var array
*/
private $factoryClasses = [
'client' => HttpClientDiscovery::class,
'message_factory' => MessageFactoryDiscovery::class,
'uri_factory' => UriFactoryDiscovery::class,
'stream_factory' => StreamFactoryDiscovery::class,
];

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$useDiscovery = false;

foreach ($this->services as $service => $class) {
$serviceId = sprintf('httplug.%s.default', $service);

if (false === $container->has($serviceId)) {
// Register and create factory for the first time
if (false === $useDiscovery) {
$this->registerFactory($container);

$factory = [
new Reference('httplug.factory'),
'find',
];

$useDiscovery = true;
}

// Register and create factory for service
$definition = $container->register($serviceId, $class);

$definition->setFactory($factory);
$definition->setFactory([$this->factoryClasses[$service], 'find']);
$definition->addArgument($class);
}
}
}

/**
* @param ContainerBuilder $container
*
* @throws RuntimeException
*/
private function registerFactory(ContainerBuilder $container)
{
if (false === $container->has('puli.discovery')) {
throw new RuntimeException(
'You need to install puli/symfony-bundle or add configuration at httplug.classes in order to use this bundle. Refer to http://docs.php-http.org/en/latest/integrations/symfony-bundle.html#discovery-of-factory-classes'
);
}

$definition = $container->register('httplug.factory', HttplugFactory::class);

$definition
->addArgument(new Reference('puli.discovery'))
->setPublic(false)
;
}
}
104 changes: 0 additions & 104 deletions HttplugFactory.php

This file was deleted.

6 changes: 1 addition & 5 deletions Tests/Resources/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ public function registerBundles()
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Http\HttplugBundle\HttplugBundle(),
];

if (false === defined('HHVM_VERSION')) {
$bundles[] = new \Puli\SymfonyBundle\PuliBundle();
}


return $bundles;
}

Expand Down
21 changes: 0 additions & 21 deletions Tests/Unit/DependencyInjection/Compiler/DiscoveryPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Http\Client\HttpClient;
use Http\HttplugBundle\DependencyInjection\Compiler\DiscoveryPass;
use Http\HttplugBundle\HttplugFactory;
use Http\Message\MessageFactory;
use Http\Message\StreamFactory;
use Http\Message\UriFactory;
Expand All @@ -24,12 +23,8 @@ protected function registerCompilerPass(ContainerBuilder $container)

public function testDiscoveryFallbacks()
{
$this->setDefinition('puli.discovery', new Definition('Puli\Discovery\Api\Discovery'));

$this->compile();

$this->assertContainerBuilderHasService('httplug.factory', HttplugFactory::class);

$this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class);
$this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class);
$this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class);
Expand All @@ -38,13 +33,10 @@ public function testDiscoveryFallbacks()

public function testDiscoveryPartialFallbacks()
{
$this->setDefinition('puli.discovery', new Definition('Puli\Discovery\Api\Discovery'));
$this->setDefinition('httplug.client.default', new Definition('Http\Adapter\Guzzle6\Client'));

$this->compile();

$this->assertContainerBuilderHasService('httplug.factory', HttplugFactory::class);

$this->assertContainerBuilderHasService('httplug.client.default', 'Http\Adapter\Guzzle6\Client');
$this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class);
$this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class);
Expand All @@ -59,18 +51,5 @@ public function testNoDiscoveryFallbacks()
$this->setDefinition('httplug.stream_factory.default', new Definition(StreamFactory::class));

$this->compile();

$this->assertContainerBuilderNotHasService('httplug.factory');
}

/**
* Overridden test as we have dependencies in this compiler pass.
*
* @test
* @expectedException \RuntimeException
*/
public function compilation_should_not_fail_with_empty_container()
{
$this->compile();
}
}
123 changes: 0 additions & 123 deletions Tests/Unit/HttplugFactoryTest.php

This file was deleted.

Loading