定制 codeofdigital/laravel-url-shortener 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

codeofdigital/laravel-url-shortener

Composer 安装命令:

composer require codeofdigital/laravel-url-shortener

包简介

Powerful URL shoterning tools using different drivers for your Laravel projects

README 文档

README

Powerful URL shortening tool using different drivers for your Laravel projects

Latest Version on Packagist Latest Release on GitHub Build Status PHP from Packagist GitHub license

Table of Contents

Overview

A Laravel package that is used to shorten URLs according to your needs using your desired URL shortening drivers. Every driver will provide different features and function so do please check their documentation and pricing for different usages.

Installation

Requirements

The package has been developed to work with the following versions and minimum requirements:

  • PHP 7.2 or higher
  • Laravel 6.0 or higher

Install Pacakge

You can install the package via the latest Composer:

composer require codeofdigital/laravel-url-shortener

Publish Config

You can then publish the package's config file by using the following command:

php artisan vendor:publish --provider="CodeOfDigital\LaravelUrlShortener\UrlShortenerServiceProvider"

Usage

The quickest way to get started with creating a shortened URL is by using the snippet below. The shorten() method will return a shortened URL link, and you can freely use it within your system.

$shortUrl = new UrlShortener();
$shortUrl->shorten('https://example.com');

Instantiate Shortener

The URL Shortener can be retrieved from the container in few ways:

$shortener = app('url.shortener');
// or ...
$shortener = url()->shortener();

This package also comes with the URL Shortener facade to instantiate the class:

use CodeOfDigital\LaravelUrlShortener\Facades\UrlShortener;

$shortUrl = UrlShortener::shorten('https://example.com');

You can also use dependency injection to inject in one of your controller's method:

use CodeOfDigital\LaravelUrlShortener\UrlShortener;

class MyController extends Controller
{
    public function myFunction(UrlShortener $shortener)
    {
        $shortener->shorten('https://example.com');
    }
}

Once you have instantiate the URL Shortener class, you can use the methods and shorten your URLs:

// This will set and create the driver instance
$shortener->driver('own-driver');

// This will return shortened URL in string
$shortener->shorten('https://example.com');

// This will return a promise object which can be used to resolve and retrieve shortened URL later on
$shortener->shortenAsync('https://example.com');

// Methods can be called from Laravel URL components
url()->shorten('https://example.com');

// Or
app('url.shortener')->shorten('https://example.com');

// Methods can be chained as well
$shortener->driver('own-driver')->shorten('https://example.com');

The URL Shortener provides the following methods to use:

Method Description
shorten Shorten the given URL
shortenAsync Shorten the given URL asynchronously
driver Set the driver and create the driver instance

Changing Driver

You can change the default driver by setting URL_SHORTENER_DRIVER={driver} in your environment file or publish the config file and make your changes there directly.

Available Drivers

There are total of 8 drivers available in this package. By default, this package will use Bit.ly as the main driver. Below is a list of drivers with their respective specs:

Service API Token Driver name Analytics Monetization
Bit.ly yes bit_ly yes no
TinyURL yes tiny_url no no
Shorte.st yes shorte_st yes yes
Is.gd no is_gd yes no
Cutt.ly yes cutt_ly yes no
HideUri no hide_uri no no
Firebase Links yes firebase yes no
Ouo.io no ouo_io yes yes

Bit.ly

Official Website

The main default driver for this package. It runs on Bit.ly API and currently using Version 4. To access the Bit.ly driver in this package, you need to provide generic access token for OAuth Authentication which can be retrieved in their Bit.ly Link Management Dashboard. You can parse in your own custom short URL domain (Paid Version) as well. Currently, there are 2 variables that needs to be set to use the driver.

Variable Description
URL_SHORTENER_API_TOKEN Bit.ly API token
URL_SHORTENER_PREFIX Custom short URL domain, by default it's bit.ly

TinyURL

Official Website

Driver that runs on TinyURL API and currently using Version 2. To access the TinyURL driver in this package, you need to provide the API token for OAuth Authentication which can be retrieved in the TinyURL's account setting. You can parse in your own custom short URL domain (Paid Version) as well. TinyURL provides 3 free custom URL domain prefix which you can check out at their website. Currently, there are 2 variables that needs to be set to use the driver.

Variable Description
URL_SHORTENER_API_TOKEN TinyURL API token
URL_SHORTENER_PREFIX Custom short URL domain, by default it's tinyurl.com

Shorte.st

Official Website

Driver that runs on Shorte.st API and currently using Version 1. To access the Shorte.st driver in this package, you need to provide an access token which can be retrieved after you have register for a Shorte.st account. This driver has monetization support where each link that has been clicked will earn a small amount of cash. Currently, there are only 1 variable that needs to be set to use the driver.

Variable Description
URL_SHORTENER_API_TOKEN Shorte.st API token

Is.gd

Official Website

Driver that runs on Is.gd API and currently using Version 1. No API token is needed for this API as there is no authentication required when sending API request. Currently, there are only 1 variable that needs to be set to use the driver. This variable determines whether statistic is enabled or disabled when shorten an URL link.

Variable Description
URL_SHORTENER_ANALYTICS Enable or disable statistics

Cutt.ly

Official Website

Driver that runs on Cutt.ly API and currently using Version 1. To access the Cutt.ly driver in this package, you need to provide an API token which can be retrieved in Cutt.ly dashboard. API token will be used within the query parameters as a method of authentication. This driver comes with analytics and statistics. Currently, there are only 1 variable that needs to be set to use the driver.

Variable Description
URL_SHORTENER_API_TOKEN Cutt.ly API token

Hide.uri

Official Website

Driver that runs on Hide.uri API and currently using Version 1. No API token is needed for this API as no authentication is required when sending API request. No variable is needed to setup the driver and you can use straight out of the box. Check the official website if there is any rate limiting on API calls.

Firebase Links

Official Website

Driver that runs on Google Firebase API and currently using Version 1. To access the Firebase driver in this package, you need to provide an access token and a URI prefix which can be retrieved in your Firebase console Web API Token. The URI prefix can be set using your own custom domain or any names and it must ends with .page.link. The suffix can have the value SHORT or UNGUESSABLE.

Variable Description
URL_SHORTENER_API_TOKEN Firebase API token
URL_SHORTENER_PREFIX Custom URL prefix
URL_SHORTENER_SUFFIX Creation method during URL shortening

Ouo.io

Official Website

Driver that runs on Ouo.io API and currently using Version 1. To access the Ouo.io driver in this package, provide the API token that is available in the Ouo.io account dashboard. This driver has monetization support where each link that has been clicked will earn a small amount of cash.

Variable Description
URL_SHORTENER_API_TOKEN Ouo.io API token

Changelog

Please see CHANGELOG for more information what has been changed in recent versions.

Security

If you discover any security related issues, please email one of the authors instead of using the issue tracker. You can find the author emails in the composer.json.

Credits

License

The MIT License (MIT). Please see License File for more information.

codeofdigital/laravel-url-shortener 适用场景与选型建议

codeofdigital/laravel-url-shortener 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 123 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「url」 「shortener」 「shortening」 「laravel」 「bit.ly」 「tinyurl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 codeofdigital/laravel-url-shortener 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codeofdigital/laravel-url-shortener 我们能提供哪些服务?
定制开发 / 二次开发

基于 codeofdigital/laravel-url-shortener 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-14