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: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185:
<?php
/**
* MvcCore
*
* This source file is subject to the BSD 3 License
* For the full copyright and license information, please view
* the LICENSE.md file that are distributed with this source code.
*
* @copyright Copyright (c) 2016 Tom Flidr (https://github.com/mvccore)
* @license https://mvccore.github.io/docs/mvccore/5.0.0/LICENCE.md
*/
namespace MvcCore\Model;
trait Props
{
/**
* `\PDO` connection arguments.
*
* If you need to reconfigure connection string for any other special
* `\PDO` database implementation or you specific needs, patch this array
* in extended application base model class in base `__construct()` method by:
* `static::$connectionArguments = array_merge(static::$connectionArguments, array(...));`
* or by:
* `static::$connectionArguments['driverName']['dsn'] = '...';`
*
* Every key in this field is driver name, so you can use usual `\PDO` drivers:
* - `mysql`, `sqlite`, `sqlsrv` (mssql), `firebird`, `ibm`, `informix`, `4D`
* Following drivers should be used with defaults, no connection args from here are necessary:
* - `oci`, `pgsql`, `cubrid`, `sysbase`, `dblib`
*
* Every value in this configuration field should be defined as:
* - `dsn` - connection query as first `\PDO` constructor argument
* with database config replacements.
* - `auth` - if required to use database credentials for connecting or not.
* - `fileDb` - if database if file database or not.
* - `options` . any additional arguments array or empty array.
* @var array
*/
protected static $connectionArguments = [
'cubrid' => [
'dsn' => '{driver}:host={host};port={port};dbname={database}',
'auth' => TRUE,
'fileDb' => FALSE,
'options' => [],
'defaults' => ['port' => 33000,],
],
'firebird' => [
'dsn' => '{driver}:dbname={host}:{database};charset={charset}',
'auth' => TRUE,
'fileDb' => TRUE,
'options' => [],
'defaults' => ['charset' => 'UTF-8',],
],
'ibm' => [
'dsn' => 'ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE={database};HOSTNAME={host};PORT={port};PROTOCOL={protocol};UID={user};PWD={password}',
'auth' => TRUE,
'fileDb' => FALSE,
'options' => [],
'defaults' => ['port' => 56789, 'protocol' => 'TCPIP',],
],
'informix' => [
'dsn' => "{driver}:host={host}; service={service}; \ndatabase={database}; server={server}; protocol={protocol}; \nEnableScrollableCursors=1",
'auth' => TRUE,
'fileDb' => FALSE,
'options' => [],
'defaults' => ['service' => 9800, 'protocol' => 'onsoctcp',],
],
'mysql' => [
'dsn' => '{driver}:host={host};dbname={database};port={port}',
'auth' => TRUE,
'fileDb' => FALSE,
'options' => [
'\PDO::ATTR_TIMEOUT' => 30,
'\PDO::ATTR_EMULATE_PREPARES' => TRUE,
'\PDO::MYSQL_ATTR_MULTI_STATEMENTS' => TRUE,
'\PDO::MYSQL_ATTR_INIT_COMMAND' => "SET NAMES 'UTF8'",
],
'defaults' => ['port' => 3306,],
],
'sqlite' => [
'dsn' => '{driver}:{database}',
'auth' => FALSE,
'fileDb' => TRUE,
'options' => [],
'defaults' => [
'\PDO::ATTR_TIMEOUT' => 30,
'\PDO::ATTR_EMULATE_PREPARES' => TRUE,
],
],
'pgsql' => [
'dsn' => '{driver}:host={host};port={port};dbname={database};user={user};password={password}',
'auth' => TRUE,
'fileDb' => FALSE,
'options' => [],
'defaults' => ['port' => 5432,],
],
'sqlsrv' => [
'dsn' => '{driver}:Server={host};Database={database};MultipleActiveResultSets=False',
'auth' => TRUE,
'fileDb' => FALSE,
'options' => [
'\PDO::SQLSRV_ATTR_QUERY_TIMEOUT' => 30,
'\PDO::SQLSRV_ATTR_DIRECT_QUERY' => FALSE,
],
'defaults' => ['port' => 1433,],
],
'default' => [
'dsn' => '{driver}:host={host};dbname={database}',
'auth' => TRUE,
'fileDb' => FALSE,
'options' => [
'\PDO::ATTR_ERRMODE' => '\PDO::ERRMODE_EXCEPTION',
],
'defaults' => [],
],
];
/**
* System configuration file database section properties names.
* @var \string[]
*/
protected static $sysConfigProperties = [
'sectionName' => 'db', // db section root node
'defaultName' => 'defaultName', // default db connection name
'defaultClass' => 'defaultClass', // custom \PDO implementation full class name
'retryAttempts' => 'retryAttempts', // reconnection tries count if connection has been lost, extension required
'retryDelay' => 'retryDelay', // delay before every reconnection, extension required
'name' => 'name', // runtime configuration definition property for connection name
'index' => 'index', // runtime configuration definition property for connection index
'driver' => 'driver', // connection driver
'host' => 'host', // connection host
'port' => 'port', // connection port
'user' => 'user', // connection user
'password' => 'password', // connection password
'database' => 'database', // connection database
'options' => 'options', // connection options
'class' => 'class', // custom connection class full name
];
/**
* Default database connection name/index, in system config defined in section `db.default = name`.
* In extended classes - use this for connection name/index of current model if different.
* @var string|int|NULL
*/
protected static $defaultConnectionName = NULL;
/**
* Default database connection class name.
* @var string
*/
protected static $defaultConnectionClass = '\\PDO';
/**
* `\PDO` connections array, keyed by connection indexes from system config.
* @var \PDO[]
*/
protected static $connections = [];
/**
* System config sections array with `\stdClass` objects, keyed by connection indexes.
* @var \stdClass[]
*/
protected static $configs = NULL;
/**
* Originally declared internal model properties to protect their
* possible overwriting by `__set()` or `__get()` magic methods.
* Keys are properties names, values are bools, if to serialize their values
* or not to.
* @var array
*/
protected static $protectedProperties = [
'initialValues' => FALSE,
];
/**
* Array with values initialized by `SetValues()` method.
* Usefull to recognize changed values bafore `Save()`.
* @var array
*/
protected $initialValues = [];
}