use native lara notifs, add phpsandbox package

This commit is contained in:
2018-07-14 17:42:53 +02:00
parent 66afe052b9
commit 6f908356dc
24 changed files with 206 additions and 495 deletions
-107
View File
@@ -1,107 +0,0 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Response;
/**
* Development sandbox.
*
* @package FlowBox\Http\Controllers
*/
class SandboxController extends Controller
{
public function index()
{
return view('debug.sandbox', [
'defcode' => $this->getDefcode()
]);
}
private function evaluateCode($code)
{
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
ini_set('display_not_found_reason', true);
ini_set('display_exceptions', true);
ini_set('html_errors', false);
error_reporting(E_ALL | E_STRICT);
ob_start();
$memBefore = memory_get_usage(true);
$startTime = microtime(true);
// Remove the <?php mark
$code = preg_replace('{^\s*<\?(php)?\s*}i', '', $code);
/** Run code with bootstrap in separate scope */
function runCode($__source_code)
{
eval($__source_code);
}
try {
runCode($code);
} catch (\Exception $e) {
// dump & die - shows nice expandable view of the exception.
dd($e);
}
$endTime = microtime(true);
$memAfter = memory_get_peak_usage(true);
$output = ob_get_clean();
$memory = ($memAfter - $memBefore) / 1024.0 / 1024.0; // in MB
$duration = ($endTime - $startTime) * 1000; // in ms
return compact('memory', 'duration', 'output');
}
public function run(Request $request)
{
$this->validate($request, [
'code' => 'required'
]);
$out = $this->evaluateCode($request->code);
if ($request->wantsJson()) {
$resp = Response::json([
'output' => $out['output'] . "\n#end-php-console-output#",
'memory' => sprintf('%.3f', $out['memory']),
'duration' => sprintf('%.3f', $out['duration'])
], 200);
return $resp;
} else {
// Full HTML page
return view('debug.sandbox', [
'code' => $request->code,
'defcode' => $this->getDefcode(),
'output' => $out['output']
]);
}
}
private function getDefcode()
{
return <<<CODE
<?php
use MightyPork\Utils\Utils;
use MightyPork\Utils\Str;
Utils::logToStdout(false);
Utils::logQueries();
CODE;
}
}
@@ -1,29 +0,0 @@
<?php
namespace App\Models\Concerns;
use App\Models\ContentReport;
use App\Models\Notification;
use Illuminate\Database\Eloquent\Relations\MorphMany;
trait NotificationContext
{
public function bootNotificationContext()
{
static::deleting(function(NotificationContext $self) {
$self->notificationsAbout()->delete();
});
}
/**
* Notifications having this model as a context
*
* @return MorphMany
*/
public function notificationsAbout()
{
return $this->morphMany(Notification::class, 'context');
}
}
+3
View File
@@ -7,6 +7,9 @@ namespace App\Models\Concerns;
use App\Models\ContentReport;
use Illuminate\Database\Eloquent\Relations\MorphMany;
/**
* @property ContentReport $reportsOf
*/
trait Reportable
{
public function bootReportable()
-1
View File
@@ -16,7 +16,6 @@ use Illuminate\Database\Eloquent\Model;
class Proposal extends Model
{
use Reportable;
use NotificationContext;
/** Authoring user */
public function author()
-1
View File
@@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Model;
class Table extends Model
{
use Reportable;
use NotificationContext;
protected static function boot()
{
-1
View File
@@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Model;
class TableComment extends Model
{
use Reportable;
use NotificationContext;
/** Context data table */
public function table()
+16 -21
View File
@@ -4,16 +4,29 @@ namespace App\Models;
use AdamWathan\EloquentOAuth\OAuthIdentity;
use App\Models\Concerns\Reportable;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
/**
* A user in the application
*
* @property Carbon $created_at
* @property Carbon $updated_at
* @property string $name - unique, for vanity URL
* @property string $email - unique, for login and social auth chaining
* @property string $password - hashed pw
* @property Proposal[]|Collection $proposals
* @property Table[]|Collection $tables
* @property OAuthIdentity[]|Collection $socialIdentities
* @property TableComment[]|Collection $tableComments
* @property Table[]|Collection $favouriteTables
* @property Table[]|Collection $followedDiscussions
* @property ContentReport[]|Collection $authoredReports
* @property Notification[]|Collection $notifications
* @property Notification[]|Collection $readNotifications
* @property Notification[]|Collection $unreadNotifications
*/
class User extends Authenticatable
{
@@ -47,13 +60,11 @@ class User extends Authenticatable
foreach ($self->proposals as $proposal) {
$proposal->delete();
}
$self->notificationsCaused()->delete();
});
}
/** Owned tables */
public function dataTables()
public function tables()
{
return $this->hasMany(Table::class, 'owner_id');
}
@@ -94,22 +105,6 @@ class User extends Authenticatable
return $this->hasMany(ContentReport::class, 'author_id');
}
/** Notifications for this user */
public function notifications()
{
return $this->hasMany(Notification::class);
}
/**
* Notifications caused by this user
*
* @return HasMany
*/
public function notificationsCaused()
{
return $this->hasMany(Notification::class, 'actor_id');
}
// --------- Relation Helpers ---------
public function addFavourite(Table $table)