Search code examples
phpsymfonydoctrine-ormbridge

How to register a bridge in symfony2?


I was trying to setup metabor/statemachine-doctrine-bridge within a symfony2 project. I am used to register new bundles, yet I have no clue how I would get symfony2 to find the bridge.

I tried including it via use statement but it seems to be not enough resulting in the error:

 [Doctrine\Common\Persistence\Mapping\MappingException]                                                                                                              
  The class 'Metabor\Bridge\Doctrine\Statemachine\State' was not found in the chain configured namespaces Hn\AssetDbBundle\Entity, Hn\UserBundle\Entity, FOS\UserBun  
  dle\Entity, FOS\UserBundle\Model 

Solution

  • One needs to both configure the autoloader and point doctrine to the correct entities.

    app/config.yml:

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
        mappings:
            MetaborBridge:
                type: annotation
                dir: %kernel.root_dir%/../vendor/metabor/statemachine-doctrine-bridge/src/Metabor
                prefix: Metabor
                is_bundle: false 
    

    composer.json:

    ...
    "autoload": {
        "psr-0": {
            "": "src/",
            "Metabor": "vendor/metabor/statemachine-doctrine-bridge/src/Metabor/",
            "MetaborStd": "vendor/metabor/metabor-std/src/MetaborStd/"
        }
    },
    ...