-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Determine asset content-type from extension (#163)
* tweak: disable deprecations dammit * fix: add Asset::getContentType() so as to stop using octet-stream * feat: add handy bin/dbsh script alternative to 'php artisan db' * fix: loosen up slug pattern
- Loading branch information
1 parent
9b3f07b
commit 1fa094e
Showing
5 changed files
with
63 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,50 @@ | ||
<?php | ||
|
||
// This one file should contain all boot-time actions relevant to the app. | ||
// There should be no need to create more ServiceProviders, unless for an actually separable concern. | ||
|
||
namespace App\Providers; | ||
|
||
use App\Auth\Role; | ||
use App\Models\User; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Facades\Gate; | ||
use Illuminate\Support\Facades\Route; | ||
use Illuminate\Support\Facades\URL; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class AppServiceProvider extends ServiceProvider | ||
{ | ||
public function register(): void | ||
{ | ||
// | ||
// Put only DI container bindings here, if and when they're needed. | ||
} | ||
|
||
public function boot(): void | ||
{ | ||
$isDev = !$this->app->isProduction(); | ||
if (!config('app.report_deprecations')) { | ||
// Both Laravel and Symfony try to force error_reporting(-1) with no way out, and it's super annoying. | ||
error_reporting(E_ALL & ~E_DEPRECATED); | ||
} | ||
|
||
// SSL termination means $request->getScheme() is always 'http', so prevent mixed content problems here. | ||
if (str_starts_with(config('app.url'), 'https')) { | ||
URL::forceScheme('https'); | ||
} | ||
|
||
$isDev = !$this->app->isProduction(); | ||
Model::preventLazyLoading($isDev); | ||
Model::preventSilentlyDiscardingAttributes($isDev); | ||
|
||
// SuperAdmins bypass all auth checks | ||
Gate::before(fn(User $user) => $user->hasRole(Role::SuperAdmin) ?: null); | ||
|
||
// make a vague stab at functional abstraction ;) | ||
$this->bootRoutes(); | ||
} | ||
|
||
private function bootRoutes(): void | ||
{ | ||
Route::pattern('slug', '[-_A-Za-z0-9]+'); // underscore is uncommon, but some assets do use it. | ||
} | ||
} |
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,21 @@ | ||
#!/bin/bash | ||
|
||
cd $(dirname $0)/.. | ||
|
||
# allow real environment variables to override .env | ||
orig_pgdatabase=${PGDATABASE:-$DB_DATABASE} | ||
orig_pghost=${PGHOST:-$DB_HOST} | ||
orig_pgpassword=${PGPASSWORD:-$DB_PASSWORD} | ||
orig_pgport=${PGPORT:-$DB_PORT} | ||
orig_pguser=${PGUSER:-$DB_USERNAME} | ||
|
||
[[ -f .env ]] && source .env | ||
|
||
# note we don't respect PG* variables set in .env, since it should only have variables used by Laravel | ||
export PGDATABASE=${orig_pgdatabase:-$DB_DATABASE} | ||
export PGHOST=${orig_pghost:-$DB_HOST} | ||
export PGPASSWORD=${orig_pgpassword:-$DB_PASSWORD} | ||
export PGPORT=${orig_pgport:-$DB_PORT} | ||
export PGUSER=${orig_pguser:-$DB_USERNAME} | ||
|
||
exec psql "$@" |
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