Skip to content

Commit bca6302

Browse files
committed
initial commit
0 parents  commit bca6302

24 files changed

+1414
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "understand/understand-laravel",
3+
"description": "",
4+
"authors": [
5+
{
6+
"name": "Aivis",
7+
"email": "aivis.silins@gmail.com"
8+
}
9+
],
10+
"require": {
11+
"php": ">=5.3.0",
12+
"illuminate/support": "4.1.*"
13+
},
14+
"autoload": {
15+
"classmap": [
16+
"src/migrations"
17+
],
18+
"psr-0": {
19+
"Understand\\UnderstandLaravel\\": "src/"
20+
}
21+
},
22+
"minimum-stability": "stable"
23+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
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 suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

public/.gitkeep

Whitespace-only changes.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?php
2+
3+
namespace Understand\UnderstandLaravel;
4+
5+
class ExceptionEncoder
6+
{
7+
8+
/**
9+
* Serialize exception object
10+
*
11+
* @param \Exception $exception
12+
* @return type
13+
*/
14+
public function exceptionToArray(\Exception $exception)
15+
{
16+
$trace = $exception->getTrace();
17+
18+
return [
19+
'message' => $exception->getMessage(),
20+
'code' => $exception->getCode(),
21+
'file' => $exception->getFile(),
22+
'line' => $exception->getLine(),
23+
'stack' => $this->stackTraceToArray($trace)
24+
];
25+
}
26+
27+
/**
28+
* Serialize stack trace to array
29+
*
30+
* @param array $stackTrace
31+
* @return array
32+
*/
33+
public function stackTraceToArray(array $stackTrace)
34+
{
35+
$stack = [];
36+
37+
foreach ($stackTrace as $trace)
38+
{
39+
$type = $this->stackTraceCallToString($trace);
40+
$args = $this->stackTraceArgsToArray($trace);
41+
42+
$stack[] = [
43+
'class' => isset($trace['class']) ? $trace['class'] : '',
44+
'function' => $trace['function'],
45+
'args' => $args,
46+
'type' => $type,
47+
'file' => $this->getStackTraceFile($trace),
48+
'line' => $this->getStackTraceLine($trace)
49+
];
50+
}
51+
52+
return $stack;
53+
}
54+
55+
/**
56+
* Return stack trace line number
57+
*
58+
* @param array $trace
59+
* @return mixed
60+
*/
61+
protected function getStackTraceLine(array $trace)
62+
{
63+
if (isset($trace['line']))
64+
{
65+
return $trace['line'];
66+
}
67+
}
68+
69+
/**
70+
* Return stack trace file
71+
*
72+
* @param array $trace
73+
* @return mixed
74+
*/
75+
protected function getStackTraceFile(array $trace)
76+
{
77+
if (isset($trace['file']))
78+
{
79+
return $trace['file'];
80+
}
81+
}
82+
83+
/**
84+
* Return call type
85+
*
86+
* @param array $trace
87+
* @return string
88+
*/
89+
protected function stackTraceCallToString(array $trace)
90+
{
91+
if (!isset($trace['type']))
92+
{
93+
return 'function';
94+
}
95+
96+
if ($trace['type'] == '::')
97+
{
98+
return 'static';
99+
}
100+
101+
if ($trace['type'] == '->')
102+
{
103+
return 'method';
104+
}
105+
}
106+
107+
/**
108+
* Serialize stack trace function arguments
109+
*
110+
* @param array $trace
111+
* @return array
112+
*/
113+
protected function stackTraceArgsToArray(array $trace)
114+
{
115+
$params = [];
116+
117+
foreach ($trace['args'] as $arg)
118+
{
119+
if (is_array($arg))
120+
{
121+
$params[] = 'array(' . count($arg) . ')';
122+
}
123+
else if (is_object($arg))
124+
{
125+
$params[] = get_class($arg);
126+
}
127+
else if (is_string($arg))
128+
{
129+
$params[] = 'string(' . $arg . ')';
130+
}
131+
else if (is_int($arg))
132+
{
133+
$params[] = 'int(' . $arg . ')';
134+
}
135+
else if (is_float($arg))
136+
{
137+
$params[] = 'float(' . $arg . ')';
138+
}
139+
else if (is_bool($arg))
140+
{
141+
$params[] = 'bool(' . ($arg ? 'true' : 'false') . ')';
142+
}
143+
else
144+
{
145+
$params[] = (string) $arg;
146+
}
147+
}
148+
149+
return $params;
150+
}
151+
152+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Understand\UnderstandLaravel\Exceptions;
4+
5+
class HandlerException extends \Exception
6+
{
7+
8+
/**
9+
* @param string $message
10+
* @param int $code
11+
* @param \Exception $previous
12+
*/
13+
public function __construct($message, $code = 0, $previous = null)
14+
{
15+
$message = 'understand-laravel: ' . $message;
16+
17+
parent::__construct($message, $code, $previous);
18+
}
19+
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Understand\UnderstandLaravel\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class UnderstandFieldProvider extends Facade
8+
{
9+
10+
/**
11+
* Return facade loc accessor
12+
*
13+
* @return string
14+
*/
15+
protected static function getFacadeAccessor()
16+
{
17+
return 'understand.field-provider';
18+
}
19+
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Understand\UnderstandLaravel\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class UnderstandLogger extends Facade
8+
{
9+
10+
/**
11+
* Return facade loc accessor
12+
*
13+
* @return string
14+
*/
15+
protected static function getFacadeAccessor()
16+
{
17+
return 'understand.logger';
18+
}
19+
20+
}

0 commit comments

Comments
 (0)