Add Class into uses section in Propel behavior

147 Views Asked by At

That's it. I created behavior and only some of its classes are added into head with use due to my behavior.

E.g. behavior creates new table named acme. Propel generator adds to my Foo class (app/propel/AppPropelModel/AcmeBundle/om/BaseFoo.php) AcmeBehavior and AcmeBehaviorQuery, but not AcmeBehaviorPeer.

I don't want to mess with full class name in behaviour-building class AcmeBehaviorObjectBuilderModifier.php How could I make Propel add use AppPropelModel\HornsAndHooves\AcmeBundle\AcmeBehaviorPeer to the destination class file as well?

1

There are 1 best solutions below

0
zebra On

If you use a class and want to add it to "use" block, you have to declare that class in the builder. Just call declareClass in this function with your full namespace:

class MyBehavior extends Behavior {
    ...

    public function objectMethods($builder)
    {
        $builder->declareClass('MyNamespace\\MyBundle\\Subfolder');
    }
}

This will result:

use MyNamespace\MyBundle\Subfolder;

abstract class MyModelClass extends ...