sellerlabs/research-php

SellerLabs Research API的PHP客户端

v0.3.0 2016-09-15 22:05 UTC

README

这是SellerLabs研究API服务的官方PHP客户端库(之前被称为NodeMWS/ModernMWS客户端)。

需求

  • PHP +5.6或HHVM +3.6。
  • Composer和autoload.php
  • 当然还需要:使用研究服务的凭据。

文档

安装与使用

使用Composer

首先,将包添加到您的composer.json文件中

    // ...
    "require": {
        "sellerlabs/research-php": "*"
    }
    // ...

然后运行composer update

如何在Laravel 5中使用

首先,您需要在应用程序服务提供程序内部配置客户端

public function register()
{
    $this->app->bind(
        SellerLabs\Research\Interfaces\ResearchClientInterface::class,
        function () {
            return new ResearchClient(
                'YourClientId',
                'YourClientSecret',
                'http://research.api.sellerlabs.com'
            );
        }
    );
}

然后,在任何控制器内部,您可以通过构造函数注入依赖项

// ...
class ProductsController extends Controller
{
    /**
     * Implementation of a client for SellerLabs' research API
     *
     * @var ResearchClientInterface
     */
    protected $researchClient;

    /**
     * Construct an instance of a ProductsController
     */
    public function __construct(ResearchClientInterface $researchClient)
    {
        $this->researchClient = $researchClient;
    }

    /**
     * Handle GET /products/
     */
    public function getIndex()
    {
        return $this->researchClient->getSearch('keyword', 'testing');
    }
}

Laravel的容器足够智能,可以自动执行依赖注入,在初始化控制器类时会为您添加客户端参数