Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Db.php
Go to the documentation of this file.
1 <?php
24 #require_once 'Zend/Log/Writer/Abstract.php';
25 
35 {
41  protected $_db;
42 
48  protected $_table;
49 
55  protected $_columnMap;
56 
65  public function __construct($db, $table, $columnMap = null)
66  {
67  $this->_db = $db;
68  $this->_table = $table;
69  $this->_columnMap = $columnMap;
70  }
71 
78  static public function factory($config)
79  {
81  $config = array_merge(array(
82  'db' => null,
83  'table' => null,
84  'columnMap' => null,
85  ), $config);
86 
87  if (isset($config['columnmap'])) {
88  $config['columnMap'] = $config['columnmap'];
89  }
90 
91  return new self(
92  $config['db'],
93  $config['table'],
94  $config['columnMap']
95  );
96  }
97 
104  public function setFormatter(Zend_Log_Formatter_Interface $formatter)
105  {
106  #require_once 'Zend/Log/Exception.php';
107  throw new Zend_Log_Exception(get_class($this) . ' does not support formatting');
108  }
109 
115  public function shutdown()
116  {
117  $this->_db = null;
118  }
119 
127  protected function _write($event)
128  {
129  if ($this->_db === null) {
130  #require_once 'Zend/Log/Exception.php';
131  throw new Zend_Log_Exception('Database adapter is null');
132  }
133 
134  if ($this->_columnMap === null) {
135  $dataToInsert = $event;
136  } else {
137  $dataToInsert = array();
138  foreach ($this->_columnMap as $columnName => $fieldKey) {
139  if (isset($event[$fieldKey])) {
140  $dataToInsert[$columnName] = $event[$fieldKey];
141  }
142  }
143  }
144 
145  $this->_db->insert($this->_table, $dataToInsert);
146  }
147 }
_write($event)
Definition: Db.php:127
$config
Definition: fraud_order.php:17
static factory($config)
Definition: Db.php:78
setFormatter(Zend_Log_Formatter_Interface $formatter)
Definition: Db.php:104
static _parseConfig($config)
Definition: Abstract.php:126
__construct($db, $table, $columnMap=null)
Definition: Db.php:65
$table
Definition: trigger.php:14