本文整理汇总了PHP中Nette\Debug类的典型用法代码示例。如果您正苦于以下问题:PHP Debug类的具体用法?PHP Debug怎么用?PHP Debug使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Debug类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __toString
/**
* Converts link to URL.
* @return string
*/
public function __toString()
{
try {
return $this->component->link($this->destination, $this->params);
} catch (\Exception $e) {
Nette\Debug::toStringException($e);
}
}
开发者ID:JanTvrdik,项目名称:nette,代码行数:12,代码来源:Link.php
示例2: __construct
public function __construct($host = 'localhost', $port = 11211, $prefix = '', Nette\Context $context = NULL)
{
if (!self::isAvailable()) {
throw new \NotSupportedException("PHP extension 'memcache' is not loaded.");
}
$this->prefix = $prefix;
$this->context = $context;
$this->memcache = new \Memcache();
Nette\Debug::tryError();
$this->memcache->connect($host, $port);
if (Nette\Debug::catchError($msg)) {
throw new \InvalidStateException($msg);
}
}
开发者ID:JPalounek,项目名称:IconStore,代码行数:14,代码来源:MemcachedStorage.php
示例3: send
/**
* Sends e-mail.
* @param Mail
* @return void
*/
public function send(Mail $mail)
{
$tmp = clone $mail;
$tmp->setHeader('Subject', NULL);
$tmp->setHeader('To', NULL);
$parts = explode(Mail::EOL . Mail::EOL, $tmp->generateMessage(), 2);
Nette\Debug::tryError();
$res = mail(str_replace(Mail::EOL, PHP_EOL, $mail->getEncodedHeader('To')), str_replace(Mail::EOL, PHP_EOL, $mail->getEncodedHeader('Subject')), str_replace(Mail::EOL, PHP_EOL, $parts[1]), str_replace(Mail::EOL, PHP_EOL, $parts[0]));
if (Nette\Debug::catchError($msg)) {
throw new \InvalidStateException($msg);
} elseif (!$res) {
throw new \InvalidStateException('Unable to send email.');
}
}
开发者ID:JPalounek,项目名称:IconStore,代码行数:19,代码来源:SendmailMailer.php
示例4: __construct
public function __construct($host = 'localhost', $port = 11211, $prefix = '', ICacheJournal $journal = NULL)
{
if (!self::isAvailable()) {
throw new \NotSupportedException("PHP extension 'memcache' is not loaded.");
}
$this->prefix = $prefix;
$this->journal = $journal;
$this->memcache = new \Memcache();
Nette\Debug::tryError();
$this->memcache->connect($host, $port);
if (Nette\Debug::catchError($e)) {
throw new \InvalidStateException($e->getMessage());
}
}
开发者ID:JanTvrdik,项目名称:nette,代码行数:14,代码来源:MemcachedStorage.php
示例5: renderDefault
/**
* @param Exception
* @return void
*/
public function renderDefault($exception)
{
if ($this->isAjax()) { // AJAX request? Just note this error in payload.
$this->payload->error = TRUE;
$this->terminate();
} elseif ($exception instanceof BadRequestException) {
$code = $exception->getCode();
$this->setView(in_array($code, array(403, 404, 405, 410, 500)) ? $code : '4xx'); // load template 403.latte or 404.latte or ... 4xx.latte
} else {
$this->setView('500'); // load template 500.latte
Debug::log($exception, Debug::ERROR); // and log exception
}
}
开发者ID:newPOPE,项目名称:screencast,代码行数:19,代码来源:ErrorPresenter.php
示例6: __toString
/**
* Renders template to string.
* @param bool can throw exceptions? (hidden parameter)
* @return string
*/
public function __toString()
{
ob_start();
try {
$this->render();
return ob_get_clean();
} catch (\Exception $e) {
ob_end_clean();
if (func_num_args() && func_get_arg(0)) {
throw $e;
} else {
Nette\Debug::toStringException($e);
}
}
}
开发者ID:nella,项目名称:ActiveMapper,代码行数:20,代码来源:BaseTemplate.php
示例7: encode
/**
* Returns the JSON representation of a value.
* @param mixed
* @return string
*/
public static function encode($value)
{
Debug::tryError();
if (function_exists('ini_set')) {
$old = ini_set('display_errors', 0); // needed to receive 'Invalid UTF-8 sequence' error
$json = json_encode($value);
ini_set('display_errors', $old);
} else {
$json = json_encode($value);
}
if (Debug::catchError($e)) { // needed to receive 'recursion detected' error
throw new JsonException($e->getMessage());
}
return $json;
}
开发者ID:newPOPE,项目名称:screencast,代码行数:20,代码来源:Json.php
示例8: renderDefault
/**
* @param Exception
* @return void
*/
public function renderDefault($exception)
{
if ($this->isAjax()) {
// AJAX request? Just note this error in payload.
$this->payload->error = TRUE;
$this->terminate();
} elseif ($exception instanceof BadRequestException) {
$this->setView('404');
// load template 404.phtml
} else {
$this->setView('500');
// load template 500.phtml
Debug::processException($exception);
// and handle error by Nette\Debug
}
}
开发者ID:jakubkulhan,项目名称:nette,代码行数:20,代码来源:ErrorPresenter.php
示例9: __construct
public function __construct($dsn, $username = NULL, $password = NULL, array $options = NULL)
{
parent::__construct($dsn, $username, $password, $options);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Nette\\Database\\Statement', array($this)));
$class = 'Nette\\Database\\Drivers\\Pdo' . $this->getAttribute(PDO::ATTR_DRIVER_NAME) . 'Driver';
if (class_exists($class)) {
$this->driver = new $class($this, (array) $options);
}
$this->preprocessor = new SqlPreprocessor($this);
$this->databaseReflection = new Nette\Database\Reflection\DatabaseReflection();
// TODO
if (!Nette\Debug::$productionMode) {
Nette\Debug::addPanel($panel = new DatabasePanel($dsn));
$this->onQuery[] = callback($panel, 'logQuery');
}
}
开发者ID:JanTvrdik,项目名称:nette,代码行数:17,代码来源:Connection.php
示例10: processRequest
/**
* Processes request.
*
* @author Jan Tvrdík
* @param PresenterRequest
* @return void
* @throws Nette\Applicationy\AbortException|\InvalidStateException
*/
public function processRequest(PresenterRequest $request)
{
$params = $request->getParams();
$exception = & $params['exception'];
if (!isset($exception)) {
throw new \InvalidStateException('Missing required parameter - exception.');
}
if ($exception instanceof BadRequestException) {
$code = $exception->getCode();
$name = in_array($code, array(403, 404, 405, 410, 500)) ? $code : '4xx';
} else {
Debug::log($exception, Debug::ERROR);
$name = '500';
}
$this->page = '@errors/' . $name;
$this->sendTemplate();
}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:28,代码来源:ErrorPresenter.php
示例11: catchPregError
/** @internal */
public static function catchPregError($pattern)
{
if (Debug::catchError($e)) { // compile error
throw new RegexpException($e->getMessage() . " in pattern: $pattern");
} elseif (preg_last_error()) { // run-time error
static $messages = array(
PREG_INTERNAL_ERROR => 'Internal error',
PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted',
PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted',
PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data',
5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR
);
$code = preg_last_error();
throw new RegexpException((isset($messages[$code]) ? $messages[$code] : 'Unknown error') . " (pattern: $pattern)", $code);
}
}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:18,代码来源:String.php
示例12:
<?php
namespace ActiveMapperTests;
require_once __DIR__ . "/../libs/Nette/loader.php";
\Nette\Debug::enable(\Nette\Debug::DEVELOPMENT);
\Nette\Environment::setVariable("tempDir", __DIR__ . "/_temp");
$loader = new \Nette\Loaders\RobotLoader();
$loader->addDirectory(__DIR__ . "/../libs");
$loader->addDirectory(__DIR__ . "/../ActiveMapper");
$loader->addDirectory(__DIR__ . "/../examples/Models");
$loader->register();
\dibi::connect(array('driver' => "sqlite3", 'database' => ":memory:", 'formatDateTime' => "'Y-m-d H:i:s'", 'lazy' => TRUE, 'profiler' => TRUE));
\dibi::loadFile(__DIR__ . "/db.structure.sql");
\dibi::loadFile(__DIR__ . "/db.data.sql");
开发者ID:nella,项目名称:ActiveMapper,代码行数:15,代码来源:bootstrap.php
示例13: grep
/**
* Return array entries that match the pattern.
* @param array
* @param string
* @param int
* @return array
*/
public static function grep(array $arr, $pattern, $flags = 0)
{
Debug::tryError();
$res = preg_grep($pattern, $arr, $flags);
String::catchPregError($pattern);
return $res;
}
开发者ID:JanTvrdik,项目名称:nette,代码行数:14,代码来源:ArrayTools.php
示例14: load
/**
* Reads configuration from INI file.
* @param string file name
* @param string section to load
* @return array
* @throws \InvalidStateException
*/
public static function load($file, $section = NULL)
{
if (!is_file($file) || !is_readable($file)) {
throw new \FileNotFoundException("File '{$file}' is missing or is not readable.");
}
Nette\Debug::tryError();
$ini = parse_ini_file($file, TRUE);
if (Nette\Debug::catchError($e)) {
throw $e;
}
$separator = trim(self::$sectionSeparator);
$data = array();
foreach ($ini as $secName => $secData) {
// is section?
if (is_array($secData)) {
if (substr($secName, -1) === self::$rawSection) {
$secName = substr($secName, 0, -1);
} elseif (self::$keySeparator) {
// process key separators (key1> key2> key3)
$tmp = array();
foreach ($secData as $key => $val) {
$cursor =& $tmp;
foreach (explode(self::$keySeparator, $key) as $part) {
if (!isset($cursor[$part]) || is_array($cursor[$part])) {
$cursor =& $cursor[$part];
} else {
throw new \InvalidStateException("Invalid key '{$key}' in section [{$secName}] in '{$file}'.");
}
}
$cursor = $val;
}
$secData = $tmp;
}
// process extends sections like [staging < production] (with special support for separator ':')
$parts = $separator ? explode($separator, strtr($secName, ':', $separator)) : array($secName);
if (count($parts) > 1) {
$parent = trim($parts[1]);
$cursor =& $data;
foreach (self::$keySeparator ? explode(self::$keySeparator, $parent) : array($parent) as $part) {
if (isset($cursor[$part]) && is_array($cursor[$part])) {
$cursor =& $cursor[$part];
} else {
throw new \InvalidStateException("Missing parent section [{$parent}] in '{$file}'.");
}
}
$secData = Nette\ArrayTools::mergeTree($secData, $cursor);
}
$secName = trim($parts[0]);
if ($secName === '') {
throw new \InvalidStateException("Invalid empty section name in '{$file}'.");
}
}
if (self::$keySeparator) {
$cursor =& $data;
foreach (explode(self::$keySeparator, $secName) as $part) {
if (!isset($cursor[$part]) || is_array($cursor[$part])) {
$cursor =& $cursor[$part];
} else {
throw new \InvalidStateException("Invalid section [{$secName}] in '{$file}'.");
}
}
} else {
$cursor =& $data[$secName];
}
if (is_array($secData) && is_array($cursor)) {
$secData = Nette\ArrayTools::mergeTree($secData, $cursor);
}
$cursor = $secData;
}
if ($section === NULL) {
return $data;
} elseif (!isset($data[$section]) || !is_array($data[$section])) {
throw new \InvalidStateException("There is not section [{$section}] in '{$file}'.");
} else {
return $data[$section];
}
}
开发者ID:Balvan,项目名称:nette,代码行数:84,代码来源:ConfigAdapterIni.php
示例15: date
namespace App;
require_once __DIR__ . "/bootstrap.php";
use Nette\Debug, Nette\Framework, dibi;
Debug::timer('benchmark');
$memory = memory_get_peak_usage();
echoBeginHtml();
/********************************************************************************************************************************/
// Setum entity manager
$em = new \ActiveMapper\Manager(\dibi::getConnection());
echo "<h1>All authors</h1>";
// Get all authors
$authors = $em->findAll('App\\Models\\Author');
foreach ($authors as $author) {
Debug::dump($author->name);
Debug::dump($author->blog->name);
}
echo "<h1>Author by ID #3</h1>";
// Get author by id
$author = $em->find('App\\Models\\Author', 3);
Debug::dump($author->name);
Debug::dump($author->blog->name);
/********************************************************************************************************************************/
// Benchmark data
Debug::barDump(Framework::NAME . " " . Framework::VERSION . " " . Framework::REVISION);
Debug::barDump("dibi " . dibi::VERSION . " " . dibi::REVISION);
Debug::barDump($mappingTime = number_format(Debug::timer('benchmark') * 1000, 1, '.', ' ') . "ms", "Mapping Time");
Debug::barDump($mappingMemory = number_format((memory_get_peak_usage() - $memory) / 1000, 1, '.', ' ') . "kB", "Mapping Memory");
echo '<p><a href="http://github.com/Vrtak-CZ/ActiveMapper/blob/master/examples/index.php" target="_blank">' . 'Show code on GitHub</a> - <a href="http://am.vrtak-cz.net/coverage">Show coverage</a></p>';
$benchMarkData = "mapping time: {$mappingTime} mapping memory: {$mappingMemory} " . "total time: " . number_format((microtime(TRUE) - Debug::$time) * 1000, 1, '.', ' ') . "ms " . "total memory: " . number_format(memory_get_peak_usage() / 1000, 1, '.', ' ') . "kB";
file_put_contents(__DIR__ . "/benchmark.log", date("r") . " # " . $benchMarkData . PHP_EOL, FILE_APPEND);
开发者ID:nella,项目名称:ActiveMapper,代码行数:31,代码来源:index.php
示例16: run
/**
* Dispatch a HTTP request to a front controller.
* @return void
*/
public function run()
{
$httpRequest = $this->getHttpRequest();
$httpResponse = $this->getHttpResponse();
$httpRequest->setEncoding('UTF-8');
if (Environment::getVariable('baseUri') === NULL) {
Environment::setVariable('baseUri', $httpRequest->getUri()->getBasePath());
}
// autostarts session
$session = $this->getSession();
if (!$session->isStarted() && $session->exists()) {
$session->start();
}
// enable routing debuggger
Nette\Debug::addPanel(new RoutingDebugger($this->getRouter(), $httpRequest));
// check HTTP method
if ($this->allowedMethods) {
$method = $httpRequest->getMethod();
if (!in_array($method, $this->allowedMethods, TRUE)) {
$httpResponse->setCode(Nette\Web\IHttpResponse::S501_NOT_IMPLEMENTED);
$httpResponse->setHeader('Allow', implode(',', $this->allowedMethods));
echo '<h1>Method ' . htmlSpecialChars($method) . ' is not implemented</h1>';
return;
}
}
// dispatching
$request = NULL;
$repeatedError = FALSE;
do {
try {
if (count($this->requests) > self::$maxLoop) {
throw new ApplicationException('Too many loops detected in application life cycle.');
}
if (!$request) {
$this->onStartup($this);
// default router
$router = $this->getRouter();
if ($router instanceof MultiRouter && !count($router)) {
$router[] = new SimpleRouter(array('presenter' => 'Default', 'action' => 'default'));
}
// routing
$request = $router->match($httpRequest);
if (!$request instanceof PresenterRequest) {
$request = NULL;
throw new BadRequestException('No route for HTTP request.');
}
if (strcasecmp($request->getPresenterName(), $this->errorPresenter) === 0) {
throw new BadRequestException('Invalid request.');
}
}
$this->requests[] = $request;
$this->onRequest($this, $request);
// Instantiate presenter
$presenter = $request->getPresenterName();
try {
$class = $this->getPresenterLoader()->getPresenterClass($presenter);
$request->setPresenterName($presenter);
} catch (InvalidPresenterException $e) {
throw new BadRequestException($e->getMessage(), 404, $e);
}
$request->freeze();
// Execute presenter
$this->presenter = new $class();
$response = $this->presenter->run($request);
// Send response
if ($response instanceof ForwardingResponse) {
$request = $response->getRequest();
continue;
} elseif ($response instanceof IPresenterResponse) {
$response->send();
}
break;
} catch (\Exception $e) {
// fault barrier
if ($this->catchExceptions === NULL) {
$this->catchExceptions = Environment::isProduction();
}
$this->onError($this, $e);
if (!$this->catchExceptions) {
$this->onShutdown($this, $e);
throw $e;
}
if ($repeatedError) {
$e = new ApplicationException('An error occured while executing error-presenter', 0, $e);
}
if (!$httpResponse->isSent()) {
$httpResponse->setCode($e instanceof BadRequestException ? $e->getCode() : 500);
}
if (!$repeatedError && $this->errorPresenter) {
$repeatedError = TRUE;
$request = new PresenterRequest($this->errorPresenter, PresenterRequest::FORWARD, array('exception' => $e));
// continue
} else {
// default error handler
echo "<!DOCTYPE html><meta name=robots content=noindex>\n\n";
echo "<style>body{color:black;background:white;width:500px;margin:100px auto}h1{font:bold 47px/1.5 sans-serif;margin:.6em 0}p{font:21px/1.5 Georgia,serif;margin:1.5em 0}small{font-size:70%;color:gray}</style>\n\n";
//.........这里部分代码省略.........
开发者ID:jakubkulhan,项目名称:nette,代码行数:101,代码来源:Application.php
示例17: start
/**
* Starts and initializes session data.
* @throws \InvalidStateException
* @return void
*/
public function start()
{
if (self::$started) {
return;
} elseif (self::$started === NULL && defined('SID')) {
throw new \InvalidStateException('A session had already been started by session.auto-start or session_start().');
}
$this->configure($this->options);
Nette\Debug::tryError();
session_start();
if (Nette\Debug::catchError($e)) {
@session_write_close();
// this is needed
throw new \InvalidStateException($e->getMessage());
}
self::$started = TRUE;
if ($this->regenerationNeeded) {
session_regenerate_id(TRUE);
$this->regenerationNeeded = FALSE;
}
/* structure:
__NF: Counter, BrowserKey, Data, Meta
DATA: namespace->variable = data
META: namespace->variable = Timestamp, Browser, Version
*/
unset($_SESSION['__NT'], $_SESSION['__NS'], $_SESSION['__NM']);
// old unused structures
// initialize structures
$nf =& $_SESSION['__NF'];
if (empty($nf)) {
// new session
$nf = array('C' => 0);
} else {
$nf['C']++;
}
// browser closing detection
$browserKey = $this->getHttpRequest()->getCookie('nette-browser');
if (!$browserKey) {
$browserKey = (string) lcg_value();
}
$browserClosed = !isset($nf['B']) || $nf['B'] !== $browserKey;
$nf['B'] = $browserKey;
// resend cookie
$this->sendCookie();
// process meta metadata
if (isset($nf['META'])) {
$now = time();
// expire namespace variables
foreach ($nf['META'] as $namespace => $metadata) {
if (is_array($metadata)) {
foreach ($metadata as $variable => $value) {
if (!empty($value['B']) && $browserClosed || !empty($value['T']) && $now > $value['T'] || $variable !== '' && is_object($nf['DATA'][$namespace][$variable]) && (isset($value['V']) ? $value['V'] : NULL) !== Nette\Reflection\ClassReflection::from($nf['DATA'][$namespace][$variable])->getAnnotation('serializationVersion')) {
if ($variable === '') {
// expire whole namespace
unset($nf['META'][$namespace], $nf['DATA'][$namespace]);
continue 2;
}
unset($nf['META'][$namespace][$variable], $nf['DATA'][$namespace][$variable]);
}
}
}
}
}
register_shutdown_function(array($this, 'clean'));
}
开发者ID:Balvan,项目名称:nette,代码行数:70,代码来源:Session.php
示例18: __toString
/**
* Outputs image to string.
* @return string
*/
public function __toString()
{
try {
return $this->toString();
} catch (\Exception $e) {
Debug::toStringException($e);
}
}
开发者ID:nella,项目名称:ActiveMapper,代码行数:12,代码来源:Image.php
示例19: getAndRegister
/**
* Register Doctrine 2 Panel
*/
public static function getAndRegister()
{
$panel = new static();
\Nette\Debug::addPanel($panel);
return $panel;
}
开发者ID:janmarek,项目名称:Neuron,代码行数:9,代码来源:Doctrine2Panel.php
示例20: array
$form->addGroup('Your account');
$form->addPassword('password', 'Choose password')->addRule(Form::FILLED, 'Choose your password')->addRule(Form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3)->setOption('description', '(at least 3 characters)');
$form->addPassword('password2', 'Reenter password')->addConditionOn($form['password'], Form::VALID)->addRule(Form::FILLED, 'Reenter your password')->addRule(Form::EQUAL, 'Passwords do not match', $form['password']);
$form->addFile('avatar', 'Picture');
$form->addHidden('userid');
$form->addTextArea('note', 'Comment');
// group for buttons
$form->addGroup();
$form->addSubmit('submit', 'Send');
// Step 2: Check if form was submitted?
if ($form->isSubmitted()) {
// Step 2c: Check if form is valid
if ($form->isValid()) {
echo '<h2>Form was submitted and successfully validated</h2>';
$values = $form->getValues();
Debug::dump($values);
// this is the end, my friend :-)
if (empty($disableExit)) {
exit;
}
}
} else {
// not submitted, define default values
$defaults = array('name' => 'John Doe', 'userid' => 231, 'country' => 'CZ');
$form->setDefaults($defaults);
}
// Step 3: Render form
?>
<!DOCTYPE html>
<html lang="en">
<head>
开发者ID:jakubkulhan,项目名称:nette,代码行数:31,代码来源:custom-rendering.php
注:本文中的Nette\Debug类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论