Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / RedBeanPHP / BeanHelper.php
1 <?php
2
3 namespace RedBeanPHP;
4
5 use RedBeanPHP\ToolBox as ToolBox;
6 use RedBeanPHP\OODBBean as OODBBean;
7
8 /**
9  * Bean Helper Interface.
10  *
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.
19  *
20  * @file    RedBeanPHP/IBeanHelper.php
21  * @author  Gabor de Mooij and the RedBeanPHP Community
22  * @license BSD/GPLv2
23  *
24  * @copyright
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.
28  */
29 interface BeanHelper
30 {
31         /**
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.
36          *
37          * @return ToolBox
38          */
39         public function getToolbox();
40
41         /**
42          * Does approximately the same as getToolbox but also extracts the
43          * toolbox for you.
44          * This method returns a list with all toolbox items in Toolbox Constructor order:
45          * OODB, adapter, writer and finally the toolbox itself!.
46          *
47          * @return array
48          */
49         public function getExtractedToolbox();
50
51         /**
52          * Given a certain bean this method will
53          * return the corresponding model.
54          * If no model is returned (NULL), RedBeanPHP might ask again.
55          *
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.
59          *
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:
63          *
64          * <code>
65          * class Book extends RedBeanPHP\SimpleModel {};
66          * class Booklet extends RedBeanPHP\SimpleModel {};
67          *
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;
72          *   return new Book;
73          *       }
74          * }
75          *
76          * $h = new FlexBeanHelper;
77          * R::getRedBean()->setBeanHelper($h);
78          * $book = R::dispense('book');
79          * var_dump($book->box()); //NULL cant reach model
80          * $book->pages = 5;
81          * var_dump($book->box()); //Booklet
82          * $book->pages = 15;
83          * var_dump($book->box()); //still.. Booklet, model has been set
84          * $book2 = R::dispense('book');
85          * $book2->pages = 15;
86          * var_dump($book2->box()); //Book, more than 10 pages
87          * </code>
88          *
89          * @param OODBBean $bean bean to obtain the corresponding model of
90          *
91          * @return SimpleModel|CustomModel|NULL
92          */
93         public function getModelForBean( OODBBean $bean );
94 }