rezzza/shorty-bundle

Symfony 中长网址的短链接

v1.2.1 2015-12-18 08:53 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:26:32 UTC


README

https://poser.pugx.org/rezzza/shorty-bundle/version.png https://travis-ci.org/rezzza/ShortyBundle.png?branch=master

Symfony 中长网址的短链接。

集成 Shorty 库。

安装

使用 Composer 安装: rezzza/shorty-bundle

在你的 composer.json 文件中,你应该有

{
    "require": {
        "rezzza/shorty-bundle": "2.0.*"
    }
}

然后更新你的 AppKernel.php 文件,注册这个包:

new Rezzza\ShortyBundle\RezzzaShortyBundle()

配置

rezzza_shorty:
    default_provider: google
    providers:
        google:
            id: google
            key: ~
            http_adapter: ~ # default is Rezzza\Shorty\Http\CurlAdapter
        google2:
            id: google
            key: anotherkey
        bitly:
            id: bitly
            access_token: ~ #required
            http_adapter: ~ # default is Rezzza\Shorty\Http\CurlAdapter
        custom:
            id: my_custom_service
        chain:
            id: chain
            providers: [google, bitly, custom, google2]

基本用法

$shorty = $this->container->get('rezzza.shorty.google');
// or
$shorty = $this->container->get('rezzza.shorty'); // will use default_provider.
try {
    $short  = $shorty->shorten('http://www.verylastroom.net');
    $long   = $shorty->expand($long);
} catch (\Rezzza\Shorty\Exception\Exception $e) {
    // oops ...
}

异常

异常目录