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: *
14: * @file RedBeanPHP/IBeanHelper.php
15: * @author Gabor de Mooij and the RedBeanPHP Community
16: * @license BSD/GPLv2
17: *
18: * @copyright
19: * copyright (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community
20: * This source file is subject to the BSD/GPLv2 License that is bundled
21: * with this source code in the file license.txt.
22: */
23: interface BeanHelper
24: {
25: /**
26: * Returns a toolbox to empower the bean.
27: * This allows beans to perform OODB operations by themselves,
28: * as such the bean is a proxy for OODB. This allows beans to implement
29: * their magic getters and setters and return lists.
30: *
31: * @return ToolBox
32: */
33: public function getToolbox();
34:
35: /**
36: * Does approximately the same as getToolbox but also extracts the
37: * toolbox for you.
38: * This method returns a list with all toolbox items in Toolbox Constructor order:
39: * OODB, adapter, writer and finally the toolbox itself!.
40: *
41: * @return array
42: */
43: public function getExtractedToolbox();
44:
45: /**
46: * Given a certain bean this method will
47: * return the corresponding model.
48: * If no model is returned (NULL), RedBeanPHP might ask again.
49: *
50: * @note You can make RedBeanPHP faster by doing the setup wiring yourself.
51: * The event listeners take time, so to speed-up RedBeanPHP you can
52: * drop 'FUSE', if you're not interested in the Models.
53: *
54: * @note You can do funny stuff with this method but please be careful.
55: * You *could* create a model depending on properties of the bean, but
56: * it's a bit well... adventurous, here is an example:
57: *
58: * <code>
59: * class Book extends RedBeanPHP\SimpleModel {};
60: * class Booklet extends RedBeanPHP\SimpleModel {};
61: *
62: * class FlexBeanHelper extends RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper {
63: * public function getModelForBean( RedBeanPHP\OODBBean $bean ) {
64: * if (!isset($bean->pages)) return NULL; //will ask again
65: * if ($bean->pages <= 10) return new Booklet;
66: * return new Book;
67: * }
68: * }
69: *
70: * $h = new FlexBeanHelper;
71: * R::getRedBean()->setBeanHelper($h);
72: * $book = R::dispense('book');
73: * var_dump($book->box()); //NULL cant reach model
74: * $book->pages = 5;
75: * var_dump($book->box()); //Booklet
76: * $book->pages = 15;
77: * var_dump($book->box()); //still.. Booklet, model has been set
78: * $book2 = R::dispense('book');
79: * $book2->pages = 15;
80: * var_dump($book2->box()); //Book, more than 10 pages
81: * </code>
82: *
83: * @param OODBBean $bean bean to obtain the corresponding model of
84: *
85: * @return SimpleModel|CustomModel|NULL
86: */
87: public function getModelForBean( OODBBean $bean );
88: }
89: