定制 sharelov/sharelov-shortener 二次开发

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

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

sharelov/sharelov-shortener

Composer 安装命令:

composer require sharelov/sharelov-shortener

包简介

A configurable tool for shortening urls inside a Laravel project.

README 文档

README

develop master
StyleCI CircleCI StyleCI CircleCI

Installation

Require the package with Composer:

composer require sharelov/sharelov-shortener

After that, add the ServiceProvider to the providers array in config/app.php

Sharelov\Shortener\ShortenerServiceProvider::class,

You can optionally use the facade. If you decide to use it, add this to your aliases array in config/app.php:

'Shortener'=>Sharelov\Shortener\Facades\Shortener::class,

Then, run composer dump-autoload.

Afterwards, run php artisan vendor:publish to get the migration and config files.

Configuration

The config file has important configuration you may want to look at and customize before running the migrations. If you haven't looked at it yet, you can customize the table name in the config file, so there will be no need to fiddle with the migration yourself. Once you make sure the table name will not cause conflicts with your existing tables, run php artisan migrate to install the table we use.

There is also the posibility to configure any of the following things:

  • Hash length. (Default = 5)
  • Maximum attempts at generating a unique hash. (Default = 3)
  • Usage of Soft Deletes with your short links model. (Default = false)

There is ample documentation for each option in the config file. Feel free to trim it down after having looked it over and setting it up.

Usage

Use this route to decode a shortened URL, if the URL doesn't exist it will run abort(404) otherwise it will perform a redirect to the stored url asociated with that hash.

Route::get('/sh/{hash}',[
    'as'=>'shortener.get',
    'uses'=>'\Sharelov\Shortener\Controllers\LinksController@translateHash'
]);

Use this route to shorten a URL, if the URL already exists on the database it will return the hash code otherwise it will create a new URL|Hash tuple and it will return a json response with the hash and the url with the current domain indicating the status of the request.

The url receives the following query parameters:

Url to process by the shortener: url=urltoshorten

Expiration date for the link expires_at=YYYY-MM-DD (don't specify this in order to make the link not expire)

You can have an example of the requests on this postman collection: PostMan Shortener Collection

Route::post('/sh',[
    'as'=>'shortener.store',
    'uses'=>'\Sharelov\Shortener\Controllers\LinksController@store'
]);

Succesfull json response

{
    "success": "true",
    "hash": "D7ZR6",
    "url": "http://sharelovdev.dev/sh/D7ZR6"
}

Unsuccessfull json response

{
    "success": "false",
    "hash": "",
    "url": ""
}

For using the facade don't forget to include it use Shortener; and then you can call the next methods:

Returns the hash for the url sended as a parameter and stores an object in the links table.

Shortener::make($url)

Returns the url corresponding to a hash string in the database.

Shortener::getUrlByHash($hash)

License

This Laravel package is licensed with the MIT License.

sharelov/sharelov-shortener 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-14