本文整理汇总了PHP中Nette\Debug::catchError方法的典型用法代码示例。如果您正苦于以下问题:PHP Debug::catchError方法的具体用法?PHP Debug::catchError怎么用?PHP Debug::catchError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Debug
的用法示例。
在下文中一共展示了Debug::catchError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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);
}
}
示例2: 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.');
}
}
示例3: __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());
}
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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];
}
}
示例7: 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'));
}