Skip to content

Commit cf50b47

Browse files
committed
Initial Commit
1 parent 41d38ef commit cf50b47

File tree

11 files changed

+262
-0
lines changed

11 files changed

+262
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
7+
before_script:
8+
- curl -s http://getcomposer.org/installer | php
9+
- php composer.phar install --dev
10+
11+
script: phpunit

composer.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "kevbaldwyn/utility",
3+
"description": "",
4+
"authors": [
5+
{
6+
"name": "Kevin Baldwyn",
7+
"email": "[email protected]"
8+
}
9+
],
10+
"require": {
11+
"php": ">=5.3.0",
12+
"illuminate/support": "4.0.x"
13+
},
14+
"autoload": {
15+
"psr-0": {
16+
"KevBaldwyn\\Utility": "src/"
17+
}
18+
},
19+
"minimum-stability": "dev"
20+
}

composer.lock

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory>./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

src/KevBaldwyn/Utility/Debug.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace KevBaldwyn\Utility;
3+
4+
use Config;
5+
6+
class Debug {
7+
8+
private static $log = array();
9+
10+
public static function pa($var, $die = false) {
11+
if(Config::get('app.debug')) {
12+
echo '<pre>';
13+
if(is_array($var)) {
14+
print_r($var);
15+
}else{
16+
var_dump($var);
17+
}
18+
echo '</pre>';
19+
if($die) {
20+
die();
21+
}
22+
}
23+
}
24+
25+
public static function log($var) {
26+
self::$log[] = $var;
27+
}
28+
29+
public static function outputLog() {
30+
if(Config::get('app.debug')) {
31+
foreach(self::$log as $var) {
32+
self::pa($var);
33+
}
34+
}
35+
}
36+
37+
public static function getLog() {
38+
return self::$log;
39+
}
40+
41+
}
42+
43+
?>
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php namespace KevBaldwyn\Utility\Facades;
2+
3+
use Illuminate\Support\Facades\Facade;
4+
5+
class Debug extends Facade {
6+
7+
/**
8+
* Get the registered name of the component.
9+
*
10+
* @return string
11+
*/
12+
protected static function getFacadeAccessor() { return 'debug'; }
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
namespace KevBaldwyn\Utility;
3+
4+
use Log;
5+
use Config;
6+
use Symfony\Component\HttpKernel\Exception\FlattenException;
7+
use Debug;
8+
use \php_error\ErrorHandler;
9+
10+
class PHPErrorException {
11+
12+
public static function report($exception, $code = false) {
13+
14+
Log::error($exception);
15+
16+
if(Config::get('app.debug')) {
17+
18+
ini_set('display_errors', '1');
19+
20+
$flatten = FlattenException::create($exception, $code);
21+
22+
$handler = new ErrorHandler(array('application_root' => str_replace('/public', '', $_SERVER['DOCUMENT_ROOT'])));
23+
$handler->turnOn();
24+
$handler->addOutputArray('Debug:log', Debug::getLog());
25+
$handler->reportError($flatten->getCode(), $flatten->getMessage(), $flatten->getLine(), $flatten->getFile(), $exception);
26+
27+
}
28+
29+
}
30+
31+
}
32+
33+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php namespace KevBaldwyn\Utility\Providers;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
use KevBaldwyn\Utility\Debug;
5+
use KevBaldwyn\Utility\PHPErrorException;
6+
//use Symfony\Component\HttpKernel\Exception\ErrorException;
7+
8+
class UtilityServiceProvider extends ServiceProvider {
9+
10+
/**
11+
* Indicates if loading of the provider is deferred.
12+
*
13+
* @var bool
14+
*/
15+
protected $defer = false;
16+
17+
/**
18+
* Bootstrap the application events.
19+
*
20+
* @return void
21+
*/
22+
public function boot()
23+
{
24+
$this->package('kevbaldwyn/utility');
25+
}
26+
27+
/**
28+
* Register the service provider.
29+
*
30+
* @return void
31+
*/
32+
public function register()
33+
{
34+
// register the classes
35+
$this->app['debug'] = $this->app->share(function() {
36+
return new Debug;
37+
});
38+
$this->app['php_errorexception'] = $this->app->share(function() {
39+
return new PHPErrorException;
40+
});
41+
42+
// incldue the start file
43+
include(__DIR__.'/../start.php');
44+
45+
}
46+
47+
/**
48+
* Get the services provided by the provider.
49+
*
50+
* @return array
51+
*/
52+
public function provides()
53+
{
54+
return array('utility');
55+
}
56+
57+
}

src/KevBaldwyn/Utility/start.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* define an error handler
4+
*/
5+
App::error(function(ErrorException $exception, $code)
6+
{
7+
KevBaldwyn\Utility\PHPErrorException::report($exception, $code);
8+
});
9+
10+
?>

tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)