toin0u/concise

通过外部提供商压缩您的URL

v0.1 2014-12-17 22:00 UTC

This package is auto-updated.

Last update: 2024-08-24 03:53:53 UTC


README

Latest Version Software License Build Status Code Coverage Quality Score HHVM Status Total Downloads SensioLabsInsight

通过外部提供商压缩您的URL :)

安装

通过Composer

$ composer require toin0u/concise

用法

使用Google提供商的简单示例

use Concise\Concise;
use Concise\Provider\Google;
use Ivory\HttpAdapter\GuzzleHttpAdapter;

$concise = new Concise(new Google(new GuzzleHttpAdapter));

// Returns the shortened URL
$concise->shorten('http://any.url');

// Returns the expanded URL
$concise->expand('http://short.ly/1234');

查看所有可用的适配器列表,请参阅官方文档

目前支持的提供商

  • Bitly
  • Google
  • Tinycc

提供商链式连接

您可以使用多个提供商同时缩短一个URL。

请确保在缩短和扩展链中按相同的顺序添加提供商。扩展会自动按相反的顺序进行。

use Concise\Concise;
use Concise\Provider\Chain;

$chain = new Chain;

$chain->addProvider(/* add a Provider instance here */);
$chain->addProvider(/* add another Provider instance here */);

$concise = new Concise($chain);

缓存

当处理大量URL时,缓存已缩短/扩展的URL可能是有意义的。这样您可以避免不必要的HTTP请求。

要使用缓存,请先安装Stash

$ composer require tedivm/stash
use Concise\Concise;
use Concise\Provider\Cache;
use Stash\Pool;

$cache = new Cache(/* add a Provider instance here */, new Pool);
$concise = new Concise($cache);

测试

$ phpspec run

贡献

有关详细信息,请参阅CONTRIBUTING

鸣谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件