socloz/guzzle-bundle

此Bundle为guzzle HTTP客户端提供集成,以便使用Symfony2访问RESTful API

安装次数: 22,657

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 12

分支: 29

类型:symfony-bundle

v1.0.0 2012-10-25 17:46 UTC

This package is not auto-updated.

Last update: 2024-09-22 02:26:53 UTC


README

DdeboerGuzzleBundle是一个用于将Guzzle PHP库集成到您项目的Symfony2 Bundle。

安装

使用composer

  1. 在项目的composer.json文件中将socloz/guzzle-bundle添加为依赖项

     {
         "require": {
             "socloz/guzzle-bundle": "dev-socloz-master",
         }
     }
    
  2. 安装依赖项

     php composer.phar update
    

启用Bundle

在kernel中启用Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Ddeboer\GuzzleBundle\DdeboerGuzzleBundle(),
    );
}

配置Bundle

添加自定义服务客户端

<?php

/*
 * Copyright CloseToMe 2011/2012
 */

namespace Acme\ExampleBundle\Webservice;

use Guzzle\Common\Collection;
use Guzzle\Service\Client;
use Guzzle\Service\Description\ServiceDescription;

class MyWebserviceClient extends Client
{

    public static function factory($config = array())
    {
        $client = new self($config['base_url'], $config);

        // Add custom setup code

        // Attach a service description to the client
        $description = ServiceDescription::factory($config);
        $client->setDescription($description);

        return $client;
    }
}

并配置webservice

# app/config/config.yml
ddeboer_guzzle:
  service_builder:
    configuration:
      Stats:
        class: "Acme\\ExampleBundle\\Webservice\\MyWebserviceClient"
        params:
          operations:
            OperationName:
              httpMethod: GET
              uri: /search
              parameters:
                query:
                  location: query
                  required: true
                  type: string
                sort:
                  location: query
                  type: string

有关更多信息,请参阅Guzzle文档

许可证

此Bundle采用MIT许可证。在Bundle中查看完整的许可证。

Resources/meta/LICENSE