mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Move assets to 5.7 location * Add 5.7 SVGs * add cache data dir * update QUEUE_DRIVER -> QUEUE_CONNECTION * Update trusted proxy config * update composer.json * 5.5 command loading * @php and @endphp can't be inline * Laravel 5.6 logging, Nice! * Update blade directives * improved redirects * remove unneeded service providers * Improved debugbar loading * no need to emulate renderable exceptions anymore * merge updated 5.7 files (WIP) * Enable CSRF * database_path() call causes issue in init.php * fix old testcase name * generic phpunit 7 fixes * add missed file_get_contents Keep migrations table content * fix duplicate key * Drop old php versions from travis-ci * remove hhvm * fix code climate message * remove use of deprecated function assertInternalType * Disable CSRF, we'll enable it separately. All forms need to be updated to work. * Update document references
98 lines
2.9 KiB
PHP
98 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Laravel.php
|
|
*
|
|
* Utility class to gather code to do
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* @package LibreNMS
|
|
* @link http://librenms.org
|
|
* @copyright 2018 Tony Murray
|
|
* @author Tony Murray <[email protected]>
|
|
*/
|
|
|
|
namespace LibreNMS\Util;
|
|
|
|
use App;
|
|
use Illuminate\Database\Events\QueryExecuted;
|
|
use LibreNMS\Config;
|
|
use LibreNMS\DB\Eloquent;
|
|
use Log;
|
|
|
|
class Laravel
|
|
{
|
|
public static function bootCli()
|
|
{
|
|
// make sure Laravel isn't already booted
|
|
if (class_exists('App') && App::isBooted()) {
|
|
return;
|
|
}
|
|
|
|
define('LARAVEL_START', microtime(true));
|
|
$install_dir = realpath(__DIR__ . '/../..');
|
|
$app = require_once $install_dir . '/bootstrap/app.php';
|
|
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);
|
|
$kernel->bootstrap();
|
|
}
|
|
|
|
public static function enableQueryDebug()
|
|
{
|
|
$db = Eloquent::DB();
|
|
|
|
if ($db && !$db->getEventDispatcher()->hasListeners('Illuminate\Database\Events\QueryExecuted')) {
|
|
$db->listen(function (QueryExecuted $query) {
|
|
// collect bindings and make them a little more readable
|
|
$bindings = collect($query->bindings)->map(function ($item) {
|
|
if ($item instanceof \Carbon\Carbon) {
|
|
return $item->toDateTimeString();
|
|
}
|
|
|
|
return $item;
|
|
})->toJson();
|
|
|
|
if (class_exists('Log')) {
|
|
Log::debug("SQL[%Y{$query->sql} %y$bindings%n {$query->time}ms] \n", ['color' => true]);
|
|
} else {
|
|
c_echo("SQL[%Y{$query->sql} %y$bindings%n {$query->time}ms] \n");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public static function disableQueryDebug()
|
|
{
|
|
$db = Eloquent::DB();
|
|
|
|
if ($db) {
|
|
// remove all query executed event handlers
|
|
$db->getEventDispatcher()->flush('Illuminate\Database\Events\QueryExecuted');
|
|
}
|
|
}
|
|
|
|
public static function enableCliDebugOutput()
|
|
{
|
|
if (class_exists('\Log') && App::runningInConsole()) {
|
|
Log::setDefaultDriver('console');
|
|
}
|
|
}
|
|
|
|
public static function disableCliDebugOutput()
|
|
{
|
|
if (class_exists('Log')) {
|
|
Log::setDefaultDriver('logfile');
|
|
}
|
|
}
|
|
}
|