Go to the documentation of this file.00001 <?php
00002
00031 class Robo47_Log_Writer_DoctrineTable extends Robo47_Log_Writer_Abstract
00032 {
00033
00041 protected $_columnMap = array(
00042 'message' => 'message',
00043 'priority' => 'priority',
00044 'category' => 'category',
00045 'timestamp' => 'timestamp',
00046 );
00052 protected $_table = null;
00053
00059 public function __construct($table, array $columnMap = array())
00060 {
00061 $this->setTable($table);
00062 $this->setColumnMap($columnMap);
00063 }
00064
00071 public function setTable($table)
00072 {
00073
00074 if (is_string($table)) {
00075 $table = Doctrine_Core::getTable($table);
00076 }
00077 if (!$table instanceof Doctrine_Table) {
00078 $message = 'table not instance of Doctrine_Table.';
00079 throw new Robo47_Log_Writer_Exception($message);
00080 }
00081 $this->_table = $table;
00082 return $this;
00083 }
00084
00090 public function getTable()
00091 {
00092 return $this->_table;
00093 }
00094
00101 public function setColumnMap(array $columnMap)
00102 {
00103 if (count($columnMap) > 0) {
00104 $this->_columnMap = $columnMap;
00105 }
00106 return $this;
00107 }
00108
00114 public function getColumnMap()
00115 {
00116 return $this->_columnMap;
00117 }
00118
00124 public function getOptions()
00125 {
00126 return array(
00127 'columnMap' => $this->getColumnMap(),
00128 'table' => $this->getTable(),
00129 );
00130 }
00131
00137 public function _write($event)
00138 {
00139 $entry = $this->_table->create(array());
00140 foreach ($this->_columnMap as $eventIndex => $tableColumn) {
00141 $entry->$tableColumn = $event[$eventIndex];
00142 }
00143 $entry->save();
00144 }
00145
00149 public function shutdown()
00150 {
00151 $this->_table = null;
00152 }
00153
00160 static public function factory($config)
00161 {
00162 if ($config instanceof Zend_Config) {
00163 $config = $config->toArray();
00164 }
00165 if (!isset($config['table'])) {
00166 $message = 'No table defined for Robo47_Log_Writer_DoctrineTable';
00167 throw new Robo47_Log_Writer_Exception($message);
00168 }
00169 $writer = new Robo47_Log_Writer_DoctrineTable($config['table']);
00170 if (isset($config['columnMap'])) {
00171 $writer->setColumnMap($config['columnMap']);
00172 }
00173 return $writer;
00174 }
00175 }