Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active January 27, 2016 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/7af525bf2a6d31e445b4 to your computer and use it in GitHub Desktop.
Save kurozumi/7af525bf2a6d31e445b4 to your computer and use it in GitHub Desktop.
【Silex】Amazon Product Adverstising API(AmazonアソシエイトAPI)ライブラリのApai-IO用のサービスプロバイダー
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace Acme\ServiceProvider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use ApaiIO\ApaiIO;
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\ResponseTransformer\XmlToSimpleXmlObject;
use ApaiIO\ResponseTransformer\XmlToDomDocument;
use ApaiIO\Operations\Lookup;
/**
* Description of ApiIOServiceProvider
*
* @author kurozumi
*/
class ApaiIOServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['apaiio.api_key'] = array(
"ENDPOINT" => null,
"AWS_API_KEY" => null,
"AWS_API_SERCERT_KEY" => null,
"AWS_ASSOCIATE_TAG" => null
);
$app['apaiio.config'] = $app->factory(function($app){
$conf = new GenericConfiguration();
$conf
->setCountry($app['apaiio.api_key']['ENDPOINT'])
->setAccessKey($app['apaiio.api_key']['AWS_API_KEY'])
->setSecretKey($app['apaiio.api_key']['AWS_API_SERCERT_KEY'])
->setAssociateTag($app['apaiio.api_key']['AWS_ASSOCIATE_TAG']);
if (false === empty($app['apaiio.api_key']['REQUEST']))
{
$conf->setRequest($app['apaiio.api_key']['REQUEST']);
}
if (false === empty($app['apaiio.api_key']['RESPONSE']))
{
$conf->setResponseTransformer($app['apaiio.api_key']['RESPONSE']);
}
return $conf;
});
$app['apaiio'] = $app->factory(function($app) {
return new ApaiIO($app['apaiio.config']);
});
$app['apaiio.lookup'] = function($app) {
return new Lookup;
};
$app['apaiio.trans.simplexml'] = function($app) {
return new XmlToSimpleXmlObject;
};
$app['apaiio.trans.dom'] = function($app) {
return new XmlToDomDocument;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment