Toolbox

From RedBean

Jump to: navigation, search

Contents

The RedBean Toolbox

The toolbox class in RedBean acts as a service locator; its main function is to provide tools you often need. I could have stashed all functionality in one big object (oodb) but I want this library to be clean and maintainable. So I have created multiple classes to separate responsibilities and improve flexibility of the overall design (you can use R though: Tutorial). A class in RedBeanPHP has therefore only one reason to change. For you this means that the Setup-class kickstart() function (who likes to make your job easier) returns a toolbox instead of a RedBean instance. Inside this toolbox you will find three classes that make up the core of RedBean. Many classes need a toolbox to create an instance. A toolbox contains the following objects:

The Adapter

The adapter is the class that communicates with the database for RedBean. This adapter makes it possible to execute queries to manipulate the database. To get an instance of this adapter use:

$adapter = $toolbox->getDatabaseAdapter();

For more information on the adapter see chapter: Querying.

The Query Writer

The Query Writer is only used by some RedBean modules to write platform specific SQL. You never have to use this in your own code but by providing the toolbox to other modules you give them the opportunity to take advantage of this system.

RedBean OODB

Most of the time you will need to interact with the RedBean Core Class instance. This object represents the object oriented database that RedBean as a whole tries to simulate. To pick this tool out of the toolbox say:

$redbean = $toolbox->getRedBean();

If you decide to write your own Plugins or module for RedBeanPHP consider the use of the toolbox.

Also see: Advanced,Plugins,Meta,Observers

Personal tools