canducci/shorten
Composer 安装命令:
composer require canducci/shorten
包简介
Canducci Shorten Url
README 文档
README
##Canducci Shorten Url
Providers: BitLy, Googl, IsGd, MigreMe, TinyUrl and TrIm.
The package offers providers in their most current version can be selected for obtaining URL shortened. Are they:
- Bitly (https://bitly.com/)
- Googl (https://developers.google.com/url-shortener/v1/getting_started)
- IsGd (http://is.gd)
- MigreMe (http://migre.me/)
- TinyUrl (http://tinyurl.com/)
- TrIm (https://tr.im/links)
All of these providers work in a clear and objective manner to generate the urls, of course you must choose one or perhaps all for the generation of short url for your systems.
Quick start
Required setup
In the require key of composer.json file add the following
"canducci/shorten": "0.0.1"
Run the Composer update comand
$ composer update
In your config/app.php add providers array
'providers' => [ ..., Canducci\Shorten\Providers\ShortenServiceProvider::class,
At the end of config/app.php add o aliases (Facade) in array
'aliases' => [ ..., 'Shorten' => Canducci\Shorten\Facades\Shorten::class, 'IsGd' => Canducci\Shorten\Facades\IsGd::class, 'TinyUrl' => Canducci\Shorten\Facades\TinyUrl::class, 'TrIm' => Canducci\Shorten\Facades\TrIm::class, 'Googl' => Canducci\Shorten\Facades\Googl::class, 'MigreMe' => Canducci\Shorten\Facades\MigreMe::class, 'Bitly' => Canducci\Shorten\Facades\Bitly::class,
How to use?
Simple example using only one of the providers (IsGd):
$provider = IsGd::create('https://packagist.org/packages/canducci/shorten'); $shorten = Shorten::create($provider); $receive = $shorten->receive(); var_dump($receive); var_dump($receive->getLongUrl()); var_dump($receive->getShortUrl()); var_dump($receive->getProviderType()->getName()); var_dump($receive->getProviderType()->getAddress()); //results object(Canducci\Shorten\ShortenReceive)#225 (3) { ["longurl":protected]=> string(47) "https://packagist.org/packages/canducci/shorten" ["shorturl":protected]=> string(19) "http://is.gd/amftYu" ["providerType":protected]=> object(Canducci\Shorten\ShortenProviderType)#224 (2) { ["name":protected]=> string(4) "IsGd" ["address":protected]=> string(13) "http://is.gd/" } } string(47) "https://packagist.org/packages/canducci/shorten" string(19) "http://is.gd/amftYu" string(4) "IsGd" string(13) "http://is.gd/"
Injection Contracts
Route::get('shorten1', function( Canducci\Shorten\Contracts\IsGdContract $isgd, Canducci\Shorten\Contracts\TinyUrlContract $tinyurl, Canducci\Shorten\Contracts\MigreMeContract $migreme, Canducci\Shorten\Contracts\BitlyContract $bitly, Canducci\Shorten\Contracts\GooglContract $googl, Canducci\Shorten\Contracts\TrImContract $trim, Canducci\Shorten\Contracts\ShortenContract $shorten ) { $provider0 = $isgd->create('https://packagist.org/packages/canducci/shorten'); $provider1 = $tinyurl->create('https://packagist.org/packages/canducci/shorten'); $provider2 = $migreme->create('https://packagist.org/packages/canducci/shorten'); $provider3 = $bitly->create('https://packagist.org/packages/canducci/shorten','key_bitly'); $provider4 = $googl->create('https://packagist.org/packages/canducci/shorten','key_google'); $provider5 = $trim->create('https://packagist.org/packages/canducci/shorten','key_api'); $shorten0 = $shorten->create($provider0); $shorten1 = $shorten->newInstance()->create($provider1); $shorten2 = $shorten->newInstance()->create($provider2); $shorten3 = $shorten->newInstance()->create($provider3); $shorten4 = $shorten->newInstance()->create($provider4); $shorten5 = $shorten->newInstance()->create($provider5); echo $shorten0->receive()->getShortUrl(); echo '<br>'; echo $shorten1->receive()->getShortUrl(); echo '<br>'; echo $shorten2->receive()->getShortUrl(); echo '<br>'; echo $shorten3->receive()->getShortUrl(); echo '<br>'; echo $shorten4->receive()->getShortUrl(); echo '<br>'; echo $shorten5->receive()->getShortUrl(); return; });
Facades
$provider0 = IsGd::create('https://packagist.org/packages/canducci/shorten'); $provider1 = TinyUrl::create('https://packagist.org/packages/canducci/shorten'); $provider2 = MigreMe::create('https://packagist.org/packages/canducci/shorten'); $provider3 = Bitly::create('https://packagist.org/packages/canducci/shorten','key_bitly'); $provider4 = Googl::create('https://packagist.org/packages/canducci/shorten','key_google'); $provider5 = TrIm::create('https://packagist.org/packages/canducci/shorten','key_api'); $shorten0 = Shorten::create($provider0); $shorten1 = Shorten::newInstance()->create($provider1); $shorten2 = Shorten::newInstance()->create($provider2); $shorten3 = Shorten::newInstance()->create($provider3); $shorten4 = Shorten::newInstance()->create($provider4); $shorten5 = Shorten::newInstance()->create($provider5); echo $shorten0->receive()->getShortUrl(); echo '<br>'; echo $shorten1->receive()->getShortUrl(); echo '<br>'; echo $shorten2->receive()->getShortUrl(); echo '<br>'; echo $shorten3->receive()->getShortUrl(); echo '<br>'; echo $shorten4->receive()->getShortUrl(); echo '<br>'; echo $shorten5->receive()->getShortUrl();
Functions
$provider0 = isgd('https://packagist.org/packages/canducci/shorten'); $provider1 = tinyurl('https://packagist.org/packages/canducci/shorten'); $provider2 = migreme('https://packagist.org/packages/canducci/shorten'); $provider3 = bitly('https://packagist.org/packages/canducci/shorten','key_bitly'); $provider4 = googl('https://packagist.org/packages/canducci/shorten','key_google'); $provider5 = tr_im('https://packagist.org/packages/canducci/shorten','key_api'); $shorten0 = shorten($provider0); $shorten1 = shorten($provider1); $shorten2 = shorten($provider2); $shorten3 = shorten($provider3); $shorten4 = shorten($provider4); $shorten5 = shorten($provider5); echo $shorten0->receive()->getShortUrl(); echo '<br>'; echo $shorten1->receive()->getShortUrl(); echo '<br>'; echo $shorten2->receive()->getShortUrl(); echo '<br>'; echo $shorten3->receive()->getShortUrl(); echo '<br>'; echo $shorten4->receive()->getShortUrl(); echo '<br>'; echo $shorten5->receive()->getShortUrl();
Single Instance
$provider0 = new \Canducci\Shorten\IsGd('https://packagist.org/packages/canducci/shorten'); $provider1 = new \Canducci\Shorten\TinyUrl('https://packagist.org/packages/canducci/shorten'); $provider2 = new \Canducci\Shorten\MigreMe('https://packagist.org/packages/canducci/shorten'); $provider3 = new \Canducci\Shorten\Bitly('https://packagist.org/packages/canducci/shorten','key_bitly'); $provider4 = new \Canducci\Shorten\Googl('https://packagist.org/packages/canducci/shorten','key_google'); $provider5 = new \Canducci\Shorten\TrIm('https://packagist.org/packages/canducci/shorten','key_api'); $shorten0 = new \Canducci\Shorten\Shorten($provider0); $shorten1 = new \Canducci\Shorten\Shorten($provider1); $shorten2 = new \Canducci\Shorten\Shorten($provider2); $shorten3 = new \Canducci\Shorten\Shorten($provider3); $shorten4 = new \Canducci\Shorten\Shorten($provider4); $shorten5 = new \Canducci\Shorten\Shorten($provider5); echo $shorten0->receive()->getShortUrl(); echo '<br>'; echo $shorten1->receive()->getShortUrl(); echo '<br>'; echo $shorten2->receive()->getShortUrl(); echo '<br>'; echo $shorten3->receive()->getShortUrl(); echo '<br>'; echo $shorten4->receive()->getShortUrl(); echo '<br>'; echo $shorten5->receive()->getShortUrl();
Note
These three providers below must have a register in that site to be released to generate short url with token or key provided on the same register.
- Bitly (key_bitly) (https://bitly.com/)
- Googl (key_google) (https://developers.google.com/url-shortener/v1/getting_started)
- TrIm (key_api) (https://tr.im/links)
Different from the others only need to have information as to url so long to run the code successfully.
canducci/shorten 适用场景与选型建议
canducci/shorten 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 12 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「url」 「trim」 「bitly」 「googl」 「tinyurl」 「providers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 canducci/shorten 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 canducci/shorten 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 canducci/shorten 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dealing with Spaces in Form Inputs using Middleware in Lumen.
PHP helpers functions
Easy URL rewrites in your Laravel application
Provides hash tools for Laravel.
Behavior that truncates all spaces and other characters in all attributes in a model before validate
Object-oriented image handling and manipulation library
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-19