Newer
Older
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace calderawp\CalderaFormsQuery\Features;
use calderawp\CalderaContainers\Container;
use calderawp\CalderaContainers\Interfaces\ServiceContainer;
use calderawp\CalderaFormsQuery\DeleteQueries;
use calderawp\CalderaFormsQuery\MySqlBuilder;
use calderawp\CalderaFormsQuery\Delete\Entry as EntryDelete;
use \calderawp\CalderaFormsQuery\Delete\EntryValues as EntryValuesDelete;
use \calderawp\CalderaFormsQuery\Select\Entry as EntrySelect;
use \calderawp\CalderaFormsQuery\Select\EntryValues as EntryValueSelect;
use calderawp\CalderaFormsQuery\SelectQueries;
class FeatureContainer extends Container
{
/**
* @var ServiceContainer
*/
protected $serviceContainer;
/**
* @var \wpdb
*/
protected $wpdb;
/**
* FeatureContainer constructor.
* @param ServiceContainer $serviceContainer
* @param \wpdb $wpdb
*/
public function __construct(ServiceContainer $serviceContainer, \wpdb $wpdb )
{
$this->serviceContainer = $serviceContainer;
$this->wpdb = $wpdb;
$this->bindServices();
}
/**
* Bind services to service container
*/
protected function bindServices()
{
$this->serviceContainer->singleton( MySqlBuilder::class, function(){
return new MySqlBuilder();
});
$this->serviceContainer->bind( SelectQueries::class, function (){
return new SelectQueries(
new EntrySelect(
$this->getBuilder(),
$this->entryTableName()
),
new EntryValueSelect(
$this->getBuilder(),
$this->entryTableName()
),
$this->wpdb
);
});
$this->serviceContainer->bind( DeleteQueries::class, function (){
return new DeleteQueries(
new EntryDelete(
$this->getBuilder(),
$this->entryTableName()
),
new EntryValuesDelete(
$this->getBuilder(),
$this->entryTableName()
),
$this->wpdb
);
});
$this->serviceContainer->singleton( Queries::class, function(){
return new Queries(
$this
->serviceContainer
->make( SelectQueries::class ),
$this
->serviceContainer
->make(DeleteQueries::class )
);
});
}
/**
* Get MySQL builder
*
* @return MySqlBuilder
*/
public function getBuilder()
{
return $this
->serviceContainer
->make( MySqlBuilder::class );
}
/**
* Get query runner
*
* @return Queries
*/
public function getQueries()
{
return $this
->serviceContainer
->make( Queries::class );
}
/**
* @return string
*/
protected function entryValueTableName(): string
{
return "{$this->wpdb->prefix}cf_form_entry_values";
}
/**
* @return string
*/
protected function entryTableName(): string
{
return "{$this->wpdb->prefix}cf_form_entries";
}
}