dozoisch/cachedbuzz 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dozoisch/cachedbuzz

Composer 安装命令:

composer require dozoisch/cachedbuzz

包简介

Browser with caching handling over Buzz

README 文档

README

This bundle is meant to provide a way to cache request made with the buzz bundle. This bundle can be used exactly like buzz, the cache is integrated directly. The bundle is under the MIT license. For more information see the file called LICENSE in the root of the path.

Installation

  1. Add this to the composer.json:

    {
        "require": {
            "dozoisch/cachedbuzz": "dev-master"
        }
    }
  2. Enable the bundle in app/AppKernel.php:

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Dozoisch\CachedBuzzBundle\DozoischCachedBuzzBundle(),
        );
    }

Configuration

No setting is mandatory as every thing fallback to a default setting or a default implementation provided by the bundle. The default cache uses APC. If the module is not available on your web server, the module initialization will fail.

Here is the full configuration (in yaml) possible, with the defaults value :

dozoisch_cached_buzz:
    http_client:
        timeout: 10
        verify_peer: true
        max_redirects: 5
        ignore_errors: true
    cache: null #takes a string
    validator: null #takes a string

In the http_client is used to configure the buzz client. The cache setting takes a string that should be a class or a service. Same thing for the validator.

The cache has to implement the class Dozoisch\CachedBuzzBundle\Cache\CacheInterface.
The validator has to implement the class Dozoisch\CachedBuzzBundle\Cache\CacheValidatorInterface.

Running as a Service

To run the Cached Buzz Bundle as a service, insert this into your services.yml file:

parameters:
  dozoisch.bundle.name: Dozoisch\CachedBuzzBundle

services:
  # The actual service
  dozoisch.buzz.browser:
    class: '%dozoisch.bundle.name%\Browser'
    arguments: ['@dozoisch.buzz.cacher', '@dozoisch.buzz.client.curl']
    
  # Parametring.
  dozoisch.buzz.client.curl:
    class:  'Buzz\Client\Curl'
    public: false
    calls:
      - [setVerifyPeer, [false]] # this is optional
      - [setTimeout, [100]] # this is optional

  dozoisch.buzz.cacheinterface:
    class: '%dozoisch.bundle.name%\Cache\APCCache'

  dozoisch.buzz.cachevalidator:
    class: '%dozoisch.bundle.name%\Cache\CacheValidator'

  dozoisch.buzz.cacher:
    class: '%dozoisch.bundle.name%\Cacher'
    arguments: ['@dozoisch.buzz.cacheinterface', '@dozoisch.buzz.cachevalidator']

When using it like that it overrides some of the normal bundles setting and thus, the cacher and client parameters for the browser are no longer optional.

How to use it

You can now call the browser just as you would with any other service.

###Container aware class

If you wish to call it from a container aware class, a controller for example, just do $this->get('dozoisch.buzz.browser');.

###Non-container aware class

To call it from a service which is not container aware, first add this to your services.yml

services:
  my.super.service:
    class: xclass.class
    arguments: ['@dozoisch.buzz.browser']

And make sure to have the appropriate constructor in your class :

/** @var Buzz\Browser */
protected $browser;

public function __construct(\Buzz\Browser $browser) {
    $this->browser = $browser;
}

###Actually using it

After retrieving the browser, you can use it as you would with the normal buzz browser. This bundles is meant to be used seamlessly over the normal buzz instance.

$response = $this->browser->get("http://example.com");
$content = $response->getContent();

The available functions are post, head, patch, put, delete.

统计信息

  • 总下载量: 40
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-05-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固