fabstei/shorturl-bundle

此包已被弃用且不再维护。未建议替代包。

为您的 Symfony2 项目提供短网址服务。

安装次数: 2,480

依赖者: 0

建议者: 0

安全: 0

星标: 12

关注者: 4

分支: 2

开放问题: 2

类型:symfony-bundle

0.2.0 2014-01-20 12:10 UTC

This package is auto-updated.

Last update: 2022-04-22 12:23:31 UTC


README

SensioLabsInsight

Build Status

注意:此包处于开发中。可能会有所变动,也可能出现错误。《反馈》非常受欢迎!

关于

此包允许您

  • 生成短网址
  • 管理从短网址到长网址的重定向

该包基于 Jonathan Snook 的短网址类。

安装

使用 Composer,添加到 composer.json

{
    "require": {
        "fabstei/shorturl-bundle": "0.2.0"
    }
}

然后安装/更新您的供应商

php composer.phar update

将包添加到您的 AppKernel.php

new Fabstei\ShorturlBundle\FabsteiShorturlBundle(),

更新您的 doctrine 数据库模式 (doctrine:schema:update --force)

从 routing.yml 导入路由

# Redirection from short to long urls
redirect:
    resource: "@FabsteiShorturlBundle/Resources/config/routing/redirect.yml"
    #hostname_pattern: example.com
    #prefix: /shorturls

# Shorturl management
shorturl:
    resource: "@FabsteiShorturlBundle/Resources/config/routing/url.yml"

可选的 主机名模式(新功能,Symphony 2.2 中提供)允许您为短网址使用单独的域名。

配置

该包提供合理的默认值,但可能需要自定义用于生成唯一标记(用作短网址)的代码集。

fabstei_shorturl:
    codeset: abcABC123-_! # Default: abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789

使用

该包包含两个服务

它还提供了一个控制器来处理重定向,以及一个控制器、视图和表单来管理重定向(默认情况下可通过 /url-manager 访问)。可以使用自定义短网址替换默认标记(从重定向 ID 计算得出)。此外,您可以在存储的长网址中使用 _locale,它在重定向时会被当前请求的区域设置替换。

这两个服务也可以通过 CLI 命令访问

php app/console fabstei:shorturl:add    # Add a long url, returns the short token
php app/console fabstei:shorturl:get    # Retrieve a long url associated with a token
php app/console fabstei:shorturl:update # Update the long url associated with a token
php app/console fabstei:shorturl:remove # Remove a redirection
php app/console fabstei:shorturl:list   # Get a list of all stored redirections

php app/console fabstei:token:codeset   # Get the codeset used to generate tokens
php app/console fabstei:token:encode    # Calculate a token from an integer
php app/console fabstei:token:decode    # Calculate the integer from a given token

待办事项

  • 添加适当的测试
  • 提高代码质量

依赖项

鸣谢