Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Closes #29 // Fixed bug in timing of calling S3 wrapper. Moved from c…
Browse files Browse the repository at this point in the history
…ontainer compilation to bundle boot.
  • Loading branch information
jmcclell committed Feb 14, 2014
1 parent 5ceb937 commit 68b1eea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
24 changes: 16 additions & 8 deletions DependencyInjection/JLMAwsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,28 @@ public function load(array $configs, ContainerBuilder $container)
$this->baseClass = $config['aws_base_class'];

$this->servicePrefix = $config['service_prefix'];

if (!empty($this->servicePrefix)) {
$this->servicePrefix .= '.';
}


$awsConfigTranslator = new AwsConfigTranslator();
$awsConfig = $awsConfigTranslator->translateConfigToAwsConfig($config);

$this->generateServices($awsConfig, $container);

$this->registerS3StreamWrapper($config, $container);
$this->registerS3StreamWrapperAlias($config, $container);
}

private function registerS3StreamWrapper(array $config, ContainerBuilder $container)
/**
* Checks to see if an S3 stream wrapper service has been set. If so, it aliases it to be picked up
* by a compiler pass later on to register the S3 stream wrapper.
*
* @param array $config
* @param ContainerBuilder $container [description]
* @return [type] [description]
*/
private function registerS3StreamWrapperAlias(array $config, ContainerBuilder $container)
{
$s3StreamWrapper = $config['s3_stream_wrapper'];
if(!empty($s3StreamWrapper)) {
Expand All @@ -67,13 +75,13 @@ private function registerS3StreamWrapper(array $config, ContainerBuilder $contai
$s3StreamWrapper = 's3.' . $s3StreamWrapper;
}

$s3 = $container->get($this->servicePrefix . $s3StreamWrapper, ContainerInterface::IGNORE_ON_INVALID_REFERENCE);
$wrapperService = $this->servicePrefix . $s3StreamWrapper;

if ($s3 == null) {
if ($container->has($wrapperService)) {
$container->setAlias('jlm_aws.s3_stream_wrapper_service', $wrapperService);
} else {
throw new \Exception("Configuration directive 's3_stream_wrapper' is set to '$s3StreamWrapper', but no S3 service is configured by that name.'");
}

$s3->registerStreamWrapper();
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions JLMAwsBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Resource\FileResource;

use JLM\AwsBundle\DependencyInjection\Compiler\S3WrapperCompilerPass;

class JLMAwsBundle extends Bundle
{
public function build(ContainerBuilder $container)
Expand All @@ -20,4 +22,13 @@ public function build(ContainerBuilder $container)
*/
$container->addResource(new FileResource(__DIR__ . '/Config/AwsConfigTranslator.php'));
}

public function boot()
{
$container = $this->container;
if ($container->has('jlm_aws.s3_stream_wrapper_service')) {
$s3 = $container->get('jlm_aws.s3_stream_wrapper_service');
$s3->registerStreamWrapper();
}
}
}
3 changes: 2 additions & 1 deletion Tests/DependencyInjection/JLMAwsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function testS3StreamWrapperTrue($format)
{
$client = $this->getClient('s3_stream_wrapper_true_' . $format);
$container = $client->getContainer();

$this->assertTrue($container->has('jlm_aws.s3_stream_wrapper_service'));
$wrappers = stream_get_wrappers();
$this->assertTrue(in_array('s3', $wrappers));
}
Expand All @@ -417,6 +417,7 @@ public function testS3StreamWrapperNamed($format)
{
$client = $this->getClient('s3_stream_wrapper_named_' . $format);
$container = $client->getContainer();
$this->assertTrue($container->has('jlm_aws.s3_stream_wrapper_service'));

$wrappers = stream_get_wrappers();

Expand Down

0 comments on commit 68b1eea

Please sign in to comment.