shivella/laravel-bitly
Composer 安装命令:
composer require shivella/laravel-bitly
包简介
Laravel package for generating bitly url
README 文档
README
A laravel package for generating Bitly short URLs.
For more information see Bitly
Requirements
Laravel 5.1 or later
Installation
Installation is a quick 3 step process:
- Download laravel-bitly using composer
- Enable the package in app.php
- Configure your Bitly credentials
- (Optional) Configure the package facade
Step 1: Download laravel-bitly using composer
Add shivella/laravel-bitly by running the command:
composer require shivella/laravel-bitly
Step 2: Enable the package in app.php
Register the Service in: config/app.php
Shivella\Bitly\BitlyServiceProvider::class,
Step 3: Configure Bitly credentials
php artisan vendor:publish --provider="Shivella\Bitly\BitlyServiceProvider"
Add this in you .env file
BITLY_ACCESS_TOKEN=your_secret_bitly_access_token
Step 4 (Optional): Configure the package facade
Register the Bitly Facade in: config/app.php
<?php return [ 'aliases' => [ 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, // ... 'Bitly' => Shivella\Bitly\Facade\Bitly::class, ], // ... ];
Usage
<?php $url = app('bitly')->getUrl('https://www.google.com/'); // http://bit.ly/nHcn3
Or if you want to use facade, add this in your class after namespace declaration:
<?php use Bitly;
Then you can use it directly by calling Bitly:: like:
<?php $url = Bitly::getUrl('https://www.google.com/'); // http://bit.ly/nHcn3
Testing
In your unit tests you may use BitlyClientFake class instead of regular client.
It will create a fake short URLs using hashing without calling an external REST API, which will speed up your unit tests.
Fake might be setup via DI at your \Tests\TestCase::createApplication() implementation:
<?php namespace Tests; use Illuminate\Contracts\Console\Kernel; use Shivella\Bitly\Testing\BitlyClientFake; trait CreatesApplication { /** * Creates the application. * * @return \Illuminate\Foundation\Application */ public function createApplication() { $app = require __DIR__.'/../bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); // swap Bitly client by a fake $app->singleton('bitly', function () { return new BitlyClientFake(); }); return $app; } }
As an alternative you may use \Shivella\Bitly\Facade\Bitly::fake() method to swap regular client by a fake.
shivella/laravel-bitly 适用场景与选型建议
shivella/laravel-bitly 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 859.15k 次下载、GitHub Stars 达 74, 最近一次更新时间为 2016 年 12 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「url」 「link」 「bitly」 「laravel」 「short」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shivella/laravel-bitly 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shivella/laravel-bitly 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shivella/laravel-bitly 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A couple of handy form fields and objects for managing external and internal links on DataObjects
PHP library that allows linking queries from diferent physical databases using mysql pdo database connections
Custom links on your sidebar for Laravel Nova.
Set Links with a specific language parameter
Easy URL rewrites in your Laravel application
A tool for scraping URL resources (oEmbed, OpenGraph, Twitter cards, JSON-LD)
统计信息
- 总下载量: 859.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 75
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-19