Sfoglia il codice sorgente

changed db managment; display_errors ini setting

develop
Robin Thoni 8 anni fa
parent
commit
5fd8fa1f77

+ 3
- 27
src/Utils/Controller/LuticateApplication.php Vedi File

@@ -37,7 +37,7 @@ class LuticateApplication implements MessageComponentInterface
37 37
      */
38 38
     public function __construct($configuration)
39 39
     {
40
-        error_reporting(0);
40
+        ini_set("display_errors", "stderr");
41 41
         $this->_config = $configuration;
42 42
         $this->_clients = new \SplObjectStorage;
43 43
         $this->_router = new LuRoute();
@@ -84,34 +84,10 @@ class LuticateApplication implements MessageComponentInterface
84 84
         
85 85
         $this->_router->setup();
86 86
     }
87
-
88
-    public function getDatabases()
89
-    {
90
-        return $this->_config['databases'];
91
-    }
92 87
     
93
-    public function setupDatabases()
88
+    public function addDatabaseProvider($dbProviderClass)
94 89
     {
95
-        $capsule = new Capsule;
96
-        foreach (static::getDatabases() as $database) {
97
-
98
-            if ($database['driver'] == 'pgsql' || $database['driver'] == 'mysql' ||
99
-                $database['driver'] == 'sqlite' || $database['driver'] == 'sqlsrv') {
100
-                $default = [
101
-                    'name'      => 'mydb',
102
-                    'host'      => '172.17.0.1',
103
-                    'database'  => 'luticate2',
104
-                    'username'  => 'dev',
105
-                    'password'  => 'dev',
106
-                    'charset'   => 'utf8',
107
-                    'collation' => 'utf8_unicode_ci',
108
-                    'prefix'    => ''
109
-                ];
110
-                $db = array_merge($default, $database);
111
-                $capsule->addConnection($db, $database['name']);
112
-            }
113
-        }
114
-        $capsule->setAsGlobal();
90
+        call_user_func([$dbProviderClass, "setupDatabases"], $this->_config['databases']);
115 91
     }
116 92
     
117 93
     private function dispatch($httpMethod, $url, $parameters)

+ 25
- 1
src/Utils/DataAccess/LuDataAccess.php Vedi File

@@ -10,7 +10,7 @@ use Luticate\Utils\Business\LuStringUtils;
10 10
 use Luticate\Utils\Dbo\LuDbo;
11 11
 use Luticate\Utils\Dbo\LuPaginatedDbo;
12 12
 
13
-abstract class LuDataAccess {
13
+abstract class LuDataAccess extends LuDatabaseProvider {
14 14
 
15 15
     protected static $_connection = "mydb";
16 16
     protected static $_table = "mydb_table";
@@ -19,6 +19,30 @@ abstract class LuDataAccess {
19 19
     protected static $_dboArrayClass = null;
20 20
     protected static $_dboIgnoreList = [];
21 21
 
22
+    public static function setupDatabases($databases)
23
+    {
24
+        $capsule = new Capsule;
25
+        foreach ($databases as $database) {
26
+
27
+            if ($database['driver'] == 'pgsql' || $database['driver'] == 'mysql' ||
28
+                $database['driver'] == 'sqlite' || $database['driver'] == 'sqlsrv') {
29
+                $default = [
30
+                    'name'      => 'mydb',
31
+                    'host'      => '172.17.0.1',
32
+                    'database'  => 'luticate2',
33
+                    'username'  => 'dev',
34
+                    'password'  => 'dev',
35
+                    'charset'   => 'utf8',
36
+                    'collation' => 'utf8_unicode_ci',
37
+                    'prefix'    => ''
38
+                ];
39
+                $db = array_merge($default, $database);
40
+                $capsule->addConnection($db, $database['name']);
41
+            }
42
+        }
43
+        $capsule->setAsGlobal();
44
+    }
45
+
22 46
     public static function transact(\Closure $function)
23 47
     {
24 48
         return static::getConnection()->transaction($function);

+ 17
- 0
src/Utils/DataAccess/LuDatabaseProvider.php Vedi File

@@ -0,0 +1,17 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 6/28/16
6
+ * Time: 11:40 PM
7
+ */
8
+
9
+namespace Luticate\Utils\DataAccess;
10
+
11
+
12
+abstract class LuDatabaseProvider
13
+{
14
+    public static function setupDatabases($databases)
15
+    {
16
+    }
17
+}

+ 1
- 1
tests/bootstrap.php Vedi File

@@ -11,4 +11,4 @@ use Luticate\Utils\Controller\LuticateApplication;
11 11
 $json = file_get_contents(__DIR__ . '/config.json');
12 12
 $config = json_decode($json, true);
13 13
 $app = new LuticateApplication($config);
14
-$app->setupDatabases();
14
+$app->addDatabaseProvider(\Luticate\Utils\DataAccess\LuDataAccess::class);

Loading…
Annulla
Salva