jlaso / jaitec-alias
简单的别名生成器
dev-master
2017-10-17 09:39 UTC
This package is auto-updated.
Last update: 2024-09-15 11:56:51 UTC
README
此包提供了生成伪随机别名的辅助工具。
安装
将 AliasBundle 添加到 vendor/bundles/ 目录
::
$ git submodule add git://github.com/jlaso/JaitecAliasBundle.git vendor/bundles/Jaitec/AliasBundle
或添加以下内容到 deps
[JaitecAliasBundle]
git=http://github.com/jlaso/JaitecAliasBundle
target=/bundles/Jaitec/AliasBundle
并运行
$ php bin/vendors install
将 Jaitec 命名空间添加到您的自动加载器
::
// app/autoload.php
$loader->registerNamespaces(array(
'Jaitec' => __DIR__.'/../vendor/bundles',
// your other namespaces
);
将 AliasBundle 添加到您的应用程序内核
::
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Jaitec\AliasBundle\JaitecAliasBundle(),
// ...
);
}
用法
AliasBundle 提供此服务以生成伪随机别名
jaitec_alias.main
实现AliasGeneratorInterface
除了这些专业服务之外,您还可以注入 jaitec_alias.main
,它提供对所有其他服务的快捷方式,并允许您仅注入一个依赖项。
示例
例如,根据 mysql 表中的行 ID 生成 URL 的别名
首先通过依赖注入获取对象
$this->alias = $this->container->get('jaitec_alias.main');
现在生成别名
$alias = $this->alias->encode($record->getId(),4);