forked from koala-framework/koala-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Abstract.php
113 lines (102 loc) · 3.11 KB
/
Abstract.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* @internal
*/
abstract class Kwf_Db_Table_Abstract extends Zend_Db_Table_Abstract
{
private $_dao;
protected $_rowClass = 'Kwf_Db_Table_Row';
protected $_rowsetClass = 'Kwf_Db_Table_Rowset';
/**
* Row-Filters für automatisch befüllte Spalten
*
* Anwendungsbeispiele:
* _filters = 'filename' //verwendet autom. Kwf_Filter_Ascii
* _filters = array('filename') //verwendet autom. Kwf_Filter_Ascii
* _filters = array('pos') //Kwf_Filter_Row_Numberize
* _filters = array('pos' => 'MyFilter')
* _filters = array('pos' => new MyFilter($settings))
*/
protected $_filters = array();
protected function _setup()
{
parent::_setup();
$this->_setupFilters();
}
//_setupAdapter nicht ausführen, wir machen das besser lazy in _setupDatabaseAdapter
protected function _setAdapter($db)
{
$this->_db = $db;
return $this;
}
protected function _setupDatabaseAdapter()
{
//instead of setDefaultAdapter - this one lazy loads
if (! $this->_db) {
$this->_db = Kwf_Registry::get('db');
} else if (is_string($this->_db)) {
$this->_db = Kwf_Registry::get('dao')->getDb($this->_db);
}
}
protected function _setupMetadata()
{
//hier drinnen damits nur gemacht wird sobald di erste Table erstellt wird
if (!self::getDefaultMetadataCache()) {
$frontendOptions = array(
'automatic_serialization' => true,
'write_control' => false
);
if (extension_loaded('apc') && PHP_SAPI != 'cli') {
$backendOptions = array();
$backend = 'Apc';
} else {
$backendOptions = array(
'cache_dir' => 'cache/model',
'file_name_prefix' => 'dbtable'
);
$backend = 'File';
}
$cache = Kwf_Cache::factory('Core', $backend, $frontendOptions, $backendOptions);
self::setDefaultMetadataCache($cache);
}
parent::_setupMetadata();
}
protected function _setupFilters()
{
}
public function getFilters()
{
if (is_string($this->_filters)) $this->_filters = array($this->_filters);
foreach($this->_filters as $k=>$f) {
if (is_int($k)) {
unset($this->_filters[$k]);
$k = $f;
if ($k == 'pos') {
$f = 'Kwf_Filter_Row_Numberize';
} else {
$f = 'Kwf_Filter_Ascii';
}
}
if (is_string($f)) {
$f = new $f();
}
if ($f instanceof Kwf_Filter_Row_Abstract) {
$f->setField($k);
}
$this->_filters[$k] = $f;
}
return $this->_filters;
}
public function setDao($dao)
{
$this->_dao = $dao;
}
public function getDao()
{
return $this->_dao;
}
public function select()
{
return new Kwf_Db_Table_Select($this);
}
}