nelmio/alice — pull request #14 by kbond (2012-12-09 21:31:12+00:00)
Title: [RFC] added ability to use custom persisters

When using the FOSUserBundle, you are required to use the `UserManager` to persist users. This causes an issue for this library.

This solution is a little hackish but I think it gets my requirement across.

### Usage

Create a custom persister class:

```php
class UserPersister implements PersisterInterface
{
protected $manager;

public function __construct(UserManager $manager)
{
$this->manager = $manager;
}

public function persist($object)
{
$this->manager->updateUser($object);
}
}
```

Add `_persister` key to your fixture file:

```yaml
MyApp\UserBundle\Entity\User:
user0:
username: kevin
plainPassword: pass
email: kevinbond@gmail.com
enabled: true
_persister: user
```

Load fixtures:

```php
$userManager = $container->get('fos_user.user_manager');

$userPersister = new \eBirdr\AppBundle\Alice\UserPersister($userManager);

// add data fixtures
\Nelmio\Alice\Fixtures::load(array(
$fixtureDir.'/users.yml'
),
$em,
array(),
array('user' => $userPersister)
);
```

Thoughts?