Skip to content

Commit

Permalink
Laravel 7.x Shift (librenms#11676)
Browse files Browse the repository at this point in the history
* Shift bindings

PHP 5.5.9+ adds the new static `class` property which provides the fully qualified class name. This is preferred over using class name strings as these references are checked by the parser.

* Shift core files

* Shift to Throwable

* Shift Laravel dependencies
Add laravel/ui dependency
Use our fork of string-blade-compiler

* Shift config files

Default config files

In an effort to make upgrading the constantly changing config files
easier, Shift defaulted them so you can review the commit diff for
changes. Moving forward, you should use ENV variables or create a
separate config file to allow the core config files to remain
automatically upgradeable.

Restore config header comment

* Remove duplicate named routes

* add basic trust host middleware

* Trusted proxies should be default null

* Fix missed rename

* wip

* Rename routes

* Update trustedproxy.php

* Update Kernel.php

* revert trustedproxy.php

It only accepted '*' and not ['*']

* Fix tests

fake request was causing the error

Co-authored-by: Laravel Shift <[email protected]>
Co-authored-by: Tony Murray <[email protected]>
  • Loading branch information
3 people authored Jul 9, 2020
1 parent e5bb6d8 commit f526ba3
Show file tree
Hide file tree
Showing 19 changed files with 963 additions and 624 deletions.
7 changes: 6 additions & 1 deletion LibreNMS/Util/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static function enableCliDebugOutput()
public static function disableCliDebugOutput()
{
if (self::isBooted()) {
Log::setDefaultDriver('logfile');
Log::setDefaultDriver('stack');
}
}

Expand All @@ -139,6 +139,11 @@ private static function rewriteDummyHeaders($request, $auth)
// set dummy path allows url helper to work and prevents full init again
$new_uri = ($auth ? '/dummy_legacy_auth' : '/dummy_legacy_unauth');
$request->server->set('REQUEST_URI', $new_uri);

// tests fail without this
if ($request->server->get('REMOTE_ADDR') === null) {
$request->server->set('REMOTE_ADDR', '127.0.0.1');
}

// set json type to prevent redirects in the dummy page
$request->server->set('HTTP_ACCEPT', 'dummy/json');
Expand Down
5 changes: 3 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Exceptions;

use Throwable;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
Expand Down Expand Up @@ -35,7 +36,7 @@ class Handler extends ExceptionHandler
\LibreNMS\Exceptions\MaximumExecutionTimeExceeded::class,
];

public function render($request, Exception $exception)
public function render($request, Throwable $exception)
{
// If for some reason Blade hasn't been registered, try it now
try {
Expand All @@ -59,7 +60,7 @@ public function render($request, Exception $exception)
return parent::render($request, $exception);
}

protected function convertExceptionToArray(Exception $e)
protected function convertExceptionToArray(Throwable $e)
{
// override the non-debug error output to clue in user on how to debug
if (!config('app.debug') && !$this->isHttpException($e)) {
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\HandleCors::class,
\App\Http\Middleware\CheckForMaintenanceMode::class,
Expand Down
20 changes: 20 additions & 0 deletions app/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustHosts as Middleware;

class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TrustProxies extends Middleware
/**
* The trusted proxies for this application.
*
* @var array|string
* @var array|string|null
*/
protected $proxies;

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public function mefInfo()

public function muninPlugins()
{
return $this->hasMany('App\Models\MuninPlugin', 'device_id');
return $this->hasMany(\App\Models\MuninPlugin::class, 'device_id');
}

public function ospfInstances()
Expand Down
32 changes: 20 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
"issues": "https://github.com/librenms/librenms/issues/",
"irc": "irc://irc.freenode.org/#librenms"
},
"repositories": [
{
"type": "vcs",
"url": "[email protected]:librenms/StringBladeCompiler.git"
}
],
"require": {
"php": "^7.2",
"php": "^7.2.5",
"ext-curl": "*",
"ext-gd": "*",
"ext-json": "*",
Expand All @@ -38,10 +44,9 @@
"easybook/geshi": "^1.0.8",
"ezyang/htmlpurifier": "^4.8",
"fico7489/laravel-pivot": "^3.0",
"fideloper/proxy": "^4.0",
"fruitcake/laravel-cors": "^2.0",
"fideloper/proxy": "^4.2",
"influxdb/influxdb-php": "^1.14",
"laravel/framework": "^6.18",
"laravel/framework": "^7.11",
"laravel/tinker": "^2.0",
"librenms/laravel-vue-i18n-generator": "^0.1.46",
"oriceon/toastr-5-laravel": "dev-master",
Expand All @@ -53,22 +58,25 @@
"symfony/yaml": "^4.0",
"tecnickcom/tcpdf": "~6.2.0",
"tightenco/ziggy": "^0.8.0",
"wpb/string-blade-compiler": "4.0.x-dev",
"xjtuwangke/passwordhash": "dev-master"
"wpb/string-blade-compiler": "dev-laravel-7-and-autoload-blade-custom-directives",
"xjtuwangke/passwordhash": "dev-master",
"laravel/ui": "^2.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^6.3"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
"barryvdh/laravel-ide-helper": "^2.6",
"barryvdh/laravel-ide-helper": "^2.6.7",
"fzaninotto/faker": "^1.9.1",
"justinrainbow/json-schema": "^5.2",
"laravel/dusk": "^5.8",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"laravel/dusk": "^5.9",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.1",
"php-parallel-lint/php-parallel-lint": "^1.1",
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5",
"staudenmeir/dusk-updater": "^1.1",
"facade/ignition": "^1.4"
"facade/ignition": "^2.0"
},
"suggest": {
"ext-memcached": "Required if you utilize distributed polling",
Expand Down
Loading

0 comments on commit f526ba3

Please sign in to comment.