function wpdt_init()
 {
     if (!is_admin() && current_user_can("level_10") && get_option('wpdt_quick_profiler')) {
         $this->db = new MySqlDatabase(DB_HOST, DB_USER, DB_PASSWORD);
         $this->db->connect(true);
         $this->db->changeDatabase(DB_NAME);
         $this->profiler = new PhpQuickProfiler(PhpQuickProfiler::getMicroTime());
         Console::logSpeed('Initializing...');
         if (get_option('wpdt_log_predefined_php') == 'checked') {
             //PHP Predefined Variables
             Console::log($_COOKIE, '_COOKIE');
             Console::log($_ENV, '_ENV');
             Console::log($_FILES, '_FILES');
             Console::log($_GET, '_GET');
             Console::log($PHP_SELF, '_PHP_SELF');
             Console::log($_POST, '_POST');
             Console::log($_REQUEST, '_REQUEST');
             Console::log($_SERVER, '_SERVER');
             Console::log($_SESSION, '_SESSION');
         }
         foreach ($this->filter_list as $filter) {
             if (get_option('wpdt_' . $filter) == 'checked') {
                 add_filter($filter, 'wpdt_' . $filter);
             } else {
                 remove_filter($filter, 'wpdt_' . $filter);
             }
         }
     } else {
         remove_action('init', array(&$this, 'wpdt_init'));
         remove_action('wp_footer', array(&$this, 'wpdt_end'));
     }
 }
Exemplo n.º 2
0
 public static function alert($mensagem, $log = false)
 {
     if (PROFILER) {
         if (class_exists("Console")) {
             Console::log($mensagem);
         }
     } else {
         $cod = time() . rand();
         echo "<div id=\"alert" . $cod . "\" style=\"";
         echo "border:2px solid #456abc; background-color:#ffffe7; color:#000000; ";
         echo "margin:auto; width:75%; margin-top:10px; text-align:center; ";
         echo "padding:10px; padding-top:0px; font-family: 'Times New Roman', ";
         echo "serif; font-style:italic;\">\n";
         echo "<div style=\"float:right; width:100%; text-align:right; ";
         echo "clear:both;\">\n";
         echo "<a href=\"#alert" . $cod . "\" onclick=\"";
         echo "document.getElementById('alert" . $cod . "').style.display='none';\" ";
         echo "style=\"color: #aa0000; font-size: 1em; text-decoration: none;\" ";
         echo "title=\"Fechar\">x</a></div>";
         echo "\n" . utf8_decode($mensagem) . "\n";
         echo "</div>\n";
     }
     if (NLOGS == 2 || NLOGS == 3 || $log) {
         gravalog('001', $mensagem);
         // Grava em log o Alerta
     }
 }
Exemplo n.º 3
0
 function logger($level, $msg, $method = null)
 {
     static $labels = array(100 => 'DEBUG', 200 => 'INFO', 250 => 'NOTICE', 300 => 'WARNING', 400 => 'ERROR', 500 => 'CRITICAL', 550 => 'ALERT', 600 => 'EMERGENCY', 700 => 'ALL');
     // make sure $level has the correct value
     if (is_int($level) and !isset($labels[$level]) or is_string($level) and !array_search(strtoupper($level), $labels)) {
         throw new \FuelException('Invalid level "' . $level . '" passed to logger()');
     }
     if (is_string($level)) {
         $level = array_search(strtoupper($level), $labels);
     }
     // get the levels defined to be logged
     $loglabels = \Config::get('log_threshold');
     // bail out if we don't need logging at all
     if ($loglabels == \Fuel::L_NONE) {
         return false;
     }
     // if profiling is active log the message to the profile
     if (\Config::get('profiling')) {
         \Console::log($method . ' - ' . $msg);
     }
     // if it's not an array, assume it's an "up to" level
     if (!is_array($loglabels)) {
         $a = array();
         foreach ($labels as $l => $label) {
             $l >= $loglabels and $a[] = $l;
         }
         $loglabels = $a;
     }
     // do we need to log the message with this level?
     if (!in_array($level, $loglabels)) {
         return false;
     }
     return \Log::instance()->log($level, (empty($method) ? '' : $method . ' - ') . $msg);
 }
Exemplo n.º 4
0
 /**
  * Index Page for this controller.
  *
  * Maps to the following URL
  * 		http://example.com/index.php/welcome
  *	- or -  
  * 		http://example.com/index.php/welcome/index
  *	- or -
  * Since this controller is set as the default controller in 
  * config/routes.php, it's displayed at http://example.com/
  *
  * So any other public methods not prefixed with an underscore will
  * map to /index.php/welcome/<method_name>
  * @see http://codeigniter.com/user_guide/general/urls.html
  */
 public function index()
 {
     $arg = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
     Console::log($arg);
     $this->output->enable_profiler(true);
     $this->load->view('welcome_message');
 }
Exemplo n.º 5
0
 public function index()
 {
     $this->load->spark('Debug-Toolbar/1.x.x');
     $this->load->library('console');
     $this->output->enable_profiler(true);
     Console::log('Hey, this is really cool');
     $this->load->view('index');
 }
Exemplo n.º 6
0
 function logger($level, $msg, $method = null)
 {
     if (Config::get('profiling')) {
         \Console::log($method . ' - ' . $msg);
     }
     if ($level > \Config::get('log_threshold')) {
         return false;
     }
     \Log::write($level, $msg, $method);
 }
Exemplo n.º 7
0
Arquivo: base.php Projeto: hymns/fuel
 function logger($level, $msg, $method = null)
 {
     !class_exists('Fuel\\Core\\Log') and import('log');
     !class_exists('Log') and class_alias('Fuel\\Core\\Log', 'Log');
     if (Config::get('profiling')) {
         \Console::log($method . ' - ' . $msg);
     }
     if ($level > \Config::get('log_threshold')) {
         return false;
     }
     \Log::write($level, $msg, $method);
 }
Exemplo n.º 8
0
 /**
  * BrowseNodeをTopSellersを取得して結果を配列で返す
  * 
  * @param (array|string) $conditions 検索条件
  * @return array 検索結果
  */
 public function getTopSellersByNode($conditions)
 {
     $_ = $this;
     $AmazonSearch = new AmazonSearchLib();
     $params = array_merge($_->params, $conditions);
     $result = $AmazonSearch->getTopSellersByNode($params, $_->secretKey);
     if ($_->dispatch_trace) {
         Console::log('AmazonschModel::get');
         Console::log($result);
     }
     return $result;
 }
Exemplo n.º 9
0
 public function mark($file, $line, $msg = '##MARK##')
 {
     if ($this->status != self::PROFILER_STATUS_STARTED) {
         $this->restart();
     }
     $now = $this->_getCurrentTime();
     $elapsed = $now - $this->startTime;
     $elapsed = sprintf('%f seconds', $elapsed);
     $timestamp = sprintf('[@%f]', $now);
     $mark = "{$timestamp} {$msg} <br />in {$file} at line {$line} after {$elapsed}";
     $this->log[] = $mark;
     Console::log($mark, 'profile');
 }
Exemplo n.º 10
0
 /**
  * @uses SimpleLog_Receiver
  * @param string $event
  * @param int|string|null $objectId
  * @param int|null $userId
  * @param string|array|object|null $additionalData
  */
 function trigger($event, $objectId = null, $userId = null, $additionalData = null, $alert = false)
 {
     global $config;
     if (class_exists('Console')) {
         Console::log($event, 'SimpleLog::trigger');
     }
     
     $instance = SimpleLog_Receiver::getInstance();
     $instance->trigger($event, $objectId, $userId, $additionalData);
     
     if ($alert) {
         mail($config['systemEmail'], $event, print_r(array('Object ID' => $objectId, 'User ID' => $userId, 'Additional Data' => $additionalData), 1), 'From: ' . $config['systemEmail']);
     }
 }
Exemplo n.º 11
0
 protected final function createTable($tableName, $options, $tableInfo = '')
 {
     \Console::log("Creating table {0}...\n", [$tableName], [\Console::FG_YELLOW]);
     if (is_array($options)) {
         $a = [];
         foreach ($options as $key => $value) {
             $a[] = is_string($key) ? "`{$key}` {$value}" : $value;
         }
         $options = implode(',', $a);
     }
     $query = "CREATE TABLE `{$tableName}` ({$options}) {$tableInfo}";
     \Console::log("{$query}\n\n");
     CW::$app->db->executeUpdate($query);
 }
Exemplo n.º 12
0
 /**
  * Write Log File
  *
  * Generally this function will be called using the global log_message() function
  *
  * @access	public
  * @param	string	the error level
  * @param	string	the error message
  * @return	bool
  */
 public static function write($level, $msg, $method = null)
 {
     if ($level > \Config::get('log_threshold')) {
         return false;
     }
     switch ($level) {
         case \Fuel::L_ERROR:
             $level = 'Error';
             break;
         case \Fuel::L_DEBUG:
             $level = 'Debug';
             break;
         case \Fuel::L_INFO:
             $level = 'Info';
             break;
     }
     if (Config::get('profiling')) {
         \Console::log($method . ' - ' . $msg);
     }
     $filepath = \Config::get('log_path') . date('Y/m') . '/';
     if (!is_dir($filepath)) {
         $old = umask(0);
         mkdir($filepath, 0777, true);
         chmod($filepath, 0777);
         umask($old);
     }
     $filename = $filepath . date('d') . '.php';
     $message = '';
     if (!file_exists($filename)) {
         $message .= "<" . "?php defined('COREPATH') or exit('No direct script access allowed'); ?" . ">" . PHP_EOL . PHP_EOL;
     }
     if (!($fp = @fopen($filename, 'a'))) {
         return false;
     }
     $call = '';
     if (!empty($method)) {
         $call .= $method;
     }
     $message .= $level . ' ' . ($level == 'info' ? ' -' : '-') . ' ';
     $message .= date(\Config::get('log_date_format'));
     $message .= ' --> ' . (empty($call) ? '' : $call . ' - ') . $msg . PHP_EOL;
     flock($fp, LOCK_EX);
     fwrite($fp, $message);
     flock($fp, LOCK_UN);
     fclose($fp);
     $old = umask(0);
     @chmod($filename, 0666);
     umask($old);
     return true;
 }
Exemplo n.º 13
0
 function __construct()
 {
     global $db;
     $configs = $db->query('SELECT * FROM {{table}}', 'plugins');
     while ($plugin = mysql_fetch_array($configs)) {
         $this->config_plugins[$plugin['name_plugins']] = array('id' => $plugin['id_plugins'], 'acti' => $plugin['activate_plugins'], 'menu' => $plugin['menu_plugins'], 'page' => $plugin["page_plugins"], 'pos' => $plugin["pos_plugins"]);
     }
     Console::log($this->config_plugins);
     foreach ($GLOBALS as $a => $b) {
         if (preg_match("/_root/i", $a)) {
             $this->root = $b;
             break;
         }
     }
 }
Exemplo n.º 14
0
	public function sampleConsoleData() {
		try {
			Console::log('Begin logging data');
			Console::logMemory($this, 'PQP Example Class : Line '.__LINE__);
			Console::logSpeed('Time taken to get to line '.__LINE__);
			Console::log(array('Name' => 'Ryan', 'Last' => 'Campbell'));
			Console::logSpeed('Time taken to get to line '.__LINE__);
			Console::logMemory($this, 'PQP Example Class : Line '.__LINE__);
			Console::log('Ending log below with a sample error.');
			throw new Exception('Unable to write to log!');
		}
		catch(Exception $e) {
			Console::logError($e, 'Sample error logging.');
		}
	}
Exemplo n.º 15
0
 /**
  * Search for companies
  *
  * @param string $keyword Query string
  * @param int $limit      Max number of results
  * @return array
  *
  * @url GET search
  * @url GET search/{keyword}
  * @url GET search/{keyword}/{limit}
  * @access protected
  */
 function search($keyword = NULL, $limit = NULL)
 {
     if ($limit && !is_int($limit)) {
         return;
     }
     if (!$limit) {
         $limit = 10;
     }
     $return = array();
     Console::log("test");
     $query = "SELECT company_ID, company_name, company_url, company_phone" . " FROM companies C" . " WHERE" . " (company_name LIKE '%{{keyword}}%' OR company_details LIKE '%{{keyword}}%' OR company_url LIKE '%{{keyword}}%')" . " LIMIT 0,{{limit}}";
     $companies = $this->db->query($query, array('keyword' => $keyword, 'limit' => $limit));
     while ($companies && ($company = $this->db->fetch_assoc($companies))) {
         $return[] = $company;
     }
     return $return;
 }
Exemplo n.º 16
0
    public function __destruct() 
	{
		$tempDB = new tempDB();
		$tempDB->queryCount = MyDB::$queryCount;
		$tempDB->queries = MyDB::$queries;


		//log all the duplicate sql's
		$queries = MyDB::$queries;
		foreach ($queries as $q)
		{
			$sql[] = $q['sql'];
		}
		$dups = array_unique(array_diff_assoc($sql,array_unique($sql)));
		Console::log($dups);

        if ($this->debug) $this->profiler->display($tempDB);
    }
Exemplo n.º 17
0
 /**
  * 結果を返す
  * 
  * @param (array|string) $conditions 検索条件
  * @return array 検索結果
  */
 public function get($filePath)
 {
     $_ = $this;
     $_->Excel->load($_->APP_ROOT . "/{$filePath}");
     $periodColumn = 0;
     $salesVolumeColumn = 1;
     $profitColumn = 2;
     $performance = [];
     for ($row = 6; $row <= 16; $row++) {
         $period = $_->Excel->getCellValue($periodColumn, $row);
         $salesVolume = $_->Excel->getCellValue($salesVolumeColumn, $row);
         $profit = $_->Excel->getCellValue($profitColumn, $row);
         $performance[$period]['sales'] = $salesVolume;
         $performance[$period]['profit'] = $profit;
     }
     if ($_->dispatch_trace) {
         Console::log('ExcelModel::get');
         Console::log($performance);
     }
     return $performance;
 }
Exemplo n.º 18
0
 /**
  * Write Log File
  *
  * Generally this function will be called using the global log_message() function
  *
  * @access	public
  * @param	int|string	the error level
  * @param	string	the error message
  * @param	string	information about the method
  * @return	bool
  */
 public static function write($level, $msg, $method = null)
 {
     // defined default error labels
     static $oldlabels = array(1 => 'Error', 2 => 'Warning', 3 => 'Debug', 4 => 'Info');
     // get the levels defined to be logged
     $loglabels = \Config::get('log_threshold');
     // bail out if we don't need logging at all
     if ($loglabels == \Fuel::L_NONE) {
         return false;
     }
     // if it's not an array, assume it's an "up to" level
     if (!is_array($loglabels)) {
         $a = array();
         foreach (static::$levels as $l => $label) {
             $l >= $loglabels and $a[] = $l;
         }
         $loglabels = $a;
     }
     // if profiling is active log the message to the profile
     if (\Config::get('profiling')) {
         \Console::log($method . ' - ' . $msg);
     }
     // convert the level to monolog standards if needed
     if (is_int($level) and isset($oldlabels[$level])) {
         $level = strtoupper($oldlabels[$level]);
     }
     if (is_string($level)) {
         if (!($level = array_search($level, static::$levels))) {
             $level = 250;
             // can't map it, convert it to a NOTICE
         }
     }
     // make sure $level has the correct value
     if (is_int($level) and !isset(static::$levels[$level]) or is_string($level) and !array_search(strtoupper($level), static::$levels)) {
         throw new \FuelException('Invalid level "' . $level . '" passed to logger()');
     }
     // do we need to log the message with this level?
     if (!in_array($level, $loglabels)) {
         return false;
     }
     // log the message
     static::instance()->log($level, (empty($method) ? '' : $method . ' - ') . $msg);
     return true;
 }
Exemplo n.º 19
0
 /**
  * リクエストされたURLに対応するコントローラーを起動する
  *
  * @return void
  */
 public static function dispatch()
 {
     $tArray = explode('/', __DIR__);
     array_pop($tArray);
     $APP_ROOT = implode('/', $tArray);
     self::setPathAndAction($APP_ROOT);
     if (self::$trace) {
         Console::log(date("Y-m-d H:i:s"));
         Console::log('classFile=' . self::$classFile);
         Console::log('action=' . self::$action);
         Console::log('path=' . self::$path);
     }
     global $dataBridge;
     $dataBridge = new DataBridge();
     $dataBridge->APP_ROOT = $APP_ROOT;
     $dataBridge->dispatch_path = self::$path;
     $dataBridge->dispatch_class = self::$class;
     $dataBridge->dispatch_action = self::$action;
     $dataBridge->dispatch_lang = self::$lang;
     $dataBridge->dispatch_trace = self::$trace;
     $class = new self::$class();
     $action = self::$action;
     $class->{$action}();
 }
Exemplo n.º 20
0
 private function logit($message = '', $level = 'debug')
 {
     if (empty($message)) {
         return;
     }
     if (class_exists('Console')) {
         Console::log($message);
     }
     log_message($level, $message);
 }
Exemplo n.º 21
0
 /**
  * Checks if a password overlaps with a user inputed data
  *
  * @param string $password Password
  * @return bool
  */
 function user_input_data($password)
 {
     if (!$this->getId()) {
         Console::log("Password Contain User Data (No User ID) FAILED");
         return false;
     }
     $return = true;
     $data = array("user_email", "user_username", "user_name_first", "user_name_last", "user_phone");
     $r = $this->db->select("users", array("user_ID" => $this->getId()), $data);
     if (!$r) {
         Console::log("Password Contain User Data (No User) FAILED");
         return false;
     }
     $user = $this->db->fetch_assoc($r);
     $words = array();
     foreach ($user as $key => $value) {
         if (!strlen($value)) {
             continue;
         }
         if (!$this->password_similarity($password, $value)) {
             $words[] = $value;
             $return = false;
         }
     }
     if ($return) {
         Console::log("Password Contain User Data PASSED");
     } else {
         $this->errors["user_input_data"] = "Too similar too " . implode(", ", $words) . ".";
         Console::log("Password Contain User Data FAILED");
     }
     return $return;
 }
 /**
  * Define the list
  * @public
  */
 function def_list()
 {
     Console::log('FormHandler -> def_list');
     Console::logMemory($this, 'FormHandler -> def_list : Line ' . __LINE__);
     Console::logSpeed('FormHandler -> def_list : Line ' . __LINE__);
     $this->tablelist['status_list']["1"] = array(gettext("INSERTED"), "1");
     $this->tablelist['status_list']["2"] = array(gettext("ENABLE"), "2");
     $this->tablelist['status_list']["3"] = array(gettext("DISABLE"), "3");
     $this->tablelist['status_list']["4"] = array(gettext("FREE"), "4");
 }
Exemplo n.º 23
0
 /**
  * セッショントークンを保存する
  *
  * @return boolean
  **/
 public function setToken()
 {
     $_ = $this;
     if (!isset($_SESSION)) {
         session_start();
     }
     if ($_SESSION[$_->SESSION_NAME]['token'] = $_->generateToken()) {
         if ($_->dispatch_trace) {
             Console::log('SESSION_NAME=' . $_->SESSION_NAME);
             Console::log($_SESSION[$_->SESSION_NAME]);
         }
         return $_SESSION[$_->SESSION_NAME]['token'];
     } else {
         return false;
     }
 }
Exemplo n.º 24
0
 /**
  * Write Log File
  *
  * Generally this function will be called using the global log_message() function
  *
  * @access	public
  * @param	int|string	the error level
  * @param	string	the error message
  * @param	string	information about the method
  * @return	bool
  */
 public static function write($level, $msg, $method = null)
 {
     // defined default error labels
     static $labels = array(1 => 'Error', 2 => 'Warning', 3 => 'Debug', 4 => 'Info');
     // get the levels defined to be logged
     $loglabels = \Config::get('log_threshold');
     // bail out if we don't need logging at all
     if ($loglabels == \Fuel::L_NONE) {
         return false;
     }
     // if it's not an array, assume it's an "up to" level
     if (!is_array($loglabels)) {
         $loglabels = array_keys(array_slice($labels, 0, $loglabels, true));
     }
     // if $level is string, it is custom level.
     if (is_int($level)) {
         // do we need to log the message with this level?
         if (!in_array($level, $loglabels)) {
             return false;
         }
         // store the label for this level for future use
         $level = $labels[$level];
     }
     // if profiling is active log the message to the profile
     if (Config::get('profiling')) {
         \Console::log($method . ' - ' . $msg);
     }
     // and write it to the logfile
     $filepath = \Config::get('log_path') . date('Y/m') . '/';
     if (!is_dir($filepath)) {
         $old = umask(0);
         mkdir($filepath, \Config::get('file.chmod.folders', 0777), true);
         umask($old);
     }
     $filename = $filepath . date('d') . '.php';
     $message = '';
     if (!($exists = file_exists($filename))) {
         $message .= "<" . "?php defined('COREPATH') or exit('No direct script access allowed'); ?" . ">" . PHP_EOL . PHP_EOL;
     }
     if (!($fp = @fopen($filename, 'a'))) {
         return false;
     }
     $call = '';
     if (!empty($method)) {
         $call .= $method;
     }
     $message .= $level . ' ' . ($level == 'info' ? ' -' : '-') . ' ';
     $message .= date(\Config::get('log_date_format'));
     $message .= ' --> ' . (empty($call) ? '' : $call . ' - ') . $msg . PHP_EOL;
     flock($fp, LOCK_EX);
     fwrite($fp, $message);
     flock($fp, LOCK_UN);
     fclose($fp);
     if (!$exists) {
         $old = umask(0);
         @chmod($filename, \Config::get('file.chmod.files', 0666));
         umask($old);
     }
     return true;
 }
 /**
  * Add in any Benchmark Results to the PQP Profiler
  *
  * @return void
  * @author Dan Morin
  **/
 static function pqp_benchmark_results()
 {
     $CI = get_instance();
     $profile = array();
     foreach ($CI->benchmark->marker as $key => $val) {
         // We match the "end" marker so that the list ends
         // up in the order that it was defined
         if (preg_match("/(.+?)_end/i", $key, $match)) {
             if (isset($CI->benchmark->marker[$match[1] . '_end']) and isset($CI->benchmark->marker[$match[1] . '_start'])) {
                 $profile[$match[1]] = $CI->benchmark->elapsed_time($match[1] . '_start', $key);
             }
         }
     }
     foreach ($profile as $key => $val) {
         $key = ucwords(str_replace(array('_', '-'), ' ', $key));
         Console::log('CI BENCHMARK - ' . $key . ': ' . $val);
     }
     Console::log('GET: ' . print_r($_GET, TRUE));
     Console::log('POST: ' . print_r($_POST, TRUE));
 }
Exemplo n.º 26
0
    private function __construct($isConsoleApp)
    {
        $this->isConsoleApp = $isConsoleApp;
        if (!$this->isConsoleApp) {
            session_start();
            $this->user = new \components\web\User();
        }
        $this->request = Request::getInstance();
        $this->response = Response::getInstance();
        set_error_handler(function ($errno, $errstr, $errfile, $errline) {
            if ('dev' === CW_ENV) {
                if ($this->isConsoleApp) {
                    if (in_array($errno, [E_USER_WARNING, E_WARNING])) {
                        $errType = "WARNING";
                    } else {
                        if (in_array($errno, [E_USER_NOTICE, E_NOTICE])) {
                            $errType = "NOTICE";
                        } else {
                            $errType = "ERROR";
                        }
                    }
                    \Console::log("{0}\n", ["{$errType}:\n{$errstr} on line {$errline} in {$errfile}"], [Console::FG_RED]);
                } else {
                    $msg = <<<HTML
                <div style="width : 100%; border : 2px solid black;">
                    error_no = {$errno}<br/>
                    error    = {$errstr}<br/>
                    file     = {$errfile}<br/>
                    line     = {$errline}<br/>
                </div>
HTML;
                }
                throw new ErrorException($msg);
            }
        });
        set_exception_handler(function ($e) {
            $this->__get('db')->rollback();
            $this->__get('db')->close();
            if (ob_get_length()) {
                ob_clean();
            }
            $this->response->setContentType('text/html');
            try {
                if ('prod' !== CW_ENV) {
                    echo '<h1>EXCEPTION:</h1><pre>';
                    var_dump($e);
                    echo '</pre>';
                    echo '<br/><br/><br/><h1>STACK TRACE:</h1><pre>';
                    print_r(debug_backtrace());
                    echo '</pre>';
                } else {
                    if (null === $this->controllerInst) {
                        $this->controllerInst = new \controllers\BaseController();
                    }
                    echo $this->renderView($this->controllerInst->doError($e), $this->controllerInst->actionId, $this->controllerInst->id);
                    exit;
                }
            } catch (\Exception $e) {
                echo 'An error occurred while processing another error.';
            }
        });
    }
Exemplo n.º 27
0
<?php

require_once '/home/nobu/composer/console/index.php';
$console = new Console();
$console->log(1, true, null, 'string', array(1, 2, 3, 4));
throw new Exception('bad');
Exemplo n.º 28
0
 /**
  * MODELをインスタンス化して返す。
  * 予め、model/ の下にMODELクラスの定義ファイルを作成しておく。
  * MODELがDBを扱う場合はDataListやDataRecordを継承したクラスにする。
  *
  * @see lib/DataList.php
  * @see lib/DataRecord.php
  * @param string $modelName モデル名
  * @return (object|boolean) MODELクラスのインスタンス。失敗したらfalse
  */
 public function getModel($modelName)
 {
     if (isset(self::$model_instances[$modelName]) && is_object(self::$model_instances[$modelName])) {
         return self::$model_instances[$modelName];
     } else {
         $pathChecker = function ($my, $modelName) {
             $separator = '_';
             //区切り文字
             $tmp = preg_replace('/([a-z])([A-Z])/', "\$1{$separator}\$2", $modelName);
             // "sampleModelList" => "sample_Model_List"
             $tmpArray = explode('_', $tmp);
             do {
                 $dmy = array_pop($tmpArray);
                 $modelGroup = lcfirst(implode('', $tmpArray));
                 $filePath = $my->APP_ROOT . "/model/{$modelGroup}/{$modelName}.php";
                 if (file_exists($filePath)) {
                     return $filePath;
                 }
             } while (!empty($tmpArray));
             Console::log("Error! : modelClassFile {$filePath} is not found.");
             return false;
         };
         if ($filePath = $pathChecker($this, $modelName)) {
             if (!class_exists($modelName)) {
                 require_once $filePath;
             }
             self::$model_instances[$modelName] = new $modelName();
             return self::$model_instances[$modelName];
         } else {
             Console::log("Error! : model {$modelName} is not found.");
             return false;
         }
     }
 }
Exemplo n.º 29
0
 /**
  * Log an error to the Console (if loaded) and to the log files.
  *
  * @param string $message The string to write to the logs.
  * @param string $level   The log level, as per CI log_message method.
  *
  * @return boolean/void False if $message is empty.
  */
 protected function logit($message = '', $level = 'debug')
 {
     if (empty($message)) {
         return false;
     }
     if (class_exists('Console', false)) {
         Console::log($message);
     }
     log_message($level, $message);
 }
Exemplo n.º 30
0
 /**
  * 商品をIDで検索して結果を配列で返す
  * 
  * @param array $my_params 検索APIのパラメータを指定
  * @param string $secret_access_key シークレットキー
  * @return array|string 成功した場合は検索結果の商品データ配列。失敗した場合はAamzonが返す生XML
  */
 public function getById($params, $secret_key)
 {
     $_ = $this;
     $params['Operation'] = 'ItemLookup';
     $end_point_url = $_->getUrl($params, $secret_key);
     $xml = simplexml_load_file($end_point_url);
     if (!$_->isValid($xml)) {
         if ($_->dispatch_trace) {
             Console::log('AmazonSearchLib::getById -Amazon API error:' . date('Y/m/d H:i:s'));
         }
         return $xml;
     }
     $productsSet = [];
     $i = 1;
     foreach ($xml->Items->Item as $Item) {
         $p = $_->parseItem($Item);
         $p['Item'] = $Item;
         $productsSet[$i] = $p;
         $i++;
     }
     return $productsSet;
 }