Skip to content

Commit

Permalink
Merge pull request #274 from theofidry/patch-1
Browse files Browse the repository at this point in the history
Change processor doc
  • Loading branch information
Seldaek committed Sep 30, 2015
2 parents db00d24 + 52d4b9c commit 977e5cf
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions doc/processors.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
# Processors

Processors allow you to process objects before and/or after they are persisted. Processors
must implement the `ProcessorInterface`.
must implement the [`Nelmio\Alice\ProcessorInterface`](../src/Nelmio/Alice/ProcessorInterface.php).

Here is an example where we may use this feature to make sure passwords are properly
hashed on a `User`:

```php
namespace Acme\DemoBundle\DataFixtures\ORM;
namespace MyApp\DataFixtures\Processor;

use Nelmio\Alice\ProcessorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use MyApp\Hasher\PasswordHashInterface;
use User;

class UserProcessor implements ProcessorInterface
{
/**
* @var ContainerInterface
* @var PasswordHashInterface
*/
protected $container;
protected $passwordHasher;

/**
* @param ContainerInterface $container
* @param PasswordHashInterface $passwordHasher
*/
public function __construct(ContainerInterface $container)
public function __construct(PasswordHashInterface $passwordHasher)
{
$this->container = $container;
$this->passwordHasher = $passwordHasher;
}

/**
* {@inheritdoc}
*/
public function preProcess($object)
{

}

/**
* {@inheritdoc}
*/
public function postProcess($object)
{
if (!($object instanceof User)) {
if (false === $object instanceof User) {
return;
}

$hasher = $this->container->get('example_password_hasher');
$object->password = $hasher->hash($object->password);
$object->passwordHasher = $this->passwordHasher->hash($object->password);
}
}
```
Expand All @@ -56,7 +54,7 @@ You can add a list of processors in the load method, e.g.
$objects = \Nelmio\Alice\Fixtures::load(__DIR__.'/fixtures.yml', $objectManager, $options, $processors);
```

Or, you can add them to your loader using the `addProcessor()` method, e.g.
Or, you can add them to your loader using the `::addProcessor()` method, e.g.

```php
$loader = new \Nelmio\Alice\Fixtures($objectManager, $options);
Expand Down

0 comments on commit 977e5cf

Please sign in to comment.