To main backwards-compatibility I need to define two class aliases in my contrib module. Both of the source and target classes are within the same namespace within my module's namespace.
I placed the class_alias( )
statements at the top of my_module.module in open code, not a function, and this works for everything in the module, and also mostly for everything everywhere. I have created a second module which uses the original classes to check this. The second module has the first as a dependency. This works most of the time, however, there are a few places where I get a 'class not found' error, meaning that the alias statements have not been processed. For example, when viewing a few admin urls e.g admin/config/regional/language
So is there a better place than my_module.module where I can put the class_alias( )
statements, such that they are always processed?
My fall-back solution would be to re-create the two original class files, in the original locations, and each of them have the class alias statement, so that autoloading finds them. But that's a bit untidy and they will cause confusion as they are named incorrectly. It would be nicer to be able to have the two alias statements somewhere, and not have two nearly empty files left around.
use Path\To\Class as AliasClass
?