我正在尝试注册一堆自定义 dbal 类型。当我运行 migrations:diff
时,我会得到例外:
致命错误:class'app persistence models types types type chony'在d中找不到: type.php 174
我尝试通过在所有学说设置后注册并使用事件订户来进行此操作:
class DoctrineCustomTypesEventSubscriber implements Subscriber {
public function getSubscribedEvents() {
return [Events::postConnect];
}
public function postConnect(ConnectionEventArgs $args) {
Type::addType('money', "AppPersistenceModelsTypesMoney");
Type::addType('geopoint', "AppPersistenceModelsTypesPoint");
Type::addType('geoarea', "AppPersistenceModelsTypesArea");
}
}
$doctrineCustomTypesSubscriber = new AppPersistenceDoctrineCustomTypesEventSubscriber();
$app['db.event_manager']->addEventSubscriber($doctrineCustomTypesSubscriber);
$app->register(new DflydevProviderDoctrineOrmDoctrineOrmServiceProvider, array(
'orm.proxies_dir' => $app['APP_ROOT_DIR'].'/app/persistence/proxies',
'orm.em.options' => array(
'mappings' => array(
array(
'type' => 'annotation',
'namespace' => 'AppPersistenceModels',
'path' => $app['APP_ROOT_DIR'].'/app/persistence/models',
'use_simple_annotation_reader' => false,
),
),
),
));
update
将注册放置在所有ORM设置之前都无法正常工作:
use DoctrineDBALTypesType;
$app->register(new SilexProviderDoctrineServiceProvider(), array(
'db.options' => array('url' => $app['APP_DB_CONN_URL']),
));
Type::addType('money', "AppPersistenceModelsTypesMoney");
Type::addType('geopoint', "AppPersistenceModelsTypesPoint");
Type::addType('geoarea', "AppPersistenceModelsTypesArea");
我在这里做错了什么?
您还可以告诉我我要放在哪里注册:
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping(...)?
类型类应该存在并在自动加载器中注册,以便可以通过与类型相关的FQCN实例化。