PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Db / Adapter.php
matomo / app / core / Db Last commit date
Adapter 6 years ago Schema 6 years ago Adapter.php 6 years ago AdapterInterface.php 6 years ago BatchInsert.php 6 years ago Schema.php 6 years ago SchemaInterface.php 6 years ago Settings.php 6 years ago TransactionLevel.php 6 years ago
Adapter.php
133 lines
1 <?php
2 /**
3 * Piwik - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9 namespace Piwik\Db;
10
11 use Zend_Db_Table;
12
13 /**
14 */
15 class Adapter
16 {
17 /**
18 * Create adapter
19 *
20 * @param string $adapterName database adapter name
21 * @param array $dbInfos database connection info
22 * @param bool $connect
23 * @return AdapterInterface
24 */
25 public static function factory($adapterName, & $dbInfos, $connect = true)
26 {
27 if ($connect) {
28 if (isset($dbInfos['port']) && is_string($dbInfos['port']) && $dbInfos['port'][0] == '/') {
29 $dbInfos['unix_socket'] = $dbInfos['port'];
30 unset($dbInfos['host']);
31 unset($dbInfos['port']);
32 }
33
34 // not used by Zend Framework
35 unset($dbInfos['tables_prefix']);
36 unset($dbInfos['adapter']);
37 unset($dbInfos['schema']);
38 }
39
40 $className = self::getAdapterClassName($adapterName);
41
42 // make sure not to pass any references otherwise they will modify $dbInfos
43 $infos = array();
44 foreach ($dbInfos as $key => $val) {
45 $infos[$key] = $val;
46 }
47
48 $adapter = new $className($infos);
49
50 if ($connect) {
51 $adapter->getConnection();
52
53 Zend_Db_Table::setDefaultAdapter($adapter);
54 // we don't want the connection information to appear in the logs
55 $adapter->resetConfig();
56 }
57
58 return $adapter;
59 }
60
61 /**
62 * Get adapter class name
63 *
64 * @param string $adapterName
65 * @return string
66 * @throws \Exception
67 */
68 private static function getAdapterClassName($adapterName)
69 {
70 $className = 'Piwik\Db\Adapter\\' . str_replace(' ', '\\', ucwords(str_replace(array('_', '\\'), ' ', strtolower($adapterName))));
71 if (!class_exists($className)) {
72 throw new \Exception(sprintf("Adapter '%s' is not valid. Maybe check that your Matomo configuration files in config/*.ini.php are readable by the webserver.", $adapterName));
73 }
74 return $className;
75 }
76
77 /**
78 * Get default port for named adapter
79 *
80 * @param string $adapterName
81 * @return int
82 */
83 public static function getDefaultPortForAdapter($adapterName)
84 {
85 $className = self::getAdapterClassName($adapterName);
86 return call_user_func(array($className, 'getDefaultPort'));
87 }
88
89 /**
90 * Get list of adapters
91 *
92 * @return array
93 */
94 public static function getAdapters()
95 {
96 static $adapterNames = array(
97 // currently supported by Piwik
98 'Pdo\Mysql',
99 'Mysqli',
100
101 // other adapters supported by Zend_Db
102 // 'Pdo_Pgsql',
103 // 'Pdo_Mssql',
104 // 'Sqlsrv',
105 // 'Pdo_Ibm',
106 // 'Db2',
107 // 'Pdo_Oci',
108 // 'Oracle',
109 );
110
111 $adapters = array();
112
113 foreach ($adapterNames as $adapterName) {
114 $className = '\Piwik\Db\Adapter\\' . $adapterName;
115 if (call_user_func(array($className, 'isEnabled'))) {
116 $adapters[strtoupper($adapterName)] = call_user_func(array($className, 'getDefaultPort'));
117 }
118 }
119
120 return $adapters;
121 }
122
123 /**
124 * Checks if the available adapters are recommended by Piwik or not.
125 * @param string $adapterName
126 * @return bool
127 */
128 public static function isRecommendedAdapter($adapterName)
129 {
130 return strtolower($adapterName) === 'pdo/mysql';
131 }
132 }
133