dvadf
File manager - Edit - /home/theblueo/tv/wp-includes/pomo/lib/error.tar
Back
XmlParseException.php 0000666 00000000271 15214167344 0010702 0 ustar 00 <?php /** * */ class Loco_error_XmlParseException extends Loco_error_Exception { public function getTitle(){ return __('XML parse error','loco-translate'); } } Exception.php 0000666 00000011457 15214167344 0007236 0 ustar 00 <?php /** * Generic exception that we know has come from the Loco plugin */ class Loco_error_Exception extends Exception implements JsonSerializable { const LEVEL_ERROR = 0; const LEVEL_WARNING = 1; const LEVEL_DEBUG = 2; const LEVEL_NOLOG = 3; /** * Links to help docs etc.. to show along side error message * @var array */ private $links = array(); /** * Override file in which exception was thrown * @var string */ private $_file; /** * Override line number from where exception was thrown * @var int */ private $_line; /** * {@inheritdoc} */ public function __construct( $message = '', $code = 0, $previous = null ) { parent::__construct( $message, $code, $previous ); } /** * @return Throwable */ private function getRootException(){ $current = $this; // note that getPrevious is absent in PHP < 5.3 while( method_exists($current,'getPrevious') && ( $next = $current->getPrevious() ) ){ $current = $next; } return $current; } /** * @return string */ public function getRealFile(){ if( $this->_file ){ return $this->_file; } return $this->getRootException()->getFile(); } /** * @return int */ public function getRealLine(){ if( $this->_line ){ return $this->getLine(); } return $this->getRootException()->getLine(); } /** * @return array */ public function getRealTrace(){ return $this->getRootException()->getTrace(); } /** * @param int number of levels up from callee * @return Loco_error_Exception */ public function setCallee( $depth = 0 ){ $stack = debug_backtrace(0); $callee = $stack[$depth]; $this->_file = $callee['file']; $this->_line = $callee['line']; // TODO could also log the stack trace from $depth upwards, but not required unless being logged or thrown return $this; } /** * Write this error to file regardless of log level * @param Loco_error_Exception * @return void */ public function log(){ $file = new Loco_fs_File( $this->getRealFile() ); $path = $file->getRelativePath( loco_plugin_root() ); $text = sprintf('[Loco.%s] "%s" in %s:%u', $this->getType(), $this->getMessage(), $path, $this->getRealLine() ); // separate error log in CWD for tests if( 'cli' === PHP_SAPI && defined('LOCO_TEST') && LOCO_TEST ){ error_log( '['.date('c').'] '.$text."\n", 3, 'debug.log' ); } // Else write to default PHP log, but note that WordPress may have set this to wp-content/debug.log. // If no `error_log` is set this will send message to the SAPI, so check your httpd/fast-cgi errors too. else { error_log( $text, 0 ); } } /** * Get view template for rendering error to HTML. * @return string path relative to root tpl directory */ public function getTemplate(){ return 'admin/errors/generic'; } /** * Get notice level short code as a string * @return string */ public function getType(){ return 'error'; } /** * Get verbosity level * @return int */ public function getLevel(){ return self::LEVEL_ERROR; } /** * Get localized notice level name * @return string */ public function getTitle(){ return __('Error','loco-translate'); } /** * @return array */ public function jsonSerialize(){ return array ( 'code' => $this->getCode(), 'type' => $this->getType(), 'class' => get_class($this), 'title' => $this->getTitle(), 'message' => $this->getMessage(), //'file' => str_replace( ABSPATH, '', $this->getRealFile() ), //'line' => $this->getRealLine() ); } /** * Push navigation links into error. Use for help pages etc.. * @param string * @param string * @return Loco_error_Exception */ public function addLink( $href, $text ){ $this->links[] = sprintf('<a href="%s">%s</a>', esc_url($href), esc_html($text) ); return $this; } /** * @return array */ public function getLinks(){ return $this->links; } /** * Convert generic exception to one of ours * @param Exception original error * @return Loco_error_Exception */ public static function convert( Exception $e ){ if( $e instanceof Loco_error_Exception ){ return $e; } return new Loco_error_Exception( $e->getMessage(), $e->getCode(), $e ); } } AdminNotices.php 0000666 00000013067 15214167344 0007654 0 ustar 00 <?php class Loco_error_AdminNotices extends Loco_hooks_Hookable { /** * @var Loco_error_AdminNotices */ private static $singleton; /** * @var array */ private $errors = array(); /** * Inline messages are handled by our own template views * @var bool */ private $inline = false; /** * @return Loco_error_AdminNotices */ public static function get(){ self::$singleton or self::$singleton = new Loco_error_AdminNotices; return self::$singleton; } /** * @param Loco_error_Exception * @return Loco_error_Exception */ public static function add( Loco_error_Exception $error ){ $notices = self::get(); $notices->errors[] = $error; // do late flush if we missed the boat if( did_action('loco_admin_init') ){ $notices->on_loco_admin_init(); } if( did_action('admin_notices') ){ $notices->on_admin_notices(); } // if exception wasn't thrown we have to do some work to establish where it was invoked if( __FILE__ === $error->getFile() ){ $error->setCallee(1); } // Log messages of minimum priority and up, depending on debug mode // note that non-debug level is in line with error_reporting set by WordPress (notices ignored) $priority = loco_debugging() ? Loco_error_Exception::LEVEL_DEBUG : Loco_error_Exception::LEVEL_WARNING; if( $error->getLevel() <= $priority ){ $error->log(); } return $error; } /** * Raise a success message * @param string * @return Loco_error_Exception */ public static function success( $message ){ $notice = new Loco_error_Success($message); return self::add( $notice->setCallee(1) ); } /** * Raise a failure message * @param string * @return Loco_error_Exception */ public static function err( $message ){ $notice = new Loco_error_Exception($message); return self::add( $notice->setCallee(1) ); } /** * Raise a warning message * @param string * @return Loco_error_Exception */ public static function warn( $message ){ $notice = new Loco_error_Warning($message); return self::add( $notice->setCallee(1) ); } /** * Raise a generic info message * @param string * @return Loco_error_Exception */ public static function info( $message ){ $notice = new Loco_error_Notice($message); return self::add( $notice->setCallee(1) ); } /** * Raise a debug notice, if debug is enabled * @param string * @return Loco_error_Debug */ public static function debug( $message ){ $notice = new Loco_error_Debug($message); $notice->setCallee(1); loco_debugging() and self::add( $notice ); return $notice; } /** * Destroy and return buffer * @return array */ public static function destroy(){ if( $notices = self::$singleton ){ $buffer = $notices->errors; $notices->errors = array(); self::$singleton = null; return $buffer; } return array(); } /** * Destroy and return all serialized notices, suitable for ajax response * @return array */ public static function destroyAjax(){ $data = array(); /* @var $notice Loco_error_Exception */ foreach( self::destroy() as $notice ){ $data[] = $notice->jsonSerialize(); } return $data; } /** * @return void */ private function flush(){ if( $this->errors ){ $htmls = array(); /* $var $error Loco_error_Exception */ foreach( $this->errors as $error ){ $html = sprintf ( '<p><strong class="has-icon">%s:</strong> <span>%s</span></p>', esc_html( $error->getTitle() ), esc_html( $error->getMessage() ) ); $styles = array( 'notice', 'notice-'.$error->getType() ); if( $this->inline ){ $styles[] = 'inline'; } if( $links = $error->getLinks() ){ $styles[] = 'has-nav'; $html .= '<nav>'.implode( '<span> | </span>', $links ).'</nav>'; } $htmls[] = '<div class="'.implode(' ',$styles).'">'.$html.'</div>'; } $this->errors = array(); echo implode("\n", $htmls),"\n"; } } /** * admin_notices action handler. */ public function on_admin_notices(){ if( ! $this->inline ){ $this->flush(); } } /** * loco_admin_notices callback. * Unlike WordPress "admin_notices" this fires from within template layout at the point we want them, hence they are marked as "inline" */ public function on_loco_admin_notices(){ $this->inline = true; $this->flush(); } /** * loco_admin_init callback * When we know a Loco admin controller will render the page we will control the point at which notices are printed */ public function on_loco_admin_init(){ $this->inline = true; } /** * @internal * Make sure we always see notices if hooks didn't fire */ public function __destruct(){ $this->inline = false; if( ! loco_doing_ajax() ){ $this->flush(); } } } Success.php 0000666 00000001007 15214167344 0006676 0 ustar 00 <?php /** * Success message. Not really an exception obviously, but compatible with Loco_error_AdminNotices */ class Loco_error_Success extends Loco_error_Exception { /** * {@inheritdoc} */ public function getType(){ return 'success'; } /** * {@inheritdoc} */ public function getTitle(){ return __('OK','loco-translate'); } /** * {@inheritdoc} */ public function getLevel(){ return Loco_error_Exception::LEVEL_NOLOG; } } UploadException.php 0000666 00000000166 15214167344 0010376 0 ustar 00 <?php /** * Exception type for failed uploads */ class Loco_error_UploadException extends Loco_error_Exception { } Notice.php 0000666 00000001065 15214167344 0006513 0 ustar 00 <?php /** * Generic, non-critical informational notice * Not to be confused with an error notice. This is for onscreen messages, and won't be logged. */ class Loco_error_Notice extends Loco_error_Exception { /** * {@inheritdoc} */ public function getType(){ return 'info'; } /** * {@inheritdoc} */ public function getTitle(){ return __('Notice','loco-translate'); } /** * {@inheritdoc} */ public function getLevel(){ return Loco_error_Exception::LEVEL_NOLOG; } } ParseException.php 0000666 00000002646 15214167344 0010231 0 ustar 00 <?php /** * */ class Loco_error_ParseException extends Loco_error_Exception { /** * @var string */ private $context; /** * @param int line number * @param int column number * @param string source in which to identify line and column * @return self */ public function setContext( $line, $column, $source ){ $this->context = null; // If line given as 0 then treat column as offset in an unknown number of lines if( 0 === $line ){ $lines = preg_split( '/\\r?\\n/', substr($source,0,$column)); $line = count($lines); $column = strlen( end($lines) ); } // get line of source code where error is and construct a ____^ thingy to show error on next line // this requires that full source is passed in, so line number must be real if( loco_debugging() ){ $lines = preg_split( '/\\r?\\n/', $source, $line+1 ); $offset = $line - 1; if( isset($lines[$offset]) ){ $this->context = $lines[$offset] ."\n". str_repeat(' ', max(0,$column) ).'^'; } } // wrap initial message with context data $this->message = sprintf("Error at line %u, column %u: %s", $line, $column, $this->message ); return $this; } /** * @return string */ public function getContext(){ return $this->context; } } LocaleException.php 0000666 00000000131 15214167344 0010341 0 ustar 00 <?php /** * */ class Loco_error_LocaleException extends Loco_error_Exception { } WriteException.php 0000666 00000000436 15214167344 0010244 0 ustar 00 <?php /** * File system write error. * Generally thrown from Loco_fs_FileWriter */ class Loco_error_WriteException extends Loco_error_Exception { /** * {@inheritdoc} */ public function getTitle(){ return __('Permission denied','loco-translate'); } } Debug.php 0000666 00000001525 15214167344 0006321 0 ustar 00 <?php /** * Developer notice */ class Loco_error_Debug extends Loco_error_Exception { /** * {@inheritdoc} */ public function getType(){ return 'debug'; } /** * {@inheritdoc} */ public function getTitle(){ return __('Debug','loco-translate'); } /** * {@inheritdoc} */ public function getLevel(){ return Loco_error_Exception::LEVEL_DEBUG; } /** * Log debugging message to file without raising admin notice * @param string * @codeCoverageIgnore */ public static function trace( $message ){ if( 1 < func_get_args() ){ $message = call_user_func_array('sprintf',func_get_args()); } $debug = new Loco_error_Debug($message); $debug->setCallee(1); $debug->log(); } } Warning.php 0000666 00000000701 15214167344 0006673 0 ustar 00 <?php /** * Generic warning */ class Loco_error_Warning extends Loco_error_Exception { /** * {@inheritdoc} */ public function getType(){ return 'warning'; } /** * {@inheritdoc} */ public function getTitle(){ return __('Warning','loco-translate'); } /** * {@inheritdoc} */ public function getLevel(){ return Loco_error_Exception::LEVEL_WARNING; } }
dvadf
dvadf
| ver. 1.4 |
Github
|
.
| PHP 7.0.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings