Skip to content

Commit

Permalink
Zf sm3 compatibility (#36)
Browse files Browse the repository at this point in the history
* sm3 compatible factories

* add sm3
  • Loading branch information
basz authored and cjyclaire committed Jun 27, 2016
1 parent e667eed commit 5bb6e07
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"php": ">=5.5",
"aws/aws-sdk-php": "3.*",
"zendframework/zend-filter": "2.*",
"zendframework/zend-servicemanager": "2.*",
"zendframework/zend-servicemanager": "2.* || 3.*",
"zendframework/zend-session": "2.*",
"zendframework/zend-version": "2.*",
"zendframework/zend-view": "2.*"
Expand Down
18 changes: 15 additions & 3 deletions src/Factory/AwsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Aws\Sdk as AwsSdk;
use AwsModule\Module;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Version\Version;
Expand All @@ -14,13 +15,15 @@
class AwsFactory implements FactoryInterface
{
/**
* {@inheritDoc}
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return AwsSdk
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
// Instantiate the AWS SDK for PHP
$config = $serviceLocator->get('Config');
$config = $container->get('Config');
$config = isset($config['aws']) ? $config['aws'] : [];
$config += [
'ua_append' => [
Expand All @@ -31,4 +34,13 @@ public function createService(ServiceLocatorInterface $serviceLocator)

return new AwsSdk($config);
}

/**
* {@inheritDoc}
* @return AwsSdk
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, AwsSdk::class);
}
}
21 changes: 17 additions & 4 deletions src/Factory/CloudFrontLinkViewHelperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Aws\Sdk as AwsSdk;
use AwsModule\View\Helper\CloudFrontLink;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand All @@ -12,6 +13,21 @@
*/
class CloudFrontLinkViewHelperFactory implements FactoryInterface
{

/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return CloudFrontLink
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/** @var AwsSdk $awsSdk */
$awsSdk = $container->get(AwsSdk::class);

return new CloudFrontLink($awsSdk->createCloudFront());
}

/**
* {@inheritDoc}
* @return CloudFrontLink
Expand All @@ -20,9 +36,6 @@ public function createService(ServiceLocatorInterface $serviceLocator)
{
$parentLocator = $serviceLocator->getServiceLocator();

/** @var AwsSdk $awsSdk */
$awsSdk = $parentLocator->get(AwsSdk::class);

return new CloudFrontLink($awsSdk->createCloudFront());
return $this($parentLocator, CloudFrontLink::class);
}
}
22 changes: 17 additions & 5 deletions src/Factory/DynamoDbSessionSaveHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Aws\Sdk as AwsSdk;
use Aws\DynamoDb\SessionHandler;
use AwsModule\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
Expand All @@ -15,13 +16,14 @@
class DynamoDbSessionSaveHandlerFactory implements FactoryInterface
{
/**
* {@inheritDoc}
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return DynamoDbSaveHandler
* @throws ServiceNotCreatedException if "dynamodb" configuration is not set up correctly
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $serviceLocator->get('Config');
$config = $container->get('Config');

if (!isset($config['aws_zf2']['session']['save_handler']['dynamodb'])) {
throw new ServiceNotCreatedException(
Expand All @@ -32,11 +34,21 @@ public function createService(ServiceLocatorInterface $serviceLocator)
}

/** @var AwsSdk $awsSdk */
$awsSdk = $serviceLocator->get(AwsSdk::class);
$awsSdk = $container->get(AwsSdk::class);

$saveHandlerConfig = $config['aws_zf2']['session']['save_handler']['dynamodb'];
$sessionHandler = SessionHandler::fromClient($awsSdk->createDynamoDb(), $saveHandlerConfig);

return new DynamoDbSaveHandler($sessionHandler);
}

/**
* {@inheritDoc}
* @return DynamoDbSaveHandler
* @throws ServiceNotCreatedException if "dynamodb" configuration is not set up correctly
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, DynamoDbSaveHandler::class);
}
}
20 changes: 16 additions & 4 deletions src/Factory/S3LinkViewHelperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Aws\Sdk as AwsSdk;
use AwsModule\View\Helper\S3Link;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand All @@ -12,6 +13,20 @@
*/
class S3LinkViewHelperFactory implements FactoryInterface
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return S3Link
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/** @var AwsSdk $awsSdk */
$awsSdk = $container->get(AwsSdk::class);

return new S3Link($awsSdk->createS3());
}

/**
* {@inheritDoc}
* @return S3Link
Expand All @@ -20,9 +35,6 @@ public function createService(ServiceLocatorInterface $serviceLocator)
{
$parentLocator = $serviceLocator->getServiceLocator();

/** @var AwsSdk $awsSdk */
$awsSdk = $parentLocator->get(AwsSdk::class);

return new S3Link($awsSdk->createS3());
$this($parentLocator, S3Link::class);
}
}
20 changes: 16 additions & 4 deletions src/Factory/S3RenameUploadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Aws\Sdk as AwsSdk;
use AwsModule\Filter\File\S3RenameUpload;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand All @@ -12,13 +13,24 @@
*/
class S3RenameUploadFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return S3RenameUpload
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$parentLocator = $serviceLocator->getServiceLocator();

/** @var AwsSdk $awsSdk */
$awsSdk = $parentLocator->get(AwsSdk::class);
$awsSdk = $container->get(AwsSdk::class);

return new S3RenameUpload($awsSdk->createS3());
}

public function createService(ServiceLocatorInterface $serviceLocator)
{
$parentLocator = $serviceLocator->getServiceLocator();

return $this($parentLocator, S3RenameUpload::class);
}
}

0 comments on commit 5bb6e07

Please sign in to comment.