Question about using common library classes

Events happening in the community are now at Drupal community events on www.drupal.org.
davidheskettmobot's picture

Question:

Say, I've three different modules, built with class objects tied to the module, and each of the three modules, have a common class object in a separate file for that class.

such that,

widget_processor_one
widget_processor_one.module
ClassObjectOne.php
ClassCommonThing.php

widget_processor_two
widget_processor_two.module
ClassObjectTwo.php
ClassCommonThing.php

widget_processor_three
widget_processor_three.module
ClassObjectThree.php
ClassCommonThing.php

when run, I end up with a "Fatal error: Cannot redeclare class ClassCommonThing...."

Does drupal have a common library area to put such things, such as a libs directory?
I doubt that "includes" was meant for this type of thing.
It doesn't seem that this type of structure is allowed.

How do I avoid class name collision and reuse the same class object without having to rename the thing?
Or is it intended that each module is independent and such sharing is not the drupal way.

Thanks

Comments

I ran into this myself

Mark EWERS's picture

I ran into this myself a few weeks ago. I had several modules all needing to instantiate a PayPal class I had developed. The easy solution was to create a separate module whose sole purpose is to perform the common functions needed by my modules. In turn I made the "children" modules dependent on the "parent" module.

These two lines are something you'll want to look at including in your .info file:

Put this one in all of your .info files to keep them all together on the admin/build/modules page
package = YourModulePackage

Put this one in all of the "childModule.info" files
dependencies[] = parent_module

good idea

davidheskettmobot's picture

Thanks Mark!

On the drive home, I thought something along these lines, just wasn't sure exactly how to hook it all together.

I'll give this a try.

PHP 5+

St. Louis

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week