-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from tylercd100/dev-record-extra-information
Merging for 3.0.0 Release
- Loading branch information
Showing
16 changed files
with
354 additions
and
42 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
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
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
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
38 changes: 38 additions & 0 deletions
38
migrations/2016_03_27_000000_add_user_data_and_url_to_lern_tables.php
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,38 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
|
||
class AddUserDataAndUrlToLERNTables extends Migration { | ||
|
||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table(config('lern.record.table'), function(Blueprint $table) { | ||
$table->integer('user_id')->nullable(); | ||
$table->text('data')->nullable(); | ||
$table->string('url')->nullable(); | ||
$table->string('method')->nullable(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table(config('lern.record.table'), function(Blueprint $table) { | ||
$table->dropColumn('user_id'); | ||
$table->dropColumn('data'); | ||
$table->dropColumn('url'); | ||
$table->dropColumn('method'); | ||
}); | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
src/Notifications/Notifier.php → src/Components/Notifier.php
100755 → 100644
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
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,150 @@ | ||
<?php | ||
|
||
namespace Tylercd100\LERN\Components; | ||
|
||
use Exception; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Input; | ||
use Illuminate\Support\Facades\Request; | ||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; | ||
use Tylercd100\LERN\Models\ExceptionModel; | ||
|
||
class Recorder { | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
protected $config = []; | ||
|
||
/** | ||
* The constructor | ||
*/ | ||
public function __construct() { | ||
$this->config = config('lern.record'); | ||
} | ||
|
||
/** | ||
* Records an Exception to the database | ||
* @param Exception $e The exception you want to record | ||
* @return ExceptionModel | ||
*/ | ||
public function record(Exception $e) | ||
{ | ||
$opts = [ | ||
'class' => get_class($e), | ||
'file' => $e->getFile(), | ||
'line' => $e->getLine(), | ||
'code' => $e->getCode(), | ||
'message' => $e->getMessage(), | ||
'trace' => $e->getTraceAsString(), | ||
]; | ||
|
||
|
||
$configDependant = ['user_id', 'status_code', 'method', 'data', 'url']; | ||
|
||
foreach ($configDependant as $key) { | ||
if ($this->canCollect($key)) { | ||
$opts[$key] = $this->collect($key, $e); | ||
} | ||
} | ||
|
||
return ExceptionModel::create($opts); | ||
} | ||
|
||
/** | ||
* Checks the config to see if you can collect certain information | ||
* @param string $type the config value you want to check | ||
* @return boolean | ||
*/ | ||
private function canCollect($type) { | ||
if (!empty($this->config) && !empty($this->config['collect']) && !empty($this->config['collect'][$type])) { | ||
return $this->config['collect'][$type] === true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @param string $key | ||
*/ | ||
protected function collect($key,Exception $e = null){ | ||
switch ($key) { | ||
case 'user_id': | ||
return $this->getUserId(); | ||
case 'method': | ||
return $this->getMethod(); | ||
case 'status_code': | ||
return $this->getStatusCode($e); | ||
case 'url': | ||
return $this->getUrl(); | ||
case 'data': | ||
return $this->getData(); | ||
default: | ||
throw new Exception("{$key} is not supported! Therefore it cannot be collected!"); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the ID of the User that is logged in | ||
* @return integer|null The ID of the User or Null if not logged in | ||
*/ | ||
protected function getUserId() { | ||
$user = Auth::user(); | ||
if (is_object($user)) { | ||
return $user->id; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the Method of the Request | ||
* @return string|null Possible values are null or GET, POST, DELETE, PUT, etc... | ||
*/ | ||
protected function getMethod() { | ||
$method = Request::method(); | ||
if (!empty($method)) { | ||
return $method; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the input data of the Request | ||
* @return array|null The Input data or null | ||
*/ | ||
protected function getData() { | ||
$data = Input::all(); | ||
if (is_array($data)) { | ||
return $data; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the URL of the Request | ||
* @return string|null Returns a URL string or null | ||
*/ | ||
protected function getUrl() { | ||
$url = Request::url(); | ||
if (is_string($url)) { | ||
return $url; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the status code of the Exception | ||
* @param Exception $e The Exception to check | ||
* @return string|integer The status code value | ||
*/ | ||
protected function getStatusCode(Exception $e) { | ||
if ($e instanceof HttpExceptionInterface) { | ||
return $e->getStatusCode(); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Notifications/MonologHandlerFactory.php → src/Factories/MonologHandlerFactory.php
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
Oops, something went wrong.