What is it for?
This module allows you to write modules in pure OOP syntax. It becomes handy when you need some kind of "aspects" to inweave into the main functionality of your module. Moopapi does it by Decorator pattern. Currently we have these types of decorators implemented:
- Logger: allows to log every method calling together with all parameters passed. A mighty tool for development and debugging in some circumstances.
Used by: BOTCHA (spam protection without CAPTCHA) - its use case is that while developing Selenium-tests for its JavaScript there is no chance to use usual development tools such as XDebug, because Selenium-tests are intended to be launched via command-line interface. Moopapi logger helps BOTCHA to keep debugged.
- Cacher (planned, see #1870060: Create new decorator: Cacher): The idea is to separate a logic of an application and tricks to make it work faster. It could be done by Cacher "aspect" which includes all speed optimizations while your application contains pure business logic.
- Adapter: Abstraction layer for Drupal major version. The concept is thoroughly described here: #1932290: Forwardport doctrine - a proposed solution for Drupal major version migration problem. See 4.x branches of BOTCHA project (D6 & D7) together with common part x.x-1.x as an implementation of such audacious approach.
Contents
- What is it for?
- How does it work?
- Dependents
- Which version to choose?
- Demo module to try this out
- How much does it cost?
- Project resources
- Credits
How does it work?
The only requirement is that oop syntax module must implement hook_boot() like so:
function hook_boot(){
module_invoke('moopapi', 'register', '[YOUR CLASS NAME WHICH SHOULD BE THE MODULE NAME]');
}
This will register your class as module and will then simply work. Just enable it and enjoy.
Dependents
Which version to choose?
- 1.x (dependencies: Autoload (D6 only)): It is initial release of Moopapi. Contains self-baked logic of overriding.
- 2.x (dependencies: Autoload (D6 only), Libraries (both D6&D7)): Uses Patchwork library. Looks like it is a bit slow. We should use Cacher decorator (see #1870060: Create new decorator: Cacher) to eliminate that deficiency - until then 1.x is recommended.
Please use included .make-file as installation instruction.
Demo module to try this out
Create ooptest.module and stick code as follows into it.
Enable both moopapi.module with ooptest.module and then visit either to /oop or /oop-test to see that it works :-D
ooptest.info:
; $Id$
name = OOPTest
description = The Next Level $417
core = 6.x
version = VERSION
ooptest.module:
<?php
//$Id$
class ooptest {
public function menu() {
$items = array();
$items['oop-test'] = array (
'title' => 'OOP Page Test',
'page callback' => 'ooptest_fark',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
$items['oop'] = array (
'title' => 'OOP FAPI Test',
'page callback' => 'drupal_get_form',
'page arguments' => array('ooptest_form'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
public function boot() {
}
public function form_alter(&$form, $form_state, $form_id) {
if ( 'ooptest_form' == $form_id) {
$form['additional'] = array(
'#type' => 'radios',
'#title' => t('Is this cool or what!?!?!? - (hook_form_alter() item)'),
'#options' => array(
'Super cool!',
'Hell yeah!!!!',
),
'#default_value' => variable_get('additional', null),
'#weight' => -1,
);
}
}
public function form() {
$form = array();
$form['testing'] = array(
'#type' => 'textfield',
'#title' => t('This is a test field (form item)'),
'#default_value' => variable_get('testing', '134'),
);
return system_settings_form($form);
}
public function fark () {
return 'hello world 2.0 style';
}
}
/**
* Implementing hook_boot() is a must, to force drupal to load this module as early as possible
* Druring hook_init phase moopapi_init() will initialize all the oop method wrappers and execute hook oop->boot()
*
*/
function ooptest_boot(){
module_invoke('moopapi', 'register', 'ooptest');
}
?>
How much does it cost?
It is absolutely free. But you have the opportunity to contribute to the implementation of new features or speed up the closure of the bug that annoys you, or just to thank the developers.
Support this module to make new features to be implemented faster:
- Flattr project page:
- FreedomSponsors project page
Project resources
Credits
PatchRanger - the first crowdfunded Drupal freelancer:
Project information
- 3,416 sites report using this module
- Created by litwol on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Development version: 7.x-1.x-dev updated 17 Feb 2014 at 05:43 UTC