Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
【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
You can’t perform that action at this time.