forked from gabordemooij/redbean
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModelHelper.php
executable file
·64 lines (57 loc) · 1.37 KB
/
ModelHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* RedBean Model Helper
*
* @file RedBean/ModelHelper.php
* @description Connects beans to models, in essence
* this is the core of so-called FUSE.
*
* @author Gabor de Mooij
* @license BSD
*
* copyright (c) G.J.G.T. (Gabor) de Mooij
* This source file is subject to the BSD/GPLv2 License that is bundled
* with this source code in the file license.txt.
*
*/
class RedBean_ModelHelper implements RedBean_Observer {
/**
* Holds a model formatter
* @var RedBean_IModelFormatter
*/
private static $modelFormatter;
/**
* Connects OODB to a model if a model exists for that
* type of bean. This connector is used in the facade.
*
* @param string $eventName
* @param RedBean_OODBBean $bean
*/
public function onEvent( $eventName, $bean ) {
$bean->$eventName();
}
/**
* Given a model ID (model identifier) this method returns the
* full model name.
*
* @param string $model
* @return string $fullname
*/
public static function getModelName( $model ) {
if (self::$modelFormatter){
return self::$modelFormatter->formatModel($model);
}
else {
return 'Model_'.ucfirst($model);
}
}
/**
* Sets the model formatter to be used to discover a model
* for Fuse.
*
* @param string $modelFormatter
*/
public static function setModelFormatter( $modelFormatter ) {
self::$modelFormatter = $modelFormatter;
}
}