diff --git a/LICENSE b/LICENSE index d706a0f..cd6dea1 100644 --- a/LICENSE +++ b/LICENSE @@ -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: diff --git a/Panda.php b/Panda.php index cd8c692..91752f0 100644 --- a/Panda.php +++ b/Panda.php @@ -8,7 +8,7 @@ * @category Panda * @package Panda * @author Akihito Koriyama - * @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 koriyama@users.sourceforge.jp $ * @link n/a @@ -16,22 +16,8 @@ * debuglib for PHP5 * Thomas Schüßler * 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 * @@ -50,7 +36,7 @@ * @category Panda * @package Panda * @author Akihito Koriyama - * @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 koriyama@users.sourceforge.jp $ * @link http://api.Panda-project.net/Panda/Panda.html @@ -59,6 +45,7 @@ class Panda { /** * Version + * @deprecated */ const VERSION = '0.3.44'; @@ -118,6 +105,7 @@ class Panda * config callback on fire * * @var string + * @deprecated */ const CONFIG_ON_ERROR_FIRED = 'on_error'; @@ -139,6 +127,7 @@ class Panda * config - use firephp ? * * @var string + * @deprecated */ const CONFIG_ENABLE_FIREPHP = 'firephp'; @@ -174,6 +163,7 @@ class Panda * config for growl * * @var string + * @deprecated */ const CONFIG_GROWL = 'growl'; @@ -228,7 +218,7 @@ class Panda /** * API check * - * @var + * @var string */ const CONFIG_IS_API_CHECK = 'is_api'; @@ -272,8 +262,7 @@ class Panda /** * PHP Error code statics * - * @var integer - * + * @var int */ private static $_errorStat = 0; @@ -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')); @@ -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); @@ -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) { @@ -743,18 +720,6 @@ 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 @@ -762,25 +727,6 @@ public static function error($heading, $subheading = "", $info = "", array $opti 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(), @@ -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 */ @@ -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]; @@ -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; } } diff --git a/Panda/Debug.php b/Panda/Debug.php index 241755d..99c83b4 100644 --- a/Panda/Debug.php +++ b/Panda/Debug.php @@ -34,7 +34,6 @@ * @author Akihito Koriyama * @copyright 2008 Akihito Koriyama All rights reserved. * @license http://opensource.org/licenses/bsd-license.php BSD - * @link n/a * */ @@ -76,8 +75,6 @@ class Panda_Debug /** * new不可 - * - * @ignore */ private function __construct() { @@ -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) { diff --git a/Panda/Debug/util.php b/Panda/Debug/util.php index e7a4e0a..52aabdf 100644 --- a/Panda/Debug/util.php +++ b/Panda/Debug/util.php @@ -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; @@ -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); } /** @@ -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"; @@ -229,16 +228,6 @@ function v($values = null) echo $colorOpenPlain . "in {$colorOpenBold}{$file}{$colorClose}{$colorOpenPlain} on line {$line}$method" . $colorClose . "\n"; return; } - $labelField = '
'; - $labelField .= '' . $label . ''; - 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 = "
";
     if ($varName != FALSE) {
diff --git a/Panda/Exception.php b/Panda/Exception.php
index 0a61930..fdf7ac9 100644
--- a/Panda/Exception.php
+++ b/Panda/Exception.php
@@ -46,7 +46,7 @@ public function __construct($message, $httpStatus = 200, array $info = array())
     /**
      * Get error info
      *
-     * @return string
+     * @return array
      */
     public function getInfo()
     {
diff --git a/README.md b/README.md
index 09dd4db..6482202 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/composer.json b/composer.json
index 487eab2..b779838 100644
--- a/composer.json
+++ b/composer.json
@@ -17,6 +17,6 @@
     },
     "autoload": {
         "classmap": ["Panda"],
-        "files": ["./Panda.php"]
+        "files": ["./Panda.php", "./Panda/Debug/util.php"]
     }
 }
diff --git a/data/htdocs/__panda/edit/index.php b/data/htdocs/__panda/edit/index.php
index e396c4e..01d7887 100644
--- a/data/htdocs/__panda/edit/index.php
+++ b/data/htdocs/__panda/edit/index.php
@@ -1,6 +1,6 @@
  true,                                                    // debug mode
-    Panda::CONFIG_VALID_PATH => array('/'),                                         // valid path (user source code path)
-    Panda::CONFIG_LOG_PATH => '/tmp/',                                              // log directory path
-    Panda::CONFIG_HTTP_TPL => __DIR__ . '/../../../Panda/templates/http.php',       // custom Http error output template
-    Panda::CONFIG_FATAL_HTML => __DIR__ . '/../../../Panda/templates/fatal.php',    // fatal error template
-    Panda::CONFIG_ON_ERROR_FIRED => array('Panda_App_Error_Handler', 'onError'),    // application error callback on fire
-    Panda::CONFIG_ENABLE_FIREPHP => true,                                           // enable firephp on firefox ?
-    Panda::CONFIG_CATCH_FATAL => true,                                              // catch fatal error ? (recommend false for debug)
-    Panda::CONFIG_PANDA_PATH => '/',                                                // Panda htdocs base path
-    Panda::CONFIG_EDITOR => Panda::EDITOR_BESPIN | Panda::EDITOR_TEXTMATE,          // Text editor link
-    Panda::CONFIG_CATCH_STRICT => true
-);                                            // catch stric error in compile ?
-Panda::init($config);
-
-/**
- * Application error handler
- *
- * @param string $headering
- * @param string $subheading
- * @param array  $info
- * @param array  $options
- *
- * @return void
- */
-class Panda_App_Error_Handler
-{
-    public static function onError($heading, $subheading, $info, $options)
-    {
-    }
-}
\ No newline at end of file
diff --git a/data/htdocs/panda_sample/pear_error.php b/data/htdocs/panda_sample/pear_error.php
deleted file mode 100644
index 2bbc18f..0000000
--- a/data/htdocs/panda_sample/pear_error.php
+++ /dev/null
@@ -1,8 +0,0 @@
-
 	
  • panda debug function
  • -

    FirePHP supported.

    -

    firebug console error output on FireFox is also available, open firefox console after install FirePHP.

    diff --git a/data/htdocs/panda_sample/memory_error.php b/example/memory_error.php similarity index 67% rename from data/htdocs/panda_sample/memory_error.php rename to example/memory_error.php index 784634b..cf5fd5f 100644 --- a/data/htdocs/panda_sample/memory_error.php +++ b/example/memory_error.php @@ -1,5 +1,6 @@ time()); // show status page with specify http code diff --git a/example/panda_ini.php b/example/panda_ini.php new file mode 100644 index 0000000..9bc8da7 --- /dev/null +++ b/example/panda_ini.php @@ -0,0 +1,14 @@ + true, // debug mode + Panda::CONFIG_VALID_PATH => array('/'), // valid path (user source code path) + Panda::CONFIG_LOG_PATH => '/tmp/', // log directory path + Panda::CONFIG_HTTP_TPL => dirname(__DIR__) . '/Panda/templates/http.php', // custom Http error output template + Panda::CONFIG_FATAL_HTML => dirname(__DIR__) . '/Panda/templates/fatal.php', // fatal error template + Panda::CONFIG_CATCH_FATAL => true, // catch fatal error ? (recommend false for debug) + Panda::CONFIG_PANDA_PATH => '/', // Panda htdocs base path + Panda::CONFIG_EDITOR => Panda::EDITOR_BESPIN | Panda::EDITOR_TEXTMATE, // Text editor link + Panda::CONFIG_CATCH_STRICT => true +]); diff --git a/example/pear_error.php b/example/pear_error.php new file mode 100644 index 0000000..40e16d4 --- /dev/null +++ b/example/pear_error.php @@ -0,0 +1,6 @@ + diff --git a/tests/Test/Panda/PandaTest.php b/tests/Test/Panda/PandaTest.php index 43f7206..949b695 100644 --- a/tests/Test/Panda/PandaTest.php +++ b/tests/Test/Panda/PandaTest.php @@ -4,21 +4,18 @@ class PandaTest extends PHPUnit_Framework_TestCase { protected function setUp() { - $config = [ + Panda::init([ Panda::CONFIG_DEBUG => false, Panda::CONFIG_VALID_PATH => ['/'], Panda::CONFIG_LOG_PATH => '/tmp', - Panda::CONFIG_ON_ERROR_FIRED => false, - Panda::CONFIG_ON_FATAL_ERROR => 'Panda/template/fatal.html', - Panda::CONFIG_ENABLE_FIREPHP => true, - Panda::CONFIG_FATAL_HTML => 'Panda/template/fatal.html', - Panda::CONFIG_HTTP_TPL => 'Panda/template/http.php', + Panda::CONFIG_ON_FATAL_ERROR => dirname(__DIR__, 2) .'/Panda/template/fatal.html', + Panda::CONFIG_FATAL_HTML => dirname(__DIR__, 2) . '/Panda/template/fatal.html', + Panda::CONFIG_HTTP_TPL => dirname(__DIR__, 2) . '/Panda/template/http.php', Panda::CONFIG_CATCH_FATAL => false, Panda::CONFIG_CATCH_STRICT => true, Panda::CONFIG_PANDA_PATH => '/', Panda::CONFIG_EDITOR => 0 - ]; - Panda::init($config); + ]); } public function testGetConfig() @@ -27,4 +24,10 @@ public function testGetConfig() $this->assertTrue(isset($config[Panda::CONFIG_DEBUG])); $this->assertFalse($config[Panda::CONFIG_DEBUG]); } + + public function testP() + { + $result = p('debug'); + $this->assertNull($result); + } }