-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
importing from local development svn
- Loading branch information
Kaloyan K. Tsvetkov
authored and
Kaloyan K. Tsvetkov
committed
Aug 11, 2017
1 parent
1532594
commit 0215aa2
Showing
8 changed files
with
963 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php /** | ||
* Autoload helper, if used outside Composer | ||
*/ | ||
function Wano_autoload($class) | ||
{ | ||
$c = explode('\\', $class); | ||
if (($c[0] == 'Wano')) | ||
{ | ||
array_shift($c); | ||
$_ = __DIR__ . '/src/' . join('/', $c) . '.php'; | ||
if (file_exists($_)) | ||
{ | ||
include $_; | ||
} | ||
} | ||
} | ||
spl_autoload_register('Wano_autoload'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php /** | ||
* Output with \Wano\Display\BasicDisplay | ||
*/ | ||
|
||
include __DIR__ . '/demo.php'; | ||
\Wano\Nab::setDisplay(new \Wano\Display\BasicDisplay); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php /** | ||
* Demonstration of what Wano does | ||
*/ | ||
|
||
/* you do not need this if you are using composer */ | ||
require dirname(__FILE__) . '/../autoload.php'; | ||
|
||
/* enable Wano to start collecting PHP error messages */ | ||
\Wano\Nab::register(); | ||
|
||
/* make it collect backtraces only for warnings */ | ||
\Wano\Nab::$backtrace = E_WARNING | E_USER_WARNING; | ||
|
||
/* Now let's do some stuff that raise PHP error messages */ | ||
|
||
/* Will trigger PHP notice "Undefined variable: y" */ | ||
$x[$y]['b'][] = 123; | ||
|
||
/* Will trigger PHP notice "Undefined variable: a" */ | ||
$z = $x[$a]; | ||
|
||
/* Will trigger PHP notice "Array to string conversion" */ | ||
$stuff = array(1,2,3); | ||
(string) $stuff; | ||
|
||
/* Let's nest some functions so that we get a nice backtrace */ | ||
function a123() | ||
{ | ||
/* Will trigger PHP warning "proba" */ | ||
trigger_error('proba', E_USER_WARNING); | ||
|
||
/* Will trigger PHP warning "Invalid error type specified" */ | ||
trigger_error('test', E_WARNING); | ||
} | ||
function b456() | ||
{ | ||
a123(); | ||
} | ||
b456(); | ||
|
||
/* Will trigger xxxx */ | ||
|
||
/* Will trigger: | ||
- PHP notice "Undefined variable: c" | ||
- PHP warning "Invalid argument supplied for foreach()" | ||
*/ | ||
foreach ($c as $i) {} | ||
|
||
/* Will trigger 5 times each: | ||
- PHP notice "Undefined variable: b" | ||
- PHP warning "fopen() expects at least 2 parameters, 1 given" | ||
*/ | ||
for ($i=0; $i<5; $i++) fopen($b); | ||
|
||
/* Will trigger PHP strict "Non-static method x::c() should not be called statically" */ | ||
class x { function c() {}} | ||
x::c(); | ||
|
||
/* Will trigger PHP deprecated "mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead" */ | ||
mysql_connect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php /** | ||
* Output with \Wano\Display\NiftyDisplay | ||
*/ | ||
|
||
include __DIR__ . '/demo.php'; | ||
\Wano\Nab::setDisplay(new \Wano\Display\NiftyDisplay); | ||
|
||
/* Make all log messages expanded when page loads */ | ||
\Wano\Display\NiftyDisplay::$collapsed = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php /** | ||
* Wano: reports raised PHP error messages (mainly warnings and notices) | ||
* | ||
* @author Kaloyan Tsvetkov (KT) <kaloyan@kaloyan.info> | ||
* @package Wano | ||
* @link https://github.com/kktsvetkov/wano/ | ||
* @license http://opensource.org/licenses/LGPL-3.0 GNU Lesser General Public License, version 3.0 | ||
*/ | ||
|
||
namespace Wano\Display; | ||
|
||
/** | ||
* A Simpler Display Adapter | ||
*/ | ||
class BasicDisplay implements DisplayInterface | ||
{ | ||
protected static $levels = array( | ||
E_ERROR => 'error', | ||
E_WARNING => 'warning', | ||
E_PARSE => 'error', | ||
E_NOTICE => 'notice', | ||
E_CORE_ERROR => 'error', | ||
E_CORE_WARNING => 'warning', | ||
E_COMPILE_ERROR => 'error', | ||
E_COMPILE_WARNING => 'warning', | ||
E_USER_ERROR => 'error', | ||
E_USER_WARNING => 'warning', | ||
E_USER_NOTICE => 'notice', | ||
E_STRICT => 'strict', | ||
E_RECOVERABLE_ERROR => 'error', | ||
E_DEPRECATED => 'deprecated', | ||
E_USER_DEPRECATED => 'deprecated', | ||
); | ||
|
||
/** | ||
* @inherit | ||
*/ | ||
public function show(array $logs) | ||
{ | ||
echo '<div style="background:khaki; margin:1em; padding:1em">'; | ||
foreach ($logs as $log) | ||
{ | ||
echo '<div style="margin-bottom: 1em">'; | ||
echo '<p>'; | ||
echo '<span style="background:black;color:white">PHP ', | ||
isset(self::$levels[$log[1]]) | ||
? self::$levels[$log[1]] | ||
: 'unknown', | ||
'</span> '; | ||
|
||
echo '<em>"', | ||
htmlspecialchars($log[2]), | ||
'"</em>'; | ||
|
||
if ($log[0] > 1) | ||
{ | ||
echo ' <b>(', $log[0], ' times)</b> '; | ||
} | ||
|
||
echo ' at <u>', $log[3], ':', $log[4], '</u>'; | ||
echo '</p>'; | ||
|
||
if (isset($log[5])) | ||
{ | ||
echo '<pre style="margin-left:1em">', | ||
htmlspecialchars($log[5]), '</pre>'; | ||
} | ||
echo '</div>'; | ||
} | ||
echo '</div>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php /** | ||
* Wano: reports raised PHP error messages (mainly warnings and notices) | ||
* | ||
* @author Kaloyan Tsvetkov (KT) <kaloyan@kaloyan.info> | ||
* @package Wano | ||
* @link https://github.com/kktsvetkov/wano/ | ||
* @license http://opensource.org/licenses/LGPL-3.0 GNU Lesser General Public License, version 3.0 | ||
*/ | ||
|
||
namespace Wano\Display; | ||
|
||
/** | ||
* Interface that all Wano Display adapters must implement | ||
*/ | ||
interface DisplayInterface | ||
{ | ||
/** | ||
* Prints the harvested PHP error messages | ||
* | ||
* @param array $logs the collected messages; each message is recorded in | ||
* that list as \SplFixedArray with 5 to 6 elements: | ||
* 0 - (integer) reference count, how many times this particular PHP error message has occured | ||
* 1 - (integer) error level | ||
* 2 - (string) error message | ||
* 3 (string) and 4 (integer) - filename and line, where the PHP error message was raised | ||
* 5 - (string) backtrace, if enabled for this error level, see {@link \Wano\Nab::$backtrace} | ||
*/ | ||
public function show(array $logs); | ||
} |
Oops, something went wrong.