This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Childish; |
||
3 | |||
4 | use PDO; |
||
5 | use Childish\database\DatabaseManager; |
||
6 | use Childish\connection\ConnectionFactory; |
||
7 | use Childish\support\Container; |
||
8 | use Childish\support\Fluent; |
||
9 | |||
10 | /** |
||
11 | * ChildishServer |
||
12 | * |
||
13 | * @author Pu ShaoWei <[email protected]> |
||
14 | * @date 2017/12/6 |
||
15 | * @package App\db |
||
16 | * @version 1.0 |
||
17 | */ |
||
18 | class ChildishServer |
||
19 | { |
||
20 | /** |
||
21 | * @var \Childish\database\DatabaseManager $manager |
||
22 | */ |
||
23 | protected $manager; |
||
24 | |||
25 | /** |
||
26 | * The current globally used instance. |
||
27 | * |
||
28 | * @var ChildishServer |
||
29 | */ |
||
30 | protected static $instance; |
||
31 | |||
32 | /** |
||
33 | * @var \Childish\support\Container $container |
||
34 | */ |
||
35 | protected $container; |
||
36 | |||
37 | /** |
||
38 | * ChildishServer constructor. |
||
39 | */ |
||
40 | public function __construct() |
||
41 | { |
||
42 | $this->setupContainer(new Container); |
||
43 | $this->setupDefaultConfiguration(); |
||
44 | $this->setupManager(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * setupContainer |
||
49 | * |
||
50 | * @param \Childish\support\Container $container |
||
51 | */ |
||
52 | protected function setupContainer(Container $container) |
||
53 | { |
||
54 | $this->container = $container; |
||
55 | if (!$this->container->bound('config')) { |
||
56 | $this->container->instance('config', new Fluent); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Make this capsule instance available globally. |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | public function setAsGlobal() |
||
66 | { |
||
67 | static::$instance = $this; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Get the IoC container instance. |
||
72 | * |
||
73 | * @return \Childish\support\Container $container |
||
74 | */ |
||
75 | public function getContainer() |
||
76 | { |
||
77 | return $this->container; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Setup the default database configuration options. |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | protected function setupDefaultConfiguration() |
||
86 | { |
||
87 | $this->container['config']['database.fetch'] = PDO::FETCH_OBJ; |
||
88 | |||
89 | $this->container['config']['database.default'] = 'default'; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Build the database manager instance. |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | protected function setupManager() |
||
98 | { |
||
99 | $factory = new ConnectionFactory($this->container); |
||
100 | $this->manager = new DatabaseManager($this->container, $factory); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Get a connection instance from the global manager. |
||
105 | * |
||
106 | * @param string $connection |
||
107 | * @return \Childish\connection\Connection |
||
108 | */ |
||
109 | public static function connection($connection = null) |
||
110 | { |
||
111 | return static::$instance->getConnection($connection); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get a fluent query builder instance. |
||
116 | * |
||
117 | * @param string $table |
||
118 | * @param string $connection |
||
119 | * @return \Childish\query\Builder; |
||
0 ignored issues
–
show
|
|||
120 | */ |
||
121 | public static function table($table, $connection = null) |
||
122 | { |
||
123 | return static::$instance->connection($connection)->table($table); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @param string $name |
||
128 | * @return \\Connection |
||
129 | */ |
||
130 | /** |
||
131 | * Get a registered connection instance. |
||
132 | * |
||
133 | * @param null $name |
||
134 | * @return \Childish\connection\Connection |
||
135 | */ |
||
136 | public function getConnection($name = null) |
||
137 | { |
||
138 | return $this->manager->connection($name); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Register a connection with the manager. |
||
143 | * |
||
144 | * @param array $config |
||
145 | * @param string $name |
||
146 | * @return void |
||
147 | */ |
||
148 | public function addConnection(array $config, $name = 'default') |
||
149 | { |
||
150 | $connections = $this->container['config']['database.connections']; |
||
151 | |||
152 | $connections[$name] = $config; |
||
153 | |||
154 | $this->container['config']['database.connections'] = $connections; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * Set the fetch mode for the database connections. |
||
159 | * |
||
160 | * @param int $fetchMode |
||
161 | * @return $this |
||
162 | */ |
||
163 | public function setFetchMode($fetchMode) |
||
164 | { |
||
165 | $this->container['config']['database.fetch'] = $fetchMode; |
||
166 | |||
167 | return $this; |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Get the database manager instance. |
||
172 | * |
||
173 | * @return mixed |
||
174 | */ |
||
175 | public function getDatabaseManager() |
||
176 | { |
||
177 | return $this->manager; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * bootEloquent |
||
182 | * |
||
183 | * @return void |
||
184 | */ |
||
185 | public function bootEloquent() |
||
186 | { |
||
187 | ChildishModel::setConnectionResolver($this->manager); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Dynamically pass methods to the default connection. |
||
192 | * |
||
193 | * @param string $method |
||
194 | * @param array $parameters |
||
195 | * @return mixed |
||
196 | */ |
||
197 | public static function __callStatic($method, $parameters) |
||
198 | { |
||
199 | return static::connection()->$method(...$parameters); |
||
200 | } |
||
201 | } |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.