This project is not covered by Drupal’s security advisory policy.

Stapler allows the definition of a PHP class to be distributed on different modules.
Some of you might know this as "mixins" from languages like Ruby, or from C++ with templates.

Inspired by a discussion in the Butler group,
Class extension / Mixins via Code Generation?

Have a look at the stapler_example module to see how this works.

Note: Stapler autoload does not work during hook_boot(). You should wait for hook_init() to use any stapled classes.

eval is evil?

Before we start a debate about this:
The main reason why we don't like eval() is if it is used to execute uncontrolled php code from the database or user input, as it happens a lot in other parts of Drupal.
The pieces of php that are eval'd with stapler are quite simple, with the only unknown part being class names built from file name fragments. (if you know a better way to sanitize class names, let me know!)

Is a "stapled" class a good design pattern?

This depends a lot on what you want to do. You might achieve a nicer solution with a composition of separate objects, and/or with magic methods. Your choice.

Status: "alpha" ?

As usual with new modules, I give people some time to play before I publish a 1.0 release.

Project information

  • chart icon1,278 downloads
  • shield alertThis project is not covered by the security advisory policy.
    Use at your own risk! It may have publicly disclosed vulnerabilities.