Exemplo n.º 1
0
 /**
  * Render a list of messages
  *
  * @param   array  $messages
  * @return  string
  */
 public function render($messages = null)
 {
     if ($messages) {
         $this->setMessages($messages);
     }
     $messages = $this->getMessages();
     foreach ($messages as $item) {
         $this->_logger->debug(print_r($item['var'], true));
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function request($uri, $method = 'GET', $parameters = [], $headers = [])
 {
     $this->requestArguments = ['uri' => $uri, 'method' => $method, 'parameters' => $parameters, 'headers' => $headers];
     $this->requestHeader = array_merge($this->requestHeader, $headers);
     $response = null;
     try {
         if ('GET' == $method) {
             $response = $this->client->get($uri, ['query' => $parameters, 'headers' => $this->requestHeader]);
         }
         if ('POST' == $method) {
             $response = $this->client->post($uri, ['form_params' => $parameters, 'headers' => $this->requestHeader]);
         }
     } catch (\Exception $e) {
         $response = $e->getResponse();
         $this->responseClientError = $e->getMessage();
     }
     if (!$this->responseClientError) {
         $this->responseBody = $response->getBody();
         $this->responseHttpCode = $response->getStatusCode();
         $this->responseHeader = $response->getHeaders();
     }
     if ($this->logger) {
         $this->logger->debug("HttpClient\\Guzzle::request( {$uri}, {$method} ), response:", $this->getResponse());
         if ($this->responseClientError) {
             $this->logger->error("HttpClient\\Guzzle::request( {$uri}, {$method} ), GuzzleHttp error: ", [$this->responseClientError]);
         }
     }
     return $this->responseBody;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function request($uri, $method = 'GET', $parameters = [], $headers = [])
 {
     $this->requestArguments = ['uri' => $uri, 'method' => $method, 'parameters' => $parameters, 'headers' => $headers];
     $curl = curl_init();
     if ('GET' == $method) {
         unset($this->curlOptions[CURLOPT_POST]);
         unset($this->curlOptions[CURLOPT_POSTFIELDS]);
         $uri = $uri . (strpos($uri, '?') ? '&' : '?') . http_build_query($parameters);
     }
     if ('POST' == $method) {
         $this->curlOptions[CURLOPT_POST] = true;
         $this->curlOptions[CURLOPT_POSTFIELDS] = $parameters;
     }
     $this->requestHeader = array_merge($this->requestHeader, $headers);
     $this->requestArguments['headers'] = $this->requestHeader;
     $this->curlOptions[CURLOPT_URL] = $uri;
     $this->curlOptions[CURLOPT_HTTPHEADER] = $this->prepareRequestHeaders();
     $this->curlOptions[CURLOPT_HEADERFUNCTION] = [$this, 'fetchResponseHeader'];
     foreach ($this->curlOptions as $opt => $value) {
         curl_setopt($curl, $opt, $value);
     }
     $response = curl_exec($curl);
     $this->responseBody = $response;
     $this->responseHttpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     $this->responseClientError = curl_error($curl);
     $this->responseClientInfo = curl_getinfo($curl);
     if ($this->logger) {
         $this->logger->debug("HttpClient\\Curl::request( {$uri}, {$method} ), response:", $this->getResponse());
         if (false === $response) {
             $this->logger->error("HttpClient\\Curl::request( {$uri}, {$method} ), curl_exec error: ", [$this->responseClientError]);
         }
     }
     curl_close($curl);
     return $this->responseBody;
 }
Exemplo n.º 4
0
 /**
  * Echo log message to CLI or web.
  *
  * @access private
  */
 private function echoMessage()
 {
     if (!nZEDb_DEBUG) {
         return;
     }
     // Check if this is CLI or web.
     if ($this->outputCLI) {
         echo $this->colorCLI->debug($this->logMessage);
     } else {
         echo '<pre>' . $this->logMessage . '</pre><br />';
     }
 }
Exemplo n.º 5
0
 /**
  * Return an array of results given a query resource
  *
  * @param resource $result Result set to get results from
  * @return array The results as an associative array
  */
 function fetch($result)
 {
     // fetchRow() returns the row, NULL on no more data or a
     // DB_Error, when an error occurs.
     $row = $result->fetchRow();
     // Always check that $result is not an error
     if (DB::isError($row)) {
         $this->foowd->debug('msg', $row->getMessage());
         return FALSE;
     }
     return $row;
 }
Exemplo n.º 6
0
 /**
  * 增加一个cache项
  *
  * @param string $sKey            
  * @param mixed $mValue            
  * @param int $iTll            
  */
 public function add($sKey, $mValue, $iTll)
 {
     if ($this->oDebug) {
         $iStartTime = microtime(true);
         self::$iOptCnt++;
         $ret = $this->oCache->add($sKey, $mValue, MEMCACHE_COMPRESSED, $iTll);
         $iUseTime = microtime(true) - $iStartTime;
         self::$iTotalTime += $iUseTime;
         $this->oDebug->groupCollapsed('Memcache add ' . $sKey . ' :' . round($iUseTime * 1000, 2) . '毫秒');
         $this->oDebug->debug($mValue);
         $this->oDebug->groupEnd();
     } else {
         $ret = $this->oCache->add($sKey, $mValue, MEMCACHE_COMPRESSED, $iTll);
     }
     return $ret;
 }
Exemplo n.º 7
0
 /**
  * Check if an object is referenced in the object reference array.
  *
  * @access protected
  * @param array indexes Array of indexes and values to find object by
  * @param string source The source to fetch the object from
  */
 function &checkLoadedReference($indexes, $source)
 {
     $this->db->getSource($source, $source, $tmp);
     $hash = '';
     ksort($indexes);
     foreach ($indexes as $key => $value) {
         if ($hash != '') {
             $hash .= '_';
         }
         $hash .= $value;
     }
     $this->foowd->debug('msg', 'CHECK Hash: ' . $hash);
     if (isset($this->objects[$source][$hash])) {
         $this->foowd->debug('msg', 'CHECK Using exising loaded reference');
         return $this->objects[$source][$hash];
     }
     return FALSE;
 }
Exemplo n.º 8
0
 /**
  * Send the request.
  * @return Curl
  * @throws PBMErrorException()
  */
 protected function send()
 {
     $this->log->debug('Checking connection certificates.');
     $this->checkCert($this->cainfo);
     $this->checkCert($this->sslcert);
     if (!$this->sslcertPwd) {
         throw new PBMErrorException('Missing certificate password!');
     }
     switch (strtolower($this->type)) {
         case 'get':
         case 'delete':
             if ($this->data) {
                 $this->url .= '?' . $this->data;
             }
             break;
         case 'post':
         case 'put':
             curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->data);
             break;
         default:
             throw new PBMErrorException('Unsupported request type: ' . $this->type);
     }
     $curl_file = tempnam('', 'res');
     $handle = fopen($curl_file, 'w');
     if ($this->debug) {
         curl_setopt($this->ch, CURLOPT_VERBOSE, true);
         curl_setopt($this->ch, CURLOPT_STDERR, $handle);
     }
     $this->body = curl_exec($this->ch);
     $this->status = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
     if ($error = curl_errno($this->ch)) {
         $this->log->error('cURL error code: ' . $error);
         $this->log->error('cURL message: ' . curl_error($this->ch));
     }
     if ($this->debug) {
         $this->log->debug('Curl result: ' . file_get_contents($curl_file));
     }
     fclose($handle);
     unlink($curl_file);
     return $this;
 }
 /**
  * Called after postTrigger
  *
  * @param   object  $event  The event
  * @return  void
  */
 private function postProcess(Event $event)
 {
     $skipped = false;
     foreach ($this->dispatcher->getListeners($event) as $listener) {
         if (!$listener instanceof TraceableListener) {
             // A new listener was added during dispatch.
             continue;
         }
         // Unwrap listener
         //$this->dispatcher->removeListener($listener, $event);
         //$this->dispatcher->addListener($listener->getWrappedListener(), $event);
         $priority = $this->dispatcher->getListenerPriority($listener, $event);
         $this->dispatcher->getListeners()[$event->getName()]->remove($listener);
         $this->dispatcher->getListeners()[$event->getName()]->add($listener->getWrappedListener(), $priority);
         $info = $this->getListenerInfo($listener->getWrappedListener(), $event->getName());
         $eventName = $event->getName();
         if ($listener->wasCalled()) {
             if (null !== $this->logger) {
                 $this->logger->debug(sprintf('Notified event "%s" to listener "%s".', $eventName, $info['pretty']));
             }
             if (!isset($this->called[$eventName])) {
                 $this->called[$eventName] = new \SplObjectStorage();
             }
             $this->called[$eventName]->attach($listener);
         }
         if (null !== $this->logger && $skipped) {
             $this->logger->debug(sprintf('Listener "%s" was not called for event "%s".', $info['pretty'], $eventName));
         }
         if ($listener->stoppedPropagation()) {
             if (null !== $this->logger) {
                 $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s".', $info['pretty'], $eventName));
             }
             $skipped = true;
         }
     }
 }
Exemplo n.º 10
0
 /**
  * Execute a raw SQL query on the database.
  *
  * @param string $sql Raw SQL string to execute.
  * @param array &$values Optional array of bind values
  * @return mixed A result set object
  */
 public function query($sql, &$values = [])
 {
     /* if ($this->logging)
         {
         $this->logger->log($sql);
         if ($values)
         {
         $this->logger->log($values);
         }
         }
        *
        */
     if ($this->logging) {
         $this->logger->debug($sql);
         if ($values) {
             $this->logger->logger->debug("Values:", $values);
         }
     }
     $this->last_query = $sql;
     try {
         if (!($sth = $this->connection->prepare($sql))) {
             throw new ExceptionDatabase($this);
         }
     } catch (\PDOException $e) {
         throw new ExceptionDatabase($this);
     }
     $sth->setFetchMode(\PDO::FETCH_ASSOC);
     try {
         if (!$sth->execute($values)) {
             throw new ExceptionDatabase($this);
         }
     } catch (\PDOException $e) {
         throw new ExceptionDatabase($e);
     }
     return $sth;
 }
 /**
  * Logs memory use.
  */
 private function _logMemoryUse()
 {
     if ($this->logger) {
         $this->logger->debug(sprintf('Memory usage (currently) %dKB/ (max) %dKB', round(memory_get_usage(true) / 1024), memory_get_peak_usage(true) / 1024));
     }
 }
Exemplo n.º 12
0
 /**
  * Determine if a job should be executed
  *
  * @param   array   $job
  * @param   object  $logger
  * @param   float   $timestamp
  *
  * @return  bool
  * @throws  \Exception
  */
 private static function shouldRunJob($job, $logger, $timestamp)
 {
     $expression = implode(" ", array($job['min'], $job['hour'], $job['dayofmonth'], $job['month'], $job['dayofweek'], $job['year']));
     if (empty($job['lastrun'])) {
         $next_calculated_run = (int) $job['firstrun'];
     } else {
         $last_date = date_create();
         date_timestamp_set($last_date, (int) $job['lastrun']);
         try {
             $cron = CronExpression::factory($expression);
             $next_calculated_run = $cron->getNextRunDate($last_date)->format('U');
         } catch (Exception $e) {
             $logger->error("Job " . $job['name'] . " cannot be executed due to cron parsing error", array("ERROR" => $e->getMessage(), "ERRID" => $e->getCode()));
             return false;
         }
     }
     $torun = $next_calculated_run <= $timestamp ? true : false;
     $logger->debug("Job " . $job['name'] . ($torun ? " will be" : " will not be") . " executed", array("EXPRESSION" => $expression, "FIRSTRUNDATE" => date('c', $job['firstrun']), "LASTRUNDATE" => date('c', $job['lastrun']), "NEXTRUN" => date('c', $next_calculated_run)));
     return $torun;
 }
Exemplo n.º 13
0
Arquivo: Orm.php Projeto: pancke/yyaf
 /**
  * 执行SQL
  *
  * @param string $sSQL
  * @param array $aParam
  * @param boolean $bStrictMaster
  * @param boolean $bIsADU
  * @return unknown
  */
 protected function _exectue($sSQL, $aParam, $bStrictMaster, $bIsADU = false)
 {
     $iStartTime = microtime(true);
     ++self::$_iQueryCnt;
     self::$_aSQLs[] = $this->_sLastSQL = $sSQL;
     $db = $bStrictMaster ? $this->_getMasterDB() : $this->_getSlaveDB();
     $this->_oSth = $db->prepare($sSQL);
     if (!empty($aParam)) {
         $this->_bindParams($aParam);
     }
     $bRet = $this->_oSth->execute();
     if (false === $bRet) {
         $sMsg = 'SQL Error: ' . $this->_formatSQL($sSQL, $aParam) . "\n";
         $sMsg .= join("\n", $this->_oSth->errorInfo());
         throw new Exception($sMsg);
         return 0;
     }
     $iUseTime = round((microtime(true) - $iStartTime) * 1000, 2);
     self::$_iUseTime += $iUseTime;
     $iAffectedRows = $this->_oSth->rowCount();
     if ($this->_oDebug) {
         $this->_oDebug->debug('[DB->' . $this->_sDbName . ']: ' . $this->_formatSQL($sSQL, $aParam) . ' AffectedRows:' . $iAffectedRows . ' Use Time:' . $iUseTime . '毫秒');
     }
     // 记录增删改日志
     if ($bIsADU) {
         self::_addADUSQL('[DB->' . $this->_sDbName . ']: ' . $this->_formatSQL($sSQL, $aParam) . ' AffectedRows:' . $iAffectedRows . ' Use Time:' . $iUseTime . '毫秒');
     }
     if ($iAffectedRows > 0 && $bIsADU) {
         $this->clearWhereCache();
     }
     return $iAffectedRows;
 }
 function extract_title()
 {
     preg_match('~(</head>|<body>|(<title>\\s*(.*?)\\s*</title>))~i', $this->response, $m);
     $this->e->debug("referer title extract: " . print_r($m, true));
     return $m[3];
 }
Exemplo n.º 15
0
 /**
  * writeDebugLogByMsg
  * 
  * 
  * @access  private
  * @author  M.Ozeki
  * @version $Id: IRJDisplayCommon_cls.php, v 1.0 2008/04/01 14:00 Exp $
  * @return 
  */
 function writeDebugLogByMsg($sMsg)
 {
     $this->_oLogObj->debug($this->createMsg($sMsg));
 }
Exemplo n.º 16
0
 /**
  * Prints some debug info to the frontend.
  *
  */
 public function debugInfo()
 {
     if (!empty($this->db->countQueries)) {
         $count_queries = $this->db->countQueries;
     } else {
         $count_queries = 0;
     }
     if ($this->configuration['queries_count']) {
         if (!empty($this->core->themeFile)) {
             $memory_used = memory_get_peak_usage();
             $time_spent = intval((microtime(true) - $GLOBALS['start_time']) * 1000);
             print $this->mod->debug($count_queries, number_format($memory_used / 1000000, 2, '.', ' '), $time_spent);
         }
     }
 }
Exemplo n.º 17
0
 /**
  *
  *
  * @access private
  */
 function _sendArticle($article)
 {
     /* data should be in the format specified by RFC850 */
     switch (true) {
         case is_string($article):
             //
             @fwrite($this->_socket, $article);
             @fwrite($this->_socket, "\r\n.\r\n");
             //
             if ($this->_logger && $this->_logger->_isMasked(PEAR_LOG_DEBUG)) {
                 foreach (explode("\r\n", $article) as $line) {
                     $this->_logger->debug('D: ' . $line);
                 }
                 $this->_logger->debug('D: .');
             }
             break;
         case is_array($article):
             //
             $header = reset($article);
             $body = next($article);
             /* Experimental...
                 	    // If header is an array, implode it.
                 	    if (is_array($header)) {
                 	        $header = implode("\r\n", $header) . "\r\n";
                 	    }
             */
             // Send header (including separation line)
             @fwrite($this->_socket, $header);
             @fwrite($this->_socket, "\r\n");
             //
             if ($this->_logger && $this->_logger->_isMasked(PEAR_LOG_DEBUG)) {
                 foreach (explode("\r\n", $header) as $line) {
                     $this->_logger->debug('D: ' . $line);
                 }
             }
             /* Experimental...
                 	    // If body is an array, implode it.
                 	    if (is_array($body)) {
                 	        $header = implode("\r\n", $body) . "\r\n";
                 	    }
             */
             // Send body
             @fwrite($this->_socket, $body);
             @fwrite($this->_socket, "\r\n.\r\n");
             //
             if ($this->_logger && $this->_logger->_isMasked(PEAR_LOG_DEBUG)) {
                 foreach (explode("\r\n", $body) as $line) {
                     $this->_logger->debug('D: ' . $line);
                 }
                 $this->_logger->debug('D: .');
             }
             break;
         default:
             return $this->throwError('Ups...', null, null);
     }
     return true;
 }
Exemplo n.º 18
0
Arquivo: Log.php Projeto: horde/horde
 /**
  * Event is being added to the Horde message stack.
  *
  * @param Horde_Notification_Event $event  Event object.
  * @param array $options                   Additional options (see
  *                                         Horde_Notification_Handler for
  *                                         details).
  */
 public function push(Horde_Notification_Event $event, $options)
 {
     $this->_logger->debug($event->message);
 }
Exemplo n.º 19
0
 /**
  * 指定されたレコードを削除します。 
  * 
  * <pre>
  * constraintまたは $idパラメータで指定されたPKに該当するレコードを削除します。
  * $id がハッシュでないときは、id列の値とみなしてDELETEします。
  * $id がハッシュのときは、key値をPKのカラム名とみなしてDELETEします。
  * </pre>
  * 
  * @param mixed $id PKの値
  * @return bool 実行結果
  */
 public function delete($id = null)
 {
     $this->_bindvalue = array();
     // rowにセットされているPKがあればconstraintに
     foreach ($this->_pk as $pk) {
         if (isset($this->{$pk}) && $this->getConstraint($pk) == "") {
             $this->setConstraint($pk, $this->{$pk});
         }
     }
     if ($id != null) {
         if (!is_array($id)) {
             if (count($this->_pk) != 1) {
                 throw new TeepleActiveRecordException("pk is not single.");
             }
             $this->setConstraint($this->_pk[0], $id);
         } else {
             foreach ($id as $col => $val) {
                 $this->setConstraint($col, $val);
             }
         }
     }
     $sql = "DELETE FROM `" . $this->_tablename . "` " . $this->_buildConstraintClause(false);
     $this->_log->info("delete " . $this->_tablename . ": {$sql}");
     $this->_log->debug("param is: \n" . @var_export($this->_bindvalue, TRUE));
     $sth = $this->_pdo->prepare($sql);
     if (!$sth) {
         $err = $this->_pdo->errorInfo();
         throw new TeepleActiveRecordException("pdo prepare failed: {$err[2]}:{$sql}");
     }
     if (!$sth->execute($this->_bindvalue)) {
         $err = $sth->errorInfo();
         throw new TeepleActiveRecordException("pdo execute failed: {$err[2]}:{$sql}");
     }
     $this->_log->info("delete " . $this->_tablename . ": result=(" . $sth->rowCount() . ")");
     $props = array_keys(get_class_vars(get_class($this)));
     foreach ($props as $key) {
         $this->{$key} = NULL;
     }
     $this->resetInstance();
     return $sth->rowCount() > 0;
 }
Exemplo n.º 20
0
 /**
  * PSR-3 Logs with an arbitrary level.
  *
  * @param mixed  $level   logging level
  * @param string $message message
  * @param array  $context array of additional context
  *
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     if (!$this->activated) {
         return;
     }
     $channel = 'messages';
     $msg = $message;
     /**
      * If we have embedded channel in the context array, format the message
      * approriatly using context values.
      */
     if (isset($context['channel'])) {
         $chan = strtolower($context['channel']);
         switch ($chan) {
             case 'blocks':
                 if (!$this->configs['include_blocks']) {
                     return;
                 }
                 //$channel = 'Blocks';
                 $msg = _MD_MONOLOG_BLOCKS . ' : ' . $message . ': ';
                 if ($context['cached']) {
                     $msg .= sprintf(_MD_MONOLOG_CACHED, (int) $context['cachetime']);
                 } else {
                     $msg .= _MD_MONOLOG_NOT_CACHED;
                 }
                 break;
             case 'deprecated':
                 if (!$this->configs['include_deprecated']) {
                     return;
                 }
                 //$channel = 'Deprecated';
                 $msg = $this->messageTag('_MD_MONOLOG_DEPRECATED', 'Deprecated*') . ' : ' . $message;
                 //$msg = _MD_MONOLOG_DEPRECATED . ' : ' . $message;
                 break;
             case 'extra':
                 if (!$this->configs['include_extra']) {
                     return;
                 }
                 //$channel = 'Extra';
                 $msg = _MD_MONOLOG_EXTRA . ' : ' . $context['name'] . ': ' . $message;
                 break;
             case 'queries':
                 if (!$this->configs['include_queries']) {
                     return;
                 }
                 //$channel = 'Queries';
                 $msg = $message;
                 $qt = empty($context['query_time']) ? '' : sprintf('%0.6f - ', $context['query_time']);
                 if ($level == LogLevel::ERROR) {
                     //if (!is_scalar($context['errno']) ||  !is_scalar($context['errno'])) {
                     //    \Xmf\Debug::dump($context);
                     //}
                     $msg .= ' -- Error number: ' . (is_scalar($context['errno']) ? $context['errno'] : '?') . ' Error message: ' . (is_scalar($context['error']) ? $context['error'] : '?');
                 }
                 $msg = $this->messageTag('_MD_MONOLOG_QUERIES', 'Queries*') . ' : ' . $qt . $msg;
                 break;
             case 'timers':
                 if (!$this->configs['include_timers']) {
                     return;
                 }
                 $msg = $this->messageTag('_MD_MONOLOG_TIMERS', 'Timers*') . ' : ' . $message;
                 break;
             default:
                 $msg = $this->messageTag('_MD_MONOLOG_ERRORS', 'Errors*') . ' : ' . $message;
                 break;
         }
     } else {
         $msg = $this->messageTag('_MD_MONOLOG_MESSAGES', 'Message*') . ' : ' . $message;
     }
     switch ($level) {
         case LogLevel::EMERGENCY:
             $this->monolog->emergency($msg, $context);
             break;
         case LogLevel::ALERT:
             $this->monolog->alert($msg, $context);
             break;
         case LogLevel::CRITICAL:
             $this->monolog->critical($msg, $context);
             break;
         case LogLevel::ERROR:
             $this->monolog->error($msg, $context);
             break;
         case LogLevel::WARNING:
             $this->monolog->warning($msg, $context);
             break;
         case LogLevel::NOTICE:
             $this->monolog->notice($msg, $context);
             break;
         case LogLevel::INFO:
             $this->monolog->info($msg, $context);
             break;
         case LogLevel::DEBUG:
         default:
             $this->monolog->debug($msg, $context);
             break;
     }
 }
Exemplo n.º 21
0
 /**
  * Handles all kinds of exceptions
  *
  * @param object $e \Exception
  *
  * @return void
  *
  * @access public
  *
  * @static
  */
 public static function handleException($e)
 {
     if ($e instanceof ErrorException) {
         $e->debug();
     } else {
         try {
             throw new ErrorException(get_class($e) . ': ' . $e->getMessage(), $e->getCode(), 0, $e->getFile(), $e->getLine());
         } catch (ErrorException $e) {
             $e->debug();
         }
     }
 }