ticketpark / expiring-url-bundle
此包已被废弃,不再维护。未建议替代包。
创建在特定时间后过期的URL。
0.4
2015-07-20 13:41 UTC
Requires
- php: >=5.3.3
- apinstein/expiring-hash: dev-master
- symfony/framework-bundle: ~2.3
- symfony/yaml: ~2.3
- ticketpark/file-bundle: ~0.1
This package is not auto-updated.
Last update: 2022-02-01 12:33:51 UTC
README
此组件已不再维护。它速度较慢,且实现不佳。使用风险自负!
此Symfony2组件创建具有过期散列的URL。这允许URL在特定时间后失效。
示例
- URL模式
/some/url/{expirationHash}/{id}
- 生成的URL
/some/url/2014-04-03T10:41:40+02:00.eaf378321b86d7ab2edb320be1be48672eb107562a3c8cebd3bc804620e1f4fe/123
安装
在composer.json中添加TicketparkExcelBundle
{ "require": { "ticketpark/expiring-url-bundle": "0.2" } }
现在运行命令告诉composer下载组件
$ php composer.phar update ticketpark/expiring-url-bundle
在kernel中启用组件
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Ticketpark\ExpiringUrlBundle\TicketparkExpiringUrlBundle(), new Ticketpark\FileBundle\TicketparkFileBundle(), ); }
配置
默认情况下不需要配置。但是,您可以覆盖一些配置设置
# app/config/config.yml ticketpark_expiring_url: ttl: 10 # Default time-to-live of urls in minutes route_parameter: 'expirationHash' # Parameter for expiration hash to be used in routes
使用
简单使用
只需将过期散列参数添加到应过期的路由中。
# Acme/Bundle/Resources/config/routing.yml: expiring_route: pattern: /some/url/{expirationHash}/{id} defaults: { _controller: AcmeBundle:AcmeController:someAction }
创建路由时无需关心过期散列参数。这将自动完成。
示例
<?php namespace Acme\Bundle\AcmeBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class AcmeController extends Controller { public function fooAction() { //no need to add the 'expirationHash' parameter when generating urls $url = $this->get('router')->generate('expiring_route', array('id' => 123) ); // ... } }
高级使用
可以通过两个可选选项扩展路由定义
# Acme/Bundle/Resources/config/routing.yml: expiring_route: pattern: /some/url/{expirationHash}/{id} defaults: { _controller: AcmeBundle:AcmeController:someAction } options: expiring_url_identifier: 'id' expiring_url_ttl: 30
expiring_url_identifier
另一个URL参数,将用于创建更具体的过期散列。想象您创建了一个URL,如/some/url/{expirationHash}/123
。如果不添加标识符,该URL中的散列也将允许在允许的时间范围内访问/some/url/{expirationHash}/456
。添加expiring_url_identifier
选项确保只有/some/url/{expirationHash}/123
可访问(以及使用相同标识符的任何其他URL),因为将创建更具体的过期散列。expiring_url_ttl
此URL的存活时间(分钟)。覆盖默认存活时间。
许可
此组件在MIT许可下。请参阅组件中的完整许可
Resources/meta/LICENSE