diff --git a/src/classes/Database.php b/src/classes/Database.php index 82028fa..6218be3 100644 --- a/src/classes/Database.php +++ b/src/classes/Database.php @@ -296,25 +296,12 @@ class Database extends Object * * @param string $sql statement to execute * @param array $input_parameters optional key/values to be bound - * @param boolean $force_slow optional, force slow query logging * @return integer ID of the last inserted row or sequence number */ - public function execute($sql, $input_parameters = null, $force_slow = false) + public function execute($sql, $input_parameters = null) { $this->open(); - if (isset($this->config->pickles['logging']) && $this->config->pickles['logging']) - { - $loggable_query = $sql; - - if ($input_parameters != null) - { - $loggable_query .= ' -- ' . json_encode($input_parameters); - } - - Log::query($loggable_query); - } - $sql = trim($sql); // Checks if the query is blank @@ -375,11 +362,6 @@ class Database extends Object $end_time = microtime(true); $duration = $end_time - $start_time; - if ($duration >= 1 || $force_slow) - { - Log::slowQuery($duration . ' seconds: ' . $loggable_query); - } - // Logs the information to the profiler if (Profiler::enabled('explains', 'queries')) { diff --git a/src/classes/Log.php b/src/classes/Log.php deleted file mode 100644 index 719e682..0000000 --- a/src/classes/Log.php +++ /dev/null @@ -1,151 +0,0 @@ - - * @copyright Copyright 2007-2014, Josh Sherman - * @license http://www.opensource.org/licenses/mit-license.html - * @package PICKLES - * @link https://github.com/joshtronic/pickles - */ - -/** - * Log Class - * - * Standardized logging methods for ease of reporting. - */ -class Log -{ - /** - * Log Information - * - * @static - * @param string $message message to log - * @return boolean whether or not the write was successful - */ - public static function information($message) - { - return self::write('information', $message); - } - - /** - * Log Warning - * - * @static - * @param string $message message to log - * @return boolean whether or not the write was successful - */ - public static function warning($message) - { - return self::write('warning', $message); - } - - /** - * Log Error - * - * @static - * @param string $message message to log - * @return boolean whether or not the write was successful - */ - public static function error($message) - { - return self::write('error', $message); - } - - /** - * Log Slow Query - * - * @static - * @param string $message message to log - * @return boolean whether or not the write was successful - */ - public static function slowQuery($message) - { - return self::write('slow_query', $message); - } - - /** - * Log Credit Card Transaction - * - * @static - * @param string $message message to log - * @return boolean whether or not the write was successful - */ - public static function transaction($message) - { - return self::write('transaction', $message); - } - - /** - * Log PHP Error - * - * @static - * @param string $message message to log - * @return boolean whether or not the write was successful - */ - public static function phpError($message, $time = false) - { - return self::write('php_error', $message, false, $time); - } - - /** - * Log SQL Query - * - * @static - * @param string $message message to log - * @return boolean whether or not the write was successful - */ - public static function query($message) - { - return self::write('query', $message); - } - - /** - * Write Message to Log File - * - * @static - * @access private - * @param string $message message to log - * @return boolean whether or not the write was successful - */ - private static function write($log_type, $message, $format = true, $time = false) - { - $config = Config::getInstance(); - - if (isset($config->pickles['logging']) && $config->pickles['logging']) - { - $log_path = LOG_PATH . date('Y/m/d/', ($time == false ? time() : $time)); - - if (!file_exists($log_path)) - { - mkdir($log_path, 0755, true); - } - - $log_file = $log_path . $log_type . '.log'; - - $message .= "\n"; - - if ($format == true) - { - $backtrace = debug_backtrace(); - rsort($backtrace); - $frame = $backtrace[strpos($backtrace[0]['file'], 'index.php') === false ? 0 : 1]; - - return file_put_contents($log_file, date('H:i:s') . ' ' . str_replace(getcwd(), '', $frame['file']) . ':' . $frame['line'] . ' ' . $message, FILE_APPEND); - } - else - { - return file_put_contents($log_file, $message, FILE_APPEND); - } - } - - return false; - } -} - diff --git a/src/classes/Resource.php b/src/classes/Resource.php index 6d30e88..1bce410 100644 --- a/src/classes/Resource.php +++ b/src/classes/Resource.php @@ -55,15 +55,17 @@ class Resource extends Object public $validate = []; // @todo Document this - public $status = 200; - public $message = 'OK'; - public $echo = false; - public $limit = false; - public $offset = false; - public $errors = []; - public $uids = []; - public $response = false; - public $profiler = false; + public $description = []; + public $auth = false; + public $status = 200; + public $message = 'OK'; + public $echo = false; + public $limit = false; + public $offset = false; + public $errors = []; + public $uids = []; + public $response = false; + public $profiler = false; /** * Constructor @@ -76,16 +78,28 @@ class Resource extends Object public function __construct($uids = false) { $this->uids = $uids; + $method = $_SERVER['REQUEST_METHOD']; try { // Determines if we need to serve over HTTP or HTTPS - if ($this->https && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == false)) + if ($this->https === true + || (isset($this->https[$method]) && $this->https[$method])) { - throw new Exception('400 - SSL is required.'); + if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == false) + { + throw new Exception('400 - SSL is required.'); + } + } + + // Check auth if flag is explicitly true or is true for the method + if ($this->auth === true + || (isset($this->auth[$method]) && $this->auth[$method])) + { + print_r($_SERVER); + exit('needs auth'); } - $method = $_SERVER['REQUEST_METHOD']; $filter = isset($this->filter[$method]); $validate = isset($this->validate[$method]); diff --git a/tests/classes/LogTest.php b/tests/classes/LogTest.php deleted file mode 100644 index 2376db5..0000000 --- a/tests/classes/LogTest.php +++ /dev/null @@ -1,102 +0,0 @@ -config = Config::getInstance(); - $this->config->data['pickles']['logging'] = true; - } - - public static function tearDownAfterClass() - { - File::removeDirectory(LOG_PATH); - } - - public function testInformation() - { - Log::information('information'); - - $file = LOG_PATH . date('Y/m/d/') . 'information.log'; - $data = file($file); - $line = $data[count($data) - 1]; - - $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ information$/', $line); - } - - public function testWarning() - { - Log::warning('warning'); - - $file = LOG_PATH . date('Y/m/d/') . 'warning.log'; - $data = file($file); - $line = $data[count($data) - 1]; - - $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ warning$/', $line); - } - - public function testError() - { - Log::error('error'); - - $file = LOG_PATH . date('Y/m/d/') . 'error.log'; - $data = file($file); - $line = $data[count($data) - 1]; - - $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ error$/', $line); - } - - public function testSlowQuery() - { - Log::slowQuery('slow query'); - - $file = LOG_PATH . date('Y/m/d/') . 'slow_query.log'; - $data = file($file); - $line = $data[count($data) - 1]; - - $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ slow query$/', $line); - } - - public function testTransaction() - { - Log::transaction('transaction'); - - $file = LOG_PATH . date('Y/m/d/') . 'transaction.log'; - $data = file($file); - $line = $data[count($data) - 1]; - - $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ transaction$/', $line); - } - - public function testPHPError() - { - Log::phperror('php error'); - - $file = LOG_PATH . date('Y/m/d/') . 'php_error.log'; - $data = file($file); - $line = $data[count($data) - 1]; - - $this->assertRegExp('/^php error$/', $line); - } - - public function testQuery() - { - Log::query('query'); - - $file = LOG_PATH . date('Y/m/d/') . 'query.log'; - $data = file($file); - $line = $data[count($data) - 1]; - - $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ query$/', $line); - } - - public function testLoggingDisabled() - { - $this->config->data['pickles']['logging'] = false; - - $this->assertFalse(Log::error('should return false')); - } -} -