定制 fasaya/url-shortener 二次开发

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

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

fasaya/url-shortener

最新稳定版本:v1.0.0

Composer 安装命令:

composer require fasaya/url-shortener

包简介

A simple url shortener library for Laravel projects.

README 文档

README

Latest Version on Packagist Total Downloads

This is a package to shorten your url and manage your shorten urls

Installation

You can install the package via composer:

composer require fasaya/url-shortener

You can publish and run the migrations with:

php artisan vendor:publish --tag="url-shortener-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="url-shortener-config"

This is the contents of the published config file:

return [

    /**
     * Here you may specify the fully qualified class name of the user model class.
     */
    'user-model' => App\Models\User::class,

    /**
     * Maximum character length of shortened url slug
     */
    'min-length' => 6,

    /**
     * Maximum character length of shortened url slug
     */
    'max-length' => 10,

    /**
     * URL route for the shortened URL
     * Example
     *  'prefix' => '/l', // https://yourdomain.com/l/exampleString
     */
    'route' => [
        'prefix' => '/l',
        'middleware' => [
            // 'web',
        ],
    ],

    /**
     * Where should the admin route be?
     */
    'admin-route' => [
        'enabled' => true, // Should the admin routes be enabled?
        'as' => 'url-shortener-manager.',
        'prefix' => 'url-shortener-manager',
        'middleware' => [
            'web',
        ],
    ],

    /**
     * Admin Template
     * example
     * 'name' => 'layouts.app' for Default urlShortener use 'url-shortener::layouts.app'
     * 'section' => 'content' for Default urlShortener use 'content'
     * 'styles_section' => 'page_style' for Default urlShortener use 'page_style'
     * 'script_section' => 'page_script' for Default urlShortener use 'page_script'
     */
    'admin-template' => [
        'name' => 'url-shortener::layouts.app',
        'section' => 'content',
        'styles_section' => 'page_style',
        'script_section' => 'page_script',
    ],

    /**
     * Number of emails per page in the admin view
     */
    'links-per-page' => 30,

    /**
     * Date Format
     */
    'date-format' => 'm/d/Y g:i a',

];

Optionally, you can publish the url shortener manager dashboard views using

php artisan vendor:publish --tag="url-shortener-views"

Usage

use Fasaya\UrlShortener\UrlShortener;

// Add an expiration date (optional)
$expire_at = '2025-12-12 00:00:00'; // NULL for no expiration date

// Generate a random short URL
$link = UrlShortener::make('http://example.com', $expire_at)->short_url;

// Generate a custom short URL
$link = UrlShortener::make('http://example.com', 'custom-short-slug', $expire_at)->short_url; 

Exceptions

The following exceptions may be thrown. You may add them to your ignore list in your exception handler, or handle them as you wish.

  • Fasaya\UrlShortener\Exceptions\UrlNotValidException - Not a valid URL.
  • Fasaya\UrlShortener\Exceptions\UrlExistsException - URL already exists and active.
  • Fasaya\UrlShortener\Exceptions\TriesLimitReachedException - Generating reached tries limit.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-28