https://github.com/bpolaszek/userawarecommandbundle
Provides a user value to Doctrine Entities that implements Gedmo Blameable when using Console commands.
https://github.com/bpolaszek/userawarecommandbundle
Last synced: 2 months ago
JSON representation
Provides a user value to Doctrine Entities that implements Gedmo Blameable when using Console commands.
- Host: GitHub
- URL: https://github.com/bpolaszek/userawarecommandbundle
- Owner: bpolaszek
- Created: 2016-08-02T14:27:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-04-13T20:28:12.000Z (over 3 years ago)
- Last Synced: 2024-10-12T11:15:26.713Z (over 1 year ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
UserAwareCommandBundle
======================
This Symfony bundle provides a user value to Doctrine Entities that implements [Gedmo Blameable](https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/blameable.md) when using Console commands.
Installation
------------
`composer require bentools/user-aware-command-bundle`
Then, enable the bundle into Symfony's AppKernel.php:
```php
# app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
// ...
$bundles[] = new BenTools\UserAwareCommandBundle\UserAwareCommandBundle();
}
}
```
Usage
-----
The bundle just works out of the box, provided you already have the Blameable extension configured and working on your entities.
Your console command just has to implement `BenTools\UserAwareCommandBundle\Model\UserAwareInterface`, which contains no method:
```php
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) {
// ...
}
}
```
By default, the bundle will bind the `System` user to your *createdBy* / *updatedBy* properties.
You can change this user per command run with the *--user* option:
`php bin/console do:mycommand --user Ben`
Advanced configuration
----------------------
```yaml
# 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
```