Open-Source PHP Framework - Designed for rapid development of performance-oriented scalable applications

/mvc/models/error

[return to app]
1
<?php
class errorModel extends model {
   /**
     * Collection name (used only if Mongo is installed) - only need to change this if you will be operating
 
multiple * Vork account instances on the same database * @var string */ protected $_collection = 'errors'; /** * Logs errors - saves to a Mongo collection if Mongo is installed, otherwise it saves to the PHP error log * @param array $error */ public function logError(array $error) { //array_merge is used for array_unshift-like behavior $error = array_merge(array('_url' => get::url(array('get' => true)), '_date' => date('r')), $error); $error['_ts'] = time(); if (is::ajax()) { $error['_isAjax'] = true; } if (isset($_SESSION)) { $error['_SESSION'] = $_SESSION; } if ($_POST) { $error['_POST'] = $_POST; } $error['_SERVER'] = $_SERVER; if (!in_array('mongo', config::$modelObjects)) { error_log(json_encode($error)); } else { $col = $this->_collection; if (isset($error['error']) && is_scalar($error['error'])) { $col .= '_' . substr(preg_replace('/\W+/', '_', $error['error']), 0, 40); } $errors = $this->mongo->selectCollection($col); $errors->insert($error); $errors->ensureIndex(array('_ts' => -1)); } } }