作者:JanVorace
项目:Diggriol
/**
* Connection factory. Connects to DB.
*
* @param Nette\DI\IContainer $container
* @return NotORM
*/
public static function dbConnect(IContainer $container)
{
$db = $container->params['database'];
$dsn = (isset($db->port))
? "{$db->driver}:host={$db->host};dbname={$db->database};port={$db->port}"
: "{$db->driver}:host={$db->host};dbname={$db->database}";
$pdo = new PDO($dsn, $db->username, $db->password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->query('SET NAMES utf8');
$conn = new NotORM($pdo, new NotORM_Structure_Convention('id', '%s_id', '%ss'), new NotORM_Cache_Session);
if ($db->profiler) {
$panel = Panel::getInstance();
$panel->setPlatform($db->driver);
Debugger::addPanel($panel);
$conn->debug = function($query, $parameters) {
Panel::getInstance()->logQuery($query, $parameters);
};
}
return $conn;
}
作者:venn
项目:catalog-modul
/**
* @param ItemRepository $productRepository
*/
public function __construct(ItemRepository $productRepository)
{
parent::__construct();
$this->productRepository = $productRepository;
$this->absoluteUrls = true;
Debugger::$bar = false;
}
作者:fuc
项目:sportsclu
/**
* @param Exception
* @return void
*/
public function renderDefault($exception)
{
// this block is there due to nette caching issue 11
// https://github.com/nette/caching/issues/11
if ($exception instanceof Nette\InvalidStateException) {
$temp = $this->context->parameters['tempDir'];
//unlink($temp . '/btfj.dat');
rename($temp . '/btfj.dat', $temp . '/btfj.dat' . microtime(TRUE));
}
if ($exception instanceof Nette\Application\BadRequestException) {
$code = $exception->getCode();
// load template 403.latte or 404.latte or ... 4xx.latte
$this->setView(in_array($code, array(403, 404, 405, 410, 500)) ? $code : '4xx');
// log to access.log
Debugger::log("HTTP code {$code}: {$exception->getMessage()} in {$exception->getFile()}:{$exception->getLine()}", 'access');
} else {
$this->setView('500');
// load template 500.latte
Debugger::log($exception, Debugger::ERROR);
// and log exception
}
if ($this->isAjax()) {
// AJAX request? Note this error in payload.
$this->payload->error = TRUE;
$this->terminate();
}
}
作者:norb
项目:framewor
public function stopQuery()
{
$keys = array_keys($this->queries);
$key = end($keys);
$this->queries[$key][2] = Debugger::timer('doctrine');
$this->totalTime += $this->queries[$key][2];
}
作者:vbos
项目:faceboo
/**
* Parses a signed_request and validates the signature.
*
* @param string $signedRequest A signed token
* @param string $appSecret
*
* @return array The payload inside it or null if the sig is wrong
*/
public static function decode($signedRequest, $appSecret)
{
if (!$signedRequest || strpos($signedRequest, '.') === false) {
Debugger::log('Signed request is invalid! ' . json_encode($signedRequest), 'facebook');
return NULL;
}
list($encoded_sig, $payload) = explode('.', $signedRequest, 2);
// decode the data
$sig = Helpers::base64UrlDecode($encoded_sig);
$data = Json::decode(Helpers::base64UrlDecode($payload), Json::FORCE_ARRAY);
if (!isset($data['algorithm']) || strtoupper($data['algorithm']) !== Configuration::SIGNED_REQUEST_ALGORITHM) {
Debugger::log("Unknown algorithm '{$data['algorithm']}', expected " . Configuration::SIGNED_REQUEST_ALGORITHM, 'facebook');
return NULL;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $appSecret, $raw = TRUE);
if (strlen($expected_sig) !== strlen($sig)) {
Debugger::log('Bad Signed JSON signature! Expected ' . self::dump($expected_sig) . ', but given ' . self::dump($sig), 'facebook');
return NULL;
}
$result = 0;
for ($i = 0; $i < strlen($expected_sig); $i++) {
$result |= ord($expected_sig[$i]) ^ ord($sig[$i]);
}
if ($result !== 0) {
Debugger::log('Bad Signed JSON signature! Expected ' . self::dump($expected_sig) . ', but given ' . self::dump($sig), 'facebook');
return NULL;
}
return $data;
}
作者:janmare
项目:doctrin
public function stopQuery()
{
if ($this->explainRunning) {
return;
}
$keys = array_keys($this->queries);
$key = end($keys);
$this->queries[$key][self::TIME] = Debugger::timer('doctrine');
$this->totalTime += $this->queries[$key][self::TIME];
// get EXPLAIN for SELECT queries
if ($this->doExplains) {
if ($this->connection === NULL) {
throw new \Nette\InvalidStateException('You must set a Doctrine\\DBAL\\Connection to get EXPLAIN.');
}
$query = $this->queries[$key][self::SQL];
if (strtoupper(substr(ltrim($query), 0, 6)) !== 'SELECT') {
// only SELECTs are supported
return;
}
// prevent logging explains & infinite recursion
$this->explainRunning = TRUE;
$params = $this->queries[$key][self::PARAMS];
$types = $this->queries[$key][self::TYPES];
$stmt = $this->connection->executeQuery('EXPLAIN ' . $query, $params, $types);
$this->queries[$key][self::EXPLAIN] = $stmt->fetchAll();
$this->explainRunning = FALSE;
}
}
作者:cuja
项目:atlashorni
public function logQuery(Nette\Database\Connection $connection, $result)
{
if ($this->disabled) {
return;
}
$this->count++;
$source = NULL;
$trace = $result instanceof \PDOException ? $result->getTrace() : debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : FALSE);
foreach ($trace as $row) {
if (isset($row['file']) && is_file($row['file']) && !Nette\Diagnostics\Debugger::getBluescreen()->isCollapsed($row['file'])) {
if (isset($row['function']) && strpos($row['function'], 'call_user_func') === 0 || isset($row['class']) && is_subclass_of($row['class'], '\\Nette\\Database\\Connection')) {
continue;
}
$source = array($row['file'], (int) $row['line']);
break;
}
}
if ($result instanceof Nette\Database\ResultSet) {
$this->totalTime += $result->getTime();
if ($this->count < $this->maxQueries) {
$this->queries[] = array($connection, $result->getQueryString(), $result->getParameters(), $source, $result->getTime(), $result->getRowCount(), NULL);
}
} elseif ($result instanceof \PDOException && $this->count < $this->maxQueries) {
$this->queries[] = array($connection, $result->queryString, NULL, $source, NULL, NULL, $result->getMessage());
}
}
作者:sg3teste
项目:songato
protected function createComponentAddSetting()
{
$form = new Form();
$form->addText('key', 'Klíč')->setRequired('Zadejte klíč nastavení');
$form->addText('value', 'Hodnota')->setRequired('Zadejte hodnotu nastavení');
$form->addSubmit('send', 'Zapsat');
$form->onSuccess[] = function (Form $f) {
try {
$val = $f->values;
$this->settings->set($val->key, $val->value);
$this->settings->push();
//Write
$this->logger->log('System', 'edit', "%user% změnila(a) nastavení");
$msg = $this->flashMessage("Nastavení bylo zapsáno", 'success');
$msg->title = 'Yehet!';
$msg->icon = 'check';
$this->redirect('this');
} catch (\PDOException $e) {
\Nette\Diagnostics\Debugger::log($e);
$msg = $this->flashMessage("Něco se podělalo. Zkuste to prosím později.", 'danger');
$msg->title = 'Oh shit!';
$msg->icon = 'warning';
}
};
return $form;
}
作者:jkucha
项目:FileDownloader-exampl
function log_write($data, FileDownload $file, IDownloader $downloader)
{
$cache = Environment::getCache("FileDownloader/log");
$log = array();
$tid = (string) $file->getTransferId();
if (!isset($cache["registry"])) {
$cache["registry"] = array();
}
$reg = $cache["registry"];
$reg[$tid] = true;
$cache["registry"] = $reg;
if (isset($cache[$tid])) {
$log = $cache[$tid];
}
Debugger::fireLog("Data: " . $data . "; " . $downloader->end);
$data = $data . ": " . Helpers::bytes($file->transferredBytes) . " <->; ";
if ($downloader instanceof AdvancedDownloader and $downloader->isInitialized()) {
$data .= "position: " . Helpers::bytes($downloader->position) . "; ";
//$data .= "length: ".Helpers::bytes($downloader->length)."; ";
$data .= "http-range: " . Helpers::bytes($downloader->start) . "-" . Helpers::bytes($downloader->end) . "; ";
$data .= "progress (con: " . round($file->transferredBytes / $downloader->end * 100) . "% X ";
$data .= "file: " . round($downloader->position / $file->sourceFileSize * 100) . "%)";
}
$log[] = $data;
$cache[$tid] = $log;
}
作者:sg3teste
项目:songato
/**
* @param $id
* @param $status
* @throws \Nette\Application\BadRequestException
*/
public function actionView($id, $status = null)
{
$interpret = $this->interpreti->find($id);
if ($status) {
$this->template->status = $status;
}
if (!$interpret) {
throw new Nette\Application\BadRequestException("Interpret does not exists!", 404);
}
if ($interpret->interpret_id) {
$msg = $this->flashMessage("Přesměrováno z '{$interpret->nazev}'");
$msg->title = "Alias";
$this->redirect("this", array("id" => $interpret->interpret_id));
//If is alias => redirect to real
}
$this->template->interpret = $interpret;
//Register helper fot fetching song form last.fm
$this->template->registerhelper('songImage', function ($song, $img = 0) {
try {
return $this->lastfm->call('Track.getInfo', ['track' => $song->name, 'artist' => $song->interpret_name])->track->album->image[$img]->{'#text'};
} catch (Model\Lastfm\LastfmException $e) {
return null;
}
});
//Last.fm Interpret info (images)
try {
$this->template->lastfm = $this->lastfm->call('Artist.getInfo', ['artist' => $interpret->nazev])->artist;
} catch (Model\Lastfm\LastfmException $e) {
if ($this->settings->get('lastfm_enabled', false)) {
Debugger::log($e);
}
}
}
作者:Johnik01
项目:rezervac
/**
* Nette\Diagnostics\Debugger::dump() shortcut.
* @tracySkipLocation
*/
function dump($var)
{
foreach (func_get_args() as $arg) {
Debugger::dump($arg);
}
return $var;
}
作者:RiKa
项目:ErrorMonitorin
/**
* @param Exception
* @return void
*/
public function renderDefault($exception)
{
if ($exception) {
$data = array('error_msg' => $exception->getMessage(), 'upd_process_id' => 'ErrorPresenter::renderDefault()');
if (isset($this->lastLogItem) && is_object($this->lastLogItem)) {
$this->logger->updateLogVisit($this->lastLogItem->id, $data);
}
}
if ($this->isAjax()) {
// AJAX request? Just note this error in payload.
$this->payload->error = TRUE;
$this->terminate();
} elseif ($exception instanceof NA\BadRequestException || $exception instanceof HQ\UnauthorizedAccessException) {
$code = $exception->getCode();
if ($exception instanceof HQ\UnauthorizedAccessException) {
// Unathorized access in admin
$this->setView("admin403");
} else {
// load template 403.latte or 404.latte or ... 4xx.latte
$this->setView(in_array($code, array(403, 404, 405, 410, 500)) ? $code : '4xx');
}
// log to access.log
Debugger::log("HTTP code {$code}: {$exception->getMessage()} in {$exception->getFile()}:{$exception->getLine()}", 'access');
} else {
$this->setView('500');
// load template 500.latte
$this->logger->logError($exception, 'exception', 'ErrorPresenter::LOG_EXCEPTION');
}
}
作者:nasex
项目:logge
/**
* generateExceptionFile
* @param Exception $exception
* @return string
*/
private function generateExceptionFile($exception)
{
$hash = md5($exception);
$exceptionFilename = "exception-" . @date('Y-m-d-H-i-s') . "-{$hash}.html";
foreach (new \DirectoryIterator($this->loggerDirectory) as $entry) {
if (strpos($entry, $hash)) {
$exceptionFilename = $entry;
$saved = TRUE;
break;
}
}
$exceptionFilename = $this->loggerDirectory . '/' . $exceptionFilename;
if (empty($saved) && ($logHandle = @fopen($exceptionFilename, 'w'))) {
ob_start();
// double buffer prevents sending HTTP headers in some PHP
ob_start(function ($buffer) use($logHandle) {
fwrite($logHandle, $buffer);
}, 4096);
Debugger::getBlueScreen()->render($exception);
ob_end_flush();
ob_end_clean();
fclose($logHandle);
}
return $exceptionFilename;
}
作者:Budr
项目:TinyRES
/**
* @param Method $element
* @throws \Flame\Rest\Security\ForbiddenRequestException
*/
public function authenticate(Method $element)
{
$referer = $this->getReferer();
if (!in_array($referer, $this->allowedReferers)) {
Debugger::log('Invalid HTTP REFERER header "' . $referer . '"', Debugger::DETECT);
throw new ForbiddenRequestException();
}
}
作者:TheTypoMaste
项目:SPHERE-Framewor
public function __toString()
{
try {
return (string) $this->getPrimary();
} catch (\Exception $e) {
Nette\Diagnostics\Debugger::toStringException($e);
}
}
作者:anagi
项目:woocommerc
public function addServer($host = 'localhost', $port = 11211, $timeout = 1)
{
Nette\Diagnostics\Debugger::tryError();
$this->memcache->addServer($host, $port, TRUE, 1, $timeout);
if (Nette\Diagnostics\Debugger::catchError($e)) {
throw new Nette\InvalidStateException('Memcache::addServer(): ' . $e->getMessage(), 0, $e);
}
}
作者:kovku
项目:r-cm
/**
* Converts link to URL.
* @return string
*/
public function __toString()
{
try {
return $this->component->link($this->destination, $this->params);
} catch (\Exception $e) {
Nette\Diagnostics\Debugger::toStringException($e);
}
}
作者:jasi
项目:phpedpane
public static function register()
{
//register panel only once
if (!self::$registered) {
Debugger::addPanel(new self());
self::$registered = TRUE;
}
}
作者:Budr
项目:TinyRES
/**
* @param Method $element
* @throws \Flame\Rest\Security\ForbiddenRequestException
*/
public function authenticate(Method $element)
{
$ip = $this->getClientIp();
if (!in_array($ip, $this->allowedIps)) {
Debugger::log('Banned ip "' . $ip . '"', Debugger::DETECT);
throw new ForbiddenRequestException();
}
}
作者:radeksimk
项目:nett
/**
* Nette\Diagnostics\Debugger::log() shortcut.
*/
function dlog($var = NULL)
{
if (func_num_args() === 0) {
Debugger::log(new Exception(), 'dlog');
}
foreach (func_get_args() as $arg) {
Debugger::log($arg, 'dlog');
}
return $var;
}