fabstei / shorturl-bundle
此包已被弃用且不再维护。未建议替代包。
为您的 Symfony2 项目提供短网址服务。
0.2.0
2014-01-20 12:10 UTC
Requires
- php: >=5.3.2
- doctrine/orm: >=2.1.0
- gedmo/doctrine-extensions: >=2.2.0
- symfony/framework-bundle: 2.*
- symfony/symfony: >=2.1.0
This package is auto-updated.
Last update: 2022-04-22 12:23:31 UTC
README
注意:此包处于开发中。可能会有所变动,也可能出现错误。《反馈》非常受欢迎!
关于
此包允许您
- 生成短网址
- 管理从短网址到长网址的重定向
该包基于 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
使用
该包包含两个服务
- fabstei_shorturl.tokenizer 用于生成短网址的标记(例如 example.com/a3x)
- fabstei_shorturl.manager 用于管理重定向(存储长网址及其相关标记)
它还提供了一个控制器来处理重定向,以及一个控制器、视图和表单来管理重定向(默认情况下可通过 /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
待办事项
- 添加适当的测试
- 提高代码质量
依赖项
鸣谢
- Jonathan Snook 提供了基础类。
- Tim Nagel 在 IRC 上提供帮助和代码示例。
- 学习最佳代码,请访问FriendsOfSymfony;对象管理器请访问FOSUserBundle。