在使用hautelook/alice-bundle时无法加载自定义处理器。
In my services.yml:
alice.processor.attendance:
class: MyVendorMyBundleDataFixturesProcessorAttendanceProcessor
arguments: [ "@doctrine.orm.my_entity_manager","@doctrine.orm.second_entity_manager" ]
tags: [ { name: hautelook_alice.alice.processor } ]
我在MyVendor/MyBundle中的文件夹结构:
DataFixtures
| Faker
| ORM
| attendance.yml
| AppFixtures.php
| Processor
| AttendanceProcessor.php
在AttendanceProcessor.php中:
<?php
namespace MyVenderMyBundleDataFixturesProcessor;
use NelmioAliceProcessorInterface;
use IshaHRBundleEntityAttendance;
class AttendanceProcessor implements ProcessorInterface
{
protected $em;
protected $suvyaEm;
public function __construct($suvyaEm,$em)
{
var_dump("hello3");
die();
$this->em = $em;
$this->suvyaEm = $suvyaEm;
}
/**
* {@inheritdoc}
*/
public function preProcess($object)
{
var_dump("hello1");
if (false === $object instanceof Attendance) {
return;
}
var_dump("hello1");
die();
}
/**
* {@inheritdoc}
*/
public function postProcess($object)
{
var_dump("hello2");
die();
}
}
最后在AppFixtures.php
<?php
namespace MyVenderMyBundleDataFixturesORM;
use HautelookAliceBundleDoctrineDataFixturesAbstractLoader;
use IshaHRBundleDataFixturesProcessorAttendanceProcessor;
use NelmioAliceFixtures;
class AppFixtures extends AbstractLoader
{
/**
* {@inheritDoc}
*/
public function getFixtures()
{
return array(
__DIR__ . '/attendance.yml',
);
}
}
服务标签似乎在某些时候发生了变化,当我设置标签fidry_alice_data_fixtures.processor
时,它为我工作。