Skip to content

Commit

Permalink
Merge pull request #14 from bearsaturday/remove-deprecated-lib
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
koriym authored Jan 22, 2019
2 parents ec4d449 + 45e423c commit 8a1a890
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 185 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Panda

Copyright (c) 2008-2018 Akihito Koriyama
Copyright (c) 2008-2019 Akihito Koriyama

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand Down
106 changes: 15 additions & 91 deletions Panda.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,16 @@
* @category Panda
* @package Panda
* @author Akihito Koriyama <[email protected]>
* @copyright 2009 Akihito Koriyama All rights reserved.
* @copyright 2009-2019 Akihito Koriyama All rights reserved.
* @license http://opensource.org/licenses/bsd-license.php BSD
* @version SVN: Release: v.0.1.0 $Id: Panda.php 97 2009-10-08 03:45:58Z [email protected] $
* @link n/a
*
* debuglib for PHP5
* Thomas Schüßler <debuglib at atomar dot de>
* http://phpdebuglib.de/
*
* FireBug
* http://www.getfirebug.com/
*
* FirePHP
* http://www.christophdorn.com/
* https://addons.mozilla.org/ja/firefox/addon/6149
* http://www.firephp.org/
*/

// for 5.2.x or earlier
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
define('E_USER_DEPRECATED', 16384);
}

/**
* Panda Class
*
Expand All @@ -50,7 +36,7 @@
* @category Panda
* @package Panda
* @author Akihito Koriyama <[email protected]>
* @copyright 2008 Akihito Koriyama All rights reserved.
* @copyright 2009-2019 Akihito Koriyama All rights reserved.
* @license http://opensource.org/licenses/bsd-license.php BSD
* @version SVN: Release: $Id: Panda.php 97 2009-10-08 03:45:58Z [email protected] $
* @link http://api.Panda-project.net/Panda/Panda.html
Expand All @@ -59,6 +45,7 @@ class Panda
{
/**
* Version
* @deprecated
*/
const VERSION = '0.3.44';

Expand Down Expand Up @@ -118,6 +105,7 @@ class Panda
* config callback on fire
*
* @var string
* @deprecated
*/
const CONFIG_ON_ERROR_FIRED = 'on_error';

Expand All @@ -139,6 +127,7 @@ class Panda
* config - use firephp ?
*
* @var string
* @deprecated
*/
const CONFIG_ENABLE_FIREPHP = 'firephp';

Expand Down Expand Up @@ -174,6 +163,7 @@ class Panda
* config for growl
*
* @var string
* @deprecated
*/
const CONFIG_GROWL = 'growl';

Expand Down Expand Up @@ -228,7 +218,7 @@ class Panda
/**
* API check
*
* @var
* @var string
*/
const CONFIG_IS_API_CHECK = 'is_api';

Expand Down Expand Up @@ -272,8 +262,7 @@ class Panda
/**
* PHP Error code statics
*
* @var integer
*
* @var int
*/
private static $_errorStat = 0;

Expand Down Expand Up @@ -342,18 +331,11 @@ public static function init(array $config = array())
// reset handler
if (self::$_config[self::CONFIG_DEBUG] !== true) {
ini_set('display_errors', 0);
function p($v = ''){
syslog(LOG_INFO, print_r($v, true));
}
if (class_exists('PEAR', false)) {
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('Panda', 'onPearError'));
}
set_exception_handler(array('Panda', 'onException'));
} else {
if (self::$_config[self::CONFIG_ENABLE_FIREPHP]) {
include_once 'FirePHPCore/FirePHP.class.php';
include_once 'FirePHPCore/fb.php';
}
self::_initOnDebug();
if (self::$_config[self::CONFIG_CATCH_FATAL] === true) {
ob_start(array('Panda', 'onFatalError'));
Expand All @@ -374,10 +356,6 @@ function p($v = ''){
*/
private static function _initOnDebug()
{
require_once 'Panda/Debug.php';
require_once 'Panda/Debug/util.php';
require_once 'Panda/Exception.php';
include_once 'Net/Growl.php';
ini_set('display_errors', 1);
// アサーションを有効
assert_options(ASSERT_ACTIVE, 1);
Expand Down Expand Up @@ -453,7 +431,6 @@ public static function onStackError($error)
* @param object $error PEAR Error object
*
* @return void
* @ignore
*/
public static function onPearError(PEAR_Error $error)
{
Expand Down Expand Up @@ -743,44 +720,13 @@ public static function error($heading, $subheading = "", $info = "", array $opti
if (self::$_config[self::CONFIG_DEBUG] !== true) {
return;
}
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') {
if (class_exists('FB', false)) {
$in = isset($options['file']) ? "- in {$options['file']} on line {$options['line']}" : '';
$msg = "$heading - {$subheading} $in";
if ($info) {
FB::group($msg);
FB::error($info);
FB::groupEnd();
return;
}
}
}
static $num = 1; //div id number
$heading = (is_numeric($heading)) ? self::$packageName[$heading] : $heading;
// Application error callback
if (is_callable(self::$_config[self::CONFIG_ON_ERROR_FIRED])) {
call_user_func(self::$_config[self::CONFIG_ON_ERROR_FIRED], $heading, $subheading, $info, $options);
}
$fileInfoString = isset($options['file']) ? "in {$options['file']} on line {$options['line']}" : 'in unknown file';
if (self::$_config[self::CONFIG_ENABLE_FIREPHP] && isset($options['severity'])) {
$fireLevel = FirePHP::ERROR;
switch (true) {
case ($options['severity'] == E_WARNING || $options['severity'] == E_USER_WARNING) :
$fireLevel = FirePHP::WARN;
break;
case ($options['severity'] == E_NOTICE || $options['severity'] == E_USER_NOTICE) :
$fireLevel = FirePHP::INFO;
break;
case ($options['severity'] == E_STRICT) :
$fireLevel = FirePHP::LOG;
break;
default :
$fireLevel = FirePHP::ERROR;
break;
}
FB::send("{$subheading} - {$fileInfoString}", $heading, $fireLevel);
}
self::GrowlNotify($heading, $subheading . "\n{$fileInfoString}");
$defaultOptions = array('file' => null,
'line' => null,
'trace' => array(),
Expand Down Expand Up @@ -847,37 +793,18 @@ public static function error($heading, $subheading = "", $info = "", array $opti

/**
* Growl notify
*
* This needs.
*
* 1) Growl installation.
* 2) Growl setting for remote application acception.
*
* @param string $title
* @param string $description
* @deprecated
*/
public static function growlNotify($title, $description)
{
static $growlApp;

if (self::CONFIG_GROWL !== true) {
return;
}

if (!$growlApp) {
$growlApp = new Net_Growl_Application('Panda', array('Panda_Growl_Notify'));
}
$growl = Net_Growl::singleton($growlApp, null, null);
$growl->setNotificationLimit(16);
$result = $growl->notify('Panda_Growl_Notify', $title, $description);
}

/**
* Message Output
*
* @param string $heading
* @param message $subheading
* @param array $info
* @param string $heading
* @param string $subheading
* @param array $info
*
* @return void
*/
Expand Down Expand Up @@ -1085,10 +1012,6 @@ public static function onFatalError($buffer)
// Web
header("HTTP/1.x 503 Service Temporarily Unavailable.");
$id = substr(md5(serialize($error)), 0, 6);
// FB
if (self::$_config[self::CONFIG_DEBUG] === true && self::$_config[self::CONFIG_ENABLE_FIREPHP]) {
FB::error("Fatal Error - {$error['message']} - ref# {$id}");
}
// write fatal error in file
if (self::$_config[self::CONFIG_LOG_PATH]) {
$path = self::$_config[self::CONFIG_LOG_PATH];
Expand Down Expand Up @@ -1220,10 +1143,11 @@ public static function outputHttpStatus($code, $withBody = true, $body = '', $id
'body' => $body,
'serverProtocol' => $serverProtocol,
'id' => $id);
$include = include self::$_config[self::CONFIG_HTTP_TPL];
if (!$include) {
$tpl = self::$_config[self::CONFIG_HTTP_TPL];
if (! file_exists($tpl)) {
trigger_error('CONFIG_HTTP_TPL file [' . self::$_config[self::CONFIG_HTTP_TPL] . '] is not exist.');
}
include $tpl;
}
}

Expand Down
4 changes: 0 additions & 4 deletions Panda/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @author Akihito Koriyama <[email protected]>
* @copyright 2008 Akihito Koriyama All rights reserved.
* @license http://opensource.org/licenses/bsd-license.php BSD
* @link n/a
*
*/

Expand Down Expand Up @@ -76,8 +75,6 @@ class Panda_Debug

/**
* new不可
*
* @ignore
*/
private function __construct()
{
Expand Down Expand Up @@ -472,7 +469,6 @@ public static function dump(&$var, $varName = false, $pInfo = false)
* @author Akihito Koriyama
*
* @link http://www.php.net/manual/ja/function.var-dump.php#76072
* @ignore
*/
private static function _doDump(&$var, $var_name = NULL, $indent = NULL, $reference = NULL)
{
Expand Down
25 changes: 7 additions & 18 deletions Panda/Debug/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@
* Prints human-readable information about a variable with print location and variable name
*
* @param mixed $mixed variables
* @param formart $formart 'var' | 'export' | 'printa' | 'fire' | 'syslog'
* @param string $format 'var' | 'export' | 'printa' | 'fire' | 'syslog'
* @param array $options
*/
function p($mixed = null, $formart = 'dump', array $options = array())
function p($mixed = null, $format = 'dump', array $options = array())
{
$config = Panda::getConfig();
if (! isset($config[Panda::CONFIG_DEBUG]) || $config[Panda::CONFIG_DEBUG] === false) {
return;
}
if (PHP_SAPI === 'cli') {
call_user_func('v', func_get_args());
return;
Expand All @@ -67,7 +71,7 @@ function p($mixed = null, $formart = 'dump', array $options = array())
return;
}
$options['trace'] = debug_backtrace();
Panda_Debug::p($mixed, $formart, $options);
Panda_Debug::p($mixed, $format, $options);
}

/**
Expand Down Expand Up @@ -213,11 +217,6 @@ function v($values = null)
$paramNum++;
}
}
$label = "$varName in {$file} on line {$line}$method";
if (strlen(serialize($values)) > 1000000) {
$ouputMode = 'dump';
}
$label = (is_object($values)) ? ucwords(get_class($values)) . " $label" : $label;
// if CLI
if (PHP_SAPI === 'cli') {
$colorOpenReverse = "\033[7;32m";
Expand All @@ -229,16 +228,6 @@ function v($values = null)
echo $colorOpenPlain . "in {$colorOpenBold}{$file}{$colorClose}{$colorOpenPlain} on line {$line}$method" . $colorClose . "\n";
return;
}
$labelField = '<fieldset style="color:#4F5155; border:1px solid black;padding:2px;width:10px;">';
$labelField .= '<legend style="color:black;font-size:9pt;font-weight:bold;font-family:Verdana,';
$labelField .= 'Arial,,SunSans-Regular,sans-serif;">' . $label . '</legend>';
if (class_exists('FB', false)) {
$label = 'p() in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'];
FB::group($label);
FB::error($values);
FB::groupEnd();
return;
}
$pre = "<pre style=\"text-align: left;margin: 0px 0px 10px 0px; display: block; background: white; color: black; ";
$pre .= "border: 1px solid #cccccc; padding: 5px; font-size: 12px; \">";
if ($varName != FALSE) {
Expand Down
2 changes: 1 addition & 1 deletion Panda/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct($message, $httpStatus = 200, array $info = array())
/**
* Get error info
*
* @return string
* @return array
*/
public function getInfo()
{
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

Panda is a PHP error handler for [BEAR.Saturday](https://github.com/bearsaturday/BEAR.Saturday) framework

# Requirement
# Testing

* vendor/bin/phpunit

# Run Demo

* php -S 127.0.0.1:8080 -t example

See http://127.0.0.1:8080/

* PHP ^5.4
* PHP ^7.0
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"autoload": {
"classmap": ["Panda"],
"files": ["./Panda.php"]
"files": ["./Panda.php", "./Panda/Debug/util.php"]
}
}
4 changes: 2 additions & 2 deletions data/htdocs/__panda/edit/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
require_once 'vendor/autoload.php';
require 'Panda.php';

set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__DIR__)) . '/vendor/autoload.php');

$file = isset($_GET['file']) ? $_GET['file'] : false;
$line = isset($_GET['line']) ? $_GET['line'] : 0;
Expand Down
Loading

0 comments on commit 8a1a890

Please sign in to comment.