定制 horde/service_urlshortener 二次开发

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

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

horde/service_urlshortener

最新稳定版本:v3.0.0alpha4

Composer 安装命令:

composer require horde/service_urlshortener

包简介

URL shortening library

README 文档

README

Modern PHP library for URL shortening services with native PSR-7/PSR-17/PSR-18 support.

Installation

composer require horde/service-urlshortener

Requirements

  • PHP 8.1+
  • PSR-18 HTTP client implementation
  • PSR-17 HTTP factory implementation

Quick Start

use Horde\Service\UrlShortener\TinyUrl;
use Horde\Service\UrlShortener\ValueObject\LongUrl;

// Simple facade API
$shortener = new TinyUrl($httpClient, $requestFactory);
$shortUrl = $shortener->shorten('https://www.example.com/very/long/url');
echo $shortUrl; // https://tinyurl.com/abc123

// Rich domain API with metadata
$longUrl = LongUrl::fromString('https://www.example.com/very/long/url');
$result = $shortener->shortenWithMetadata($longUrl);

echo $result->getShortUrl()->toString();
echo "Saved: {$result->getPercentageSaved()}%";
echo "Reduction: {$result->getLengthReduction()} characters";

Configuration

use Horde\Service\UrlShortener\ValueObject\ShortenerConfig;

$config = ShortenerConfig::default()
    ->withTimeout(30)
    ->withCustomAlias('myalias')
    ->withExpiration(14); // days

$shortener = new TinyUrl($httpClient, $requestFactory, $config);

Architecture

This library provides two API levels for progressive disclosure:

Facade API

Simple string-based interface for basic usage:

shorten(string|UriInterface $url): string

Domain API

Rich value objects with detailed metadata:

shortenWithMetadata(LongUrl $url): ShorteningResult

Value Objects

  • LongUrl - Input URL with validation and parsing
  • ShortUrl - Output short URL with service metadata
  • ShorteningResult - Complete result with metrics (length reduction, expiration, etc.)
  • ShortenerConfig - Immutable configuration with fluent interface

Supported Services

  • TinyURL (built-in)
  • Extensible via UrlShortenerInterface

Exception Handling

use Horde\Service\UrlShortener\UrlShortenerException;

try {
    $shortUrl = $shortener->shorten($longUrl);
} catch (UrlShortenerException $e) {
    // Handle shortening failures
}

Legacy Support

The PSR-0 lib/ directory provides backward compatibility wrappers for Horde 5 applications. New code should use the modern Horde\Service\UrlShortener namespace.

Documentation

License

LGPL 2.1 - See LICENSE file for details.

Contributing

Contributions are welcome! Please follow:

  • PHP 8.2+ with strict types
  • PER-1 coding style
  • Comprehensive unit tests
  • Conventional Commits for commit messages

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 5
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1-only
  • 更新时间: 2023-12-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固