1: <?php
2:
3: namespace RedBeanPHP;
4:
5: use RedBeanPHP\OODB as OODB;
6: use RedBeanPHP\QueryWriter as QueryWriter;
7: use RedBeanPHP\Adapter\DBAdapter as DBAdapter;
8: use RedBeanPHP\Adapter as Adapter;
9:
10: /**
11: * ToolBox.
12: *
13: * The toolbox is an integral part of RedBeanPHP providing the basic
14: * architectural building blocks to manager objects, helpers and additional tools
15: * like plugins. A toolbox contains the three core components of RedBeanPHP:
16: * the adapter, the query writer and the core functionality of RedBeanPHP in
17: * OODB.
18: *
19: * @file RedBeanPHP/ToolBox.php
20: * @author Gabor de Mooij and the RedBeanPHP community
21: * @license BSD/GPLv2
22: *
23: * @copyright
24: * copyright (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
25: * This source file is subject to the BSD/GPLv2 License that is bundled
26: * with this source code in the file license.txt.
27: */
28: class ToolBox
29: {
30:
31: /**
32: * @var OODB
33: */
34: protected $oodb;
35:
36: /**
37: * @var QueryWriter
38: */
39: protected $writer;
40:
41: /**
42: * @var DBAdapter
43: */
44: protected $adapter;
45:
46: /**
47: * Constructor.
48: * The toolbox is an integral part of RedBeanPHP providing the basic
49: * architectural building blocks to manager objects, helpers and additional tools
50: * like plugins. A toolbox contains the three core components of RedBeanPHP:
51: * the adapter, the query writer and the core functionality of RedBeanPHP in
52: * OODB.
53: *
54: * @param OODB $oodb Object Database, OODB
55: * @param DBAdapter $adapter Database Adapter
56: * @param QueryWriter $writer Query Writer
57: */
58: public function __construct( OODB $oodb, Adapter $adapter, QueryWriter $writer )
59: {
60: $this->oodb = $oodb;
61: $this->adapter = $adapter;
62: $this->writer = $writer;
63: return $this;
64: }
65:
66: /**
67: * Returns the query writer in this toolbox.
68: * The Query Writer is responsible for building the queries for a
69: * specific database and executing them through the adapter.
70: *
71: * @return QueryWriter
72: */
73: public function getWriter()
74: {
75: return $this->writer;
76: }
77:
78: /**
79: * Returns the OODB instance in this toolbox.
80: * OODB is responsible for creating, storing, retrieving and deleting
81: * single beans. Other components rely
82: * on OODB for their basic functionality.
83: *
84: * @return OODB
85: */
86: public function getRedBean()
87: {
88: return $this->oodb;
89: }
90:
91: /**
92: * Returns the database adapter in this toolbox.
93: * The adapter is responsible for executing the query and binding the values.
94: * The adapter also takes care of transaction handling.
95: *
96: * @return DBAdapter
97: */
98: public function getDatabaseAdapter()
99: {
100: return $this->adapter;
101: }
102: }
103: