RedBeanPHP 4KS
Easy ORM for PHP

Plugins

Plugins are an elegant way to add new functionality to RedBeanPHP. To create a plugin, create a class or function and use:

    R::ext'doSomething', function() {
        return 
MyClass::myMethod();
    } );

to add your new feature to the R-class (required PHP 5.3+ and RedBeanPHP 3.5+). For older versions of PHP use:

    R::ext'doSomething',
        array( 
'MyClass''MyStaticMethod' )
    );

Now you can use your plugin like this:

    R::doSomething();

it's that easy! Here is a list of some interesting 3rd party plugins for RedBeanPHP !

Installing a Plugin

Installing plugins is really easy. Most plugins, the legacy plugins for instance, automatically register their plugin functions with the R-facade for your convenience. So to install the Cooker plugin (one of the legacy plugins) use:

    require 'plugins/Cooker/Cooker.php';

Yes, that's all. Just include the file and you're done. Sometimes the plugin author has additional instructions and might require manual registration with the R-facade, this is mainly because the author is an object 'purist'. To install these plugins correctly consult the corresponding readme files or manuals.

Testing your plugin

You can use the RedBeanPHP unit test facilities to test your plugin. Simply write a test class extending RedUNIT\Base like this:

    class TestMe extends \RedUNIT\Base {
        public function 
testMethod()
        {
            ...
        }
    }

The RedUNIT test facility will simply run all methods starting with 'test'. The tests will run for every driver. If you want your test to run for a specific driver only extend RedUNIT\MySQL or RedUNIT\Postgres etc instead. To perform a test use the asrt($a, $b) command. If $a === $b the test will pass and the number of the test will be printed on the screen, otherwise the program will exit immediately printing an error message. A list of test commands:

    asrt$a$b ); //pass if a === b otherwise fail
    
pass(); //count as passed
    
fail(); //fail (i.e. die with error message)
    
testpack$message ); //print message

To run your tests:

php runtests.php "testing/Mytest.php" "RedUNIT\Base\Mytest"

First argument is the file to run, second argument is the name of the testing class contained in the file. You can not test more than one test file per plugin. Test coverage of your plugin will be calculated and printed. A report containing all missed lines will be saved to the cli folder. You can specify a third parameter to only count code lines of specific files, only lines in matching filenames will be counted in the code coverage statistics.

Writing a new Query Writer

To add a new, custom Query Writer for your favourite RDBMS simply wrap the writer in a plugin. To activate your writer people should issue the following command:

    //for instance to install DB2 database support
    
require 'db2.php';
    
R::setupDB2($dsn$user$pass);

The reason for this is that it is too hard for me to maintain all writers in the core, especially writers for commercial database platform I can't even obtain. Therefore they are separated from the core and hosted in their own repositories by the contributors. Query Writer authors can make the plugins available using the setup-approach described above. Note that this is also more flexible as it allows a database writer plugin to select a different driver (OCI instead of PDO for instance) or maybe even a different toolbox. Query writers should implement all methods defined in the Query Writer interface (see API). Many methods are already implemented in the Abstract Query Writer, these can be reused if they are appropriate for the new Query Writer as well.

Legacy Plugins

RedBeanPHP 4 KS goes back to the roots of RedBeanPHP, on-the-fly ORM. As such many additional functionalities and modules have been removed from this core. However they have been moved to a special plugin repository on github.

Plugins for RedBeanPHP

Here is a list of 3rd party plugins for RedBeanPHP, enjoy!

ReBean

Plugin: ReBean, automatic revision management for RedBeanPHP.
Author: Zewa666

ReBean adds revision tables to your database and uses triggers to automatically insert revision beans.

StdErr Logger

Plugin:StdErr Logger, Logger that writes to StdErr.
Author: Zewa666

Logs queries to error log.

MySQL Backup Plugin

Plugin:MySQL Backup, Table exporter for MySQL
Author: Zewa666

Backups all tables in a MySQL database to a file. Only works for MySQL.

German Porter Stemmer Plugin

Plugin:German Porter Stemmer Plugin, a tool to improve search results in German language.
Author: Zewa666

A linguistic extension to improve search results for German language.


 

RedBeanPHP Easy ORM for PHP © 2014 Gabor de Mooij () and the RedBeanPHP community (credits) - Licensed New BSD/GPLv2 - RedBeanPHP Archives