du127953 2017-03-13 17:14
浏览 26

无法注册自定义DBAL类型

I'm trying to register a bunch of custom DBAL types. When I run the migrations:diff I get the exception:

Fatal error: Class 'App\Persistence\Models\Types\Money' not found in D:\development\projects\project\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\Type.php on line 174

I've tried to do this either by registering it after all Doctrine settings and using a event subscriber:

class DoctrineCustomTypesEventSubscriber implements Subscriber {

    public function getSubscribedEvents() {
        return [Events::postConnect];
    }

    public function postConnect(ConnectionEventArgs $args) {
        Type::addType('money', "App\Persistence\Models\Types\Money");
        Type::addType('geopoint', "App\Persistence\Models\Types\Point");
        Type::addType('geoarea', "App\Persistence\Models\Types\Area");
    }

}

$doctrineCustomTypesSubscriber = new App\Persistence\DoctrineCustomTypesEventSubscriber();
$app['db.event_manager']->addEventSubscriber($doctrineCustomTypesSubscriber);

$app->register(new Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array(
    'orm.proxies_dir' => $app['APP_ROOT_DIR'].'/app/persistence/proxies',
    'orm.em.options' => array(
        'mappings' => array(
            array(
                'type' => 'annotation',
                'namespace' => 'App\Persistence\Models',
                'path' => $app['APP_ROOT_DIR'].'/app/persistence/models',
                'use_simple_annotation_reader' => false,
            ),
        ),
    ),
));

Update

Placing the registration before all orm settings doesn't work either:

use Doctrine\DBAL\Types\Type;

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
    'db.options' => array('url' => $app['APP_DB_CONN_URL']),
));

Type::addType('money', "App\Persistence\Models\Types\Money");
Type::addType('geopoint', "App\Persistence\Models\Types\Point");
Type::addType('geoarea', "App\Persistence\Models\Types\Area");

What am I doing wrong here?


Also can you tell me where do I put these registrations:

$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping(...)?
  • 写回答

1条回答 默认 最新

  • dongyang2229 2017-03-13 17:41
    关注

    The type classes should exist and be registered in autoloader, so that they can be instantiated by FQCN associated with type.

    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私