5 use RedBeanPHP\ToolBox as ToolBox;
6 use RedBeanPHP\OODBBean as OODBBean;
9 * Bean Helper Interface.
11 * Interface for Bean Helper.
12 * A little bolt that glues the whole machinery together.
13 * The Bean Helper is passed to the OODB RedBeanPHP Object to
14 * faciliatte the creation of beans and providing them with
15 * a toolbox. The Helper also facilitates the FUSE feature,
16 * determining how beans relate to their models. By overriding
17 * the getModelForBean method you can tune the FUSEing to
18 * fit your business application needs.
20 * @file RedBeanPHP/IBeanHelper.php
21 * @author Gabor de Mooij and the RedBeanPHP Community
25 * copyright (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community
26 * This source file is subject to the BSD/GPLv2 License that is bundled
27 * with this source code in the file license.txt.
32 * Returns a toolbox to empower the bean.
33 * This allows beans to perform OODB operations by themselves,
34 * as such the bean is a proxy for OODB. This allows beans to implement
35 * their magic getters and setters and return lists.
39 public function getToolbox();
42 * Does approximately the same as getToolbox but also extracts the
44 * This method returns a list with all toolbox items in Toolbox Constructor order:
45 * OODB, adapter, writer and finally the toolbox itself!.
49 public function getExtractedToolbox();
52 * Given a certain bean this method will
53 * return the corresponding model.
54 * If no model is returned (NULL), RedBeanPHP might ask again.
56 * @note You can make RedBeanPHP faster by doing the setup wiring yourself.
57 * The event listeners take time, so to speed-up RedBeanPHP you can
58 * drop 'FUSE', if you're not interested in the Models.
60 * @note You can do funny stuff with this method but please be careful.
61 * You *could* create a model depending on properties of the bean, but
62 * it's a bit well... adventurous, here is an example:
65 * class Book extends RedBeanPHP\SimpleModel {};
66 * class Booklet extends RedBeanPHP\SimpleModel {};
68 * class FlexBeanHelper extends RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper {
69 * public function getModelForBean( RedBeanPHP\OODBBean $bean ) {
70 * if (!isset($bean->pages)) return NULL; //will ask again
71 * if ($bean->pages <= 10) return new Booklet;
76 * $h = new FlexBeanHelper;
77 * R::getRedBean()->setBeanHelper($h);
78 * $book = R::dispense('book');
79 * var_dump($book->box()); //NULL cant reach model
81 * var_dump($book->box()); //Booklet
83 * var_dump($book->box()); //still.. Booklet, model has been set
84 * $book2 = R::dispense('book');
86 * var_dump($book2->box()); //Book, more than 10 pages
89 * @param OODBBean $bean bean to obtain the corresponding model of
91 * @return SimpleModel|CustomModel|NULL
93 public function getModelForBean( OODBBean $bean );