dsl / mytarget-client-bundle
Requires
- php: >=5.5
- dsl/cache-control: ~0.1
- dsl/my-target-sdk: >=1.0.1
- guzzlehttp/guzzle: ^6.2
- predis/predis: ^1.0
- symfony/framework-bundle: >=2.7.3
README
此捆绑包为在 symfony 框架中提供 MyTarget SDK 客户端的简单设置。
使用 Composer 安装
由于捆绑包和 SDK 不可稳定,使用 dev-master 修订版是合理的。稳定版本即将推出。 composer require dsl/my-target-client-bundle:~0.4.0
将 \DSL\MyTargetClientBundle\DslMyTargetClientBundle
添加到您的 symfony AppKernel。
<?php class AppKernel extends Kernel { //... public function registerBundles() { ... $bundles = [ ... , new \DSL\MyTargetClientBundle\DslMyTargetClientBundle(), ]; ... return $bundles; } //... }
配置 Symfony 捆绑包
以下示例中配置了2个独立客户端
dsl_my_target_client:
redis_lock_client: acme.bundle.service.predis_client #id of predis client service. Must be configured in your app to store locks.
redis_token_client: acme.bundle.service.predis_client #id of predis client service. Must be configured in your app to store tokens cache. Can be the same as previous.
lock_prefix: lock_ #keys prefix for reddis
lock_lifetime: 300 #lifetime for token lock. default value is 300
default_client: test
clients:
main:
auth:
client_id: 12 #your mytarget client id
client_secret: someclientsecret #your mytarget client secret
guzzle_client: acme.bundle.service.guzzle_client #custom guzzle client. not required
test:
auth:
client_id: 49
client_secret: someotherclientsecret
transport_service: acme.bundle.service.guzzle_client #custom http transport. not required
用法
根据上述配置,您可以使用两个服务
dsl.my_target_client.service.client.test
dsl.my_target_client.service.client.main
此外,捆绑包为在 default_client
参数中指定的服务创建了一个别名 dsl.mytarget_client.client
。在示例中,别名 dsl.mytarget_client.client
指向 dsl.my_target_client.service.client.test
,但默认情况下,default_client
参数等于 main
。因此,如果您省略此参数,别名将指向 dsl.my_target_client.service.client.main
。
<?php //... $mtClient =$this->getContainer()->get('dsl.my_target_client.client'); // dsl.my_target_client.service.client.test // or $mtClient =$this->getContainer()->get('dsl.my_target_client.service.client.main'); $mtMapper =$this->getContainer()->get('dsl.my_target_client.service.mapper'); $bannerOperator = new BannerOperator($mtClient, $mtMapper); var_dump( $bannerOperator->all() ); //...
中间件
您可以创建自己的中间件,并用标签 <tag name="dsl.my_target_client.middleware" radius="128" client="client-name" />
标记它们。
如果指定了 client
属性,则此中间件将仅添加到此客户端,否则所有客户端都将接收它。
默认情况下,所有中间件都获取 PHP_INT_MAX
的半径,您可以在从 PHP_INT_MIN
到 PHP_INT_MAX
的范围内指定任何其他期望的值。您可以将中间件视为一个球形层,半径是中间件到球心(其中 HttpTransport
位于球心)的邻近度。