Fix BindingResolutionError when debug toolbar isn't present (#465)

* Fix BindingResolutionError when debug toolbar isn't present

* Formatting
This commit is contained in:
Nabeel S 2019-12-11 15:12:31 -05:00 committed by GitHub
parent e6d38f9338
commit a58bca390b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 21 deletions

View File

@ -18,15 +18,20 @@ if [ "$TRAVIS" = "true" ]; then
exit 0
fi
# Write the version out but place the branch ID in there
# This is only for the dev branch
BASE_VERSION=$(php artisan phpvms:version --base-only)
PKG_NAME=${BASE_VERSION}-${TRAVIS_BRANCH}
# This now includes the pre-release version, so "-dev" by default
PKG_NAME=${BASE_VERSION}
# Don't pass in a version here, just write out the latest hash
php artisan phpvms:version --write > VERSION
php artisan phpvms:version --write >VERSION
VERSION=$(cat VERSION)
fi
echo "Version: $VERSION"
echo "Package name: $TAR_NAME"
FILE_NAME="phpvms-$PKG_NAME"
TAR_NAME="$FILE_NAME.tar.gz"
@ -99,8 +104,6 @@ if [ "$TRAVIS" = "true" ]; then
composer dump-autoload
make clean
echo "Writing $TAR_NAME"
cd /tmp
tar -czf $TAR_NAME -C $TRAVIS_BUILD_DIR/../ phpvms
sha256sum $TAR_NAME >"$TAR_NAME.sha256"

View File

@ -50,6 +50,7 @@ class Version extends Command
}
}
// Always write out the build ID/build number which is the commit hash
$build_number = $this->versionSvc->getBuildId($cfg);
$cfg['current']['commit'] = $build_number;
$cfg['build']['number'] = $build_number;

View File

@ -25,6 +25,7 @@ use App\Models\Subfleet;
use App\Models\User;
use App\Repositories\SettingRepository;
use App\Services\ModuleService;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
@ -75,10 +76,13 @@ class AppServiceProvider extends ServiceProvider
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
if (config('app.debug_toolbar') === true) {
app('debugbar')->enable();
} else {
app('debugbar')->disable();
try {
if (config('app.debug_toolbar') === true) {
app('debugbar')->enable();
} else {
app('debugbar')->disable();
}
} catch (BindingResolutionException $e) {
}
}
}

View File

@ -185,6 +185,8 @@ class VersionService extends Service
$current_version = $this->cleanVersionString($current_version);
}
// Replace "dev" with "alpha", since
$latest_version = $this->getLatestVersion();
// Convert to semver

View File

@ -4,6 +4,18 @@ use App\Exceptions\SettingNotFound;
use Carbon\Carbon;
use Illuminate\Contracts\View\Factory;
/*
* array_key_first only exists in PHP 7.3+
*/
if (!function_exists('array_key_first')) {
function array_key_first(array $arr)
{
foreach ($arr as $key => $unused) {
return $key;
}
}
}
if (!function_exists('in_mask')) {
/**
* Return true/false if a value exists in a mask

View File

@ -3,6 +3,7 @@
namespace Modules\Installer\Http\Controllers;
use App\Contracts\Controller;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Modules\Installer\Services\Importer\ImporterService;
@ -15,7 +16,10 @@ class ImporterController extends Controller
{
$this->importerSvc = $importerSvc;
app('debugbar')->disable();
try {
app('debugbar')->disable();
} catch (BindingResolutionException $e) {
}
}
/**
@ -28,7 +32,10 @@ class ImporterController extends Controller
*/
public function index(Request $request)
{
app('debugbar')->disable(); // saves the query logging
try {
app('debugbar')->disable();
} catch (BindingResolutionException $e) {
}
return view('installer::importer/step1-configure');
}
@ -42,7 +49,10 @@ class ImporterController extends Controller
*/
public function config(Request $request)
{
app('debugbar')->disable(); // saves the query logging
try {
app('debugbar')->disable();
} catch (BindingResolutionException $e) {
}
try {
// Save the credentials to use later
@ -78,7 +88,10 @@ class ImporterController extends Controller
*/
public function run(Request $request)
{
app('debugbar')->disable(); // saves the query logging
try {
app('debugbar')->disable();
} catch (BindingResolutionException $e) {
}
$importer = $request->input('importer');
$start = $request->input('start');

View File

@ -11,6 +11,7 @@ use App\Services\Installer\MigrationService;
use App\Services\Installer\SeederService;
use App\Services\UserService;
use App\Support\Countries;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
@ -63,7 +64,10 @@ class InstallerController extends Controller
$this->seederSvc = $seederSvc;
$this->userService = $userService;
app('debugbar')->disable();
try {
app('debugbar')->disable();
} catch (BindingResolutionException $e) {
}
}
/**

View File

@ -20,17 +20,24 @@ class VersionTest extends TestCase
public function testGreaterThanVersionStrings(): void
{
$test = [
'7.0.0' => '6.0.0',
'7.0.0+1231s' => '6.0.0',
'7.0.0-beta' => '7.0.0-alpha',
'7.0.0-beta.1' => '7.0.0-beta',
'7.0.0-beta.2' => '7.0.0-beta.1',
'7.0.0-beta.2+a34sdf' => '7.0.0-beta.1',
['7.0.0' => '6.0.0'],
['7.0.0+1231s' => '6.0.0'],
// ['7.0.0-beta' => '7.0.0-dev'],
['7.0.0-beta' => '7.0.0-alpha'],
['7.0.0-beta.1' => '7.0.0-beta'],
['7.0.0-beta.2' => '7.0.0-beta.1'],
['7.0.0-beta.2+a34sdf' => '7.0.0-beta.1'],
];
$versionSvc = app(VersionService::class);
foreach ($test as $newVersion => $currentVersion) {
$this->assertTrue($versionSvc->isGreaterThan($newVersion, $currentVersion));
foreach ($test as $set) {
$newVersion = array_key_first($set);
$currentVersion = $set[$newVersion];
$this->assertTrue(
$versionSvc->isGreaterThan($newVersion, $currentVersion),
"{$newVersion} not greater than ${currentVersion}"
);
}
}