bentools/user-aware-command-bundle

为使用控制台命令时实现 Gedmo Blameable 的 Doctrine 实体提供用户值。

安装量: 19,856

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 3

分支: 1

开放问题: 0

类型:symfony-bundle

v1.0.1 2016-08-23 12:36 UTC

This package is auto-updated.

Last update: 2024-09-14 01:42:40 UTC


README

此 Symfony 扩展为使用控制台命令时实现 Gedmo Blameable 的 Doctrine 实体提供用户值。

安装

composer require bentools/user-aware-command-bundle

然后,在 Symfony 的 AppKernel.php 中启用此扩展

# app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles() 
    {
        // ...
        $bundles[] = new BenTools\UserAwareCommandBundle\UserAwareCommandBundle();
    }
}

使用方法

该扩展无需配置即可直接使用,前提是您已经为您实体配置并启用了 Blameable 扩展。您的控制台命令只需要实现 BenTools\UserAwareCommandBundle\Model\UserAwareInterface 接口,该接口不包含任何方法。

namespace AppBundle\Command;

use BenTools\UserAwareCommandBundle\Model\UserAwareInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class DoMyCommand extends Command implements UserAwareInterface 
{
    protected function execute(InputInterface $input, OutputInterface $output) {
	    // ...
	}
}

默认情况下,该扩展会将 System 用户绑定到您的 createdBy / updatedBy 属性。

您可以使用 --user 选项在每个命令执行期间更改此用户

php bin/console do:mycommand --user Ben

高级配置

# app/config.yml

user_aware_command:
    user_name: System # change default user
    option_name: user # change default command option
    option_shortcut: u # set option shortcut