From 26fc8b1bc9e2788b8a1585180437da2d2813d207 Mon Sep 17 00:00:00 2001 From: Skyler Fenn Date: Sun, 26 Jul 2020 10:30:11 -0600 Subject: [PATCH 1/4] update files from laravel skeleton --- .../app/Http/Controllers/Controller.stub | 6 +- src/publishes/app/Http/Kernel.stub | 18 ++- src/publishes/bootstrap/app.stub | 2 +- src/publishes/config/app.stub | 103 +++++++-------- src/publishes/config/mail.stub | 117 ++++++++---------- 5 files changed, 122 insertions(+), 124 deletions(-) diff --git a/src/publishes/app/Http/Controllers/Controller.stub b/src/publishes/app/Http/Controllers/Controller.stub index c5125cd..a0a2a8a 100644 --- a/src/publishes/app/Http/Controllers/Controller.stub +++ b/src/publishes/app/Http/Controllers/Controller.stub @@ -2,12 +2,12 @@ namespace App\Http\Controllers; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; -use LaraPress\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; +use Illuminate\Routing\Controller as BaseController; class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; -} \ No newline at end of file +} diff --git a/src/publishes/app/Http/Kernel.stub b/src/publishes/app/Http/Kernel.stub index bdba26f..36ced13 100644 --- a/src/publishes/app/Http/Kernel.stub +++ b/src/publishes/app/Http/Kernel.stub @@ -2,7 +2,7 @@ namespace App\Http; -use LaraPress\Foundation\Http\Kernel as HttpKernel; +use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel { @@ -14,11 +14,13 @@ class Kernel extends HttpKernel * @var array */ protected $middleware = [ - \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, + // \App\Http\Middleware\TrustHosts::class, + \App\Http\Middleware\TrustProxies::class, + \Fruitcake\Cors\HandleCors::class, + \App\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, \App\Http\Middleware\TrimStrings::class, \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, - \App\Http\Middleware\TrustProxies::class, ]; /** @@ -39,7 +41,7 @@ class Kernel extends HttpKernel 'api' => [ 'throttle:60,1', - 'bindings', + \Illuminate\Routing\Middleware\SubstituteBindings::class, ], ]; @@ -51,11 +53,15 @@ class Kernel extends HttpKernel * @var array */ protected $routeMiddleware = [ - 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, + 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, + 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, + 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, ]; -} \ No newline at end of file +} diff --git a/src/publishes/bootstrap/app.stub b/src/publishes/bootstrap/app.stub index 34ee44f..88bb81a 100644 --- a/src/publishes/bootstrap/app.stub +++ b/src/publishes/bootstrap/app.stub @@ -14,7 +14,7 @@ defined('LARAPRESS_THEME_TEXTDOMAIN') ?: define('LARAPRESS_THEME_TEXTDOMAIN', 'l */ $app = new LaraPress\Foundation\Application( - realpath(__DIR__ . '/..') + $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__) ); /* diff --git a/src/publishes/config/app.stub b/src/publishes/config/app.stub index d723372..1fef6f9 100644 --- a/src/publishes/config/app.stub +++ b/src/publishes/config/app.stub @@ -22,7 +22,7 @@ return [ | | This value determines the "environment" your application is currently | running in. This may determine how you prefer to configure various - | services your application utilizes. Set this in your ".env" file. + | services the application utilizes. Set this in your ".env" file. | */ @@ -39,7 +39,7 @@ return [ | */ - 'debug' => env('APP_DEBUG', false), + 'debug' => (bool) env('APP_DEBUG', false), /* |-------------------------------------------------------------------------- @@ -54,6 +54,8 @@ return [ 'url' => env('APP_URL', 'http://localhost'), + 'asset_url' => env('ASSET_URL', null), + /* |-------------------------------------------------------------------------- | Application Timezone @@ -95,35 +97,31 @@ return [ /* |-------------------------------------------------------------------------- - | Encryption Key + | Faker Locale |-------------------------------------------------------------------------- | - | This key is used by the Illuminate encrypter service and should be set - | to a random, 32 character string, otherwise these encrypted strings - | will not be safe. Please do this before deploying an application! + | This locale will be used by the Faker PHP library when generating fake + | data for your database seeds. For example, this will be used to get + | localized telephone numbers, street address information and more. | */ - 'key' => env('APP_KEY'), - - 'cipher' => 'AES-256-CBC', + 'faker_locale' => 'en_US', /* |-------------------------------------------------------------------------- - | Logging Configuration + | Encryption Key |-------------------------------------------------------------------------- | - | Here you may configure the log settings for your application. Out of - | the box, Laravel uses the Monolog PHP logging library. This gives - | you a variety of powerful log handlers / formatters to utilize. - | - | Available Settings: "single", "daily", "syslog", "errorlog" + | This key is used by the Illuminate encrypter service and should be set + | to a random, 32 character string, otherwise these encrypted strings + | will not be safe. Please do this before deploying an application! | */ - 'log' => env('APP_LOG', 'single'), + 'key' => env('APP_KEY'), - 'log_level' => env('APP_LOG_LEVEL', 'debug'), + 'cipher' => 'AES-256-CBC', /* |-------------------------------------------------------------------------- @@ -164,6 +162,10 @@ return [ Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, + /* + * Package Service Providers... + */ + /* * LaraPress Framework Service Providers */ @@ -211,39 +213,42 @@ return [ 'aliases' => [ - 'App' => Illuminate\Support\Facades\App::class, - 'Artisan' => Illuminate\Support\Facades\Artisan::class, - 'Auth' => Illuminate\Support\Facades\Auth::class, - 'Blade' => Illuminate\Support\Facades\Blade::class, - 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, - 'Bus' => Illuminate\Support\Facades\Bus::class, - 'Cache' => Illuminate\Support\Facades\Cache::class, - 'Config' => Illuminate\Support\Facades\Config::class, - 'Cookie' => Illuminate\Support\Facades\Cookie::class, - 'Crypt' => Illuminate\Support\Facades\Crypt::class, - 'DB' => Illuminate\Support\Facades\DB::class, - 'Eloquent' => Illuminate\Database\Eloquent\Model::class, - 'Event' => Illuminate\Support\Facades\Event::class, - 'File' => Illuminate\Support\Facades\File::class, - 'Gate' => Illuminate\Support\Facades\Gate::class, - 'Hash' => Illuminate\Support\Facades\Hash::class, - 'Lang' => Illuminate\Support\Facades\Lang::class, - 'Log' => Illuminate\Support\Facades\Log::class, - 'Mail' => Illuminate\Support\Facades\Mail::class, + 'App' => Illuminate\Support\Facades\App::class, + 'Arr' => Illuminate\Support\Arr::class, + 'Artisan' => Illuminate\Support\Facades\Artisan::class, + 'Auth' => Illuminate\Support\Facades\Auth::class, + 'Blade' => Illuminate\Support\Facades\Blade::class, + 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, + 'Bus' => Illuminate\Support\Facades\Bus::class, + 'Cache' => Illuminate\Support\Facades\Cache::class, + 'Config' => Illuminate\Support\Facades\Config::class, + 'Cookie' => Illuminate\Support\Facades\Cookie::class, + 'Crypt' => Illuminate\Support\Facades\Crypt::class, + 'DB' => Illuminate\Support\Facades\DB::class, + 'Eloquent' => Illuminate\Database\Eloquent\Model::class, + 'Event' => Illuminate\Support\Facades\Event::class, + 'File' => Illuminate\Support\Facades\File::class, + 'Gate' => Illuminate\Support\Facades\Gate::class, + 'Hash' => Illuminate\Support\Facades\Hash::class, + 'Http' => Illuminate\Support\Facades\Http::class, + 'Lang' => Illuminate\Support\Facades\Lang::class, + 'Log' => Illuminate\Support\Facades\Log::class, + 'Mail' => Illuminate\Support\Facades\Mail::class, 'Notification' => Illuminate\Support\Facades\Notification::class, - 'Password' => Illuminate\Support\Facades\Password::class, - 'Queue' => Illuminate\Support\Facades\Queue::class, - 'Redirect' => Illuminate\Support\Facades\Redirect::class, - 'Redis' => Illuminate\Support\Facades\Redis::class, - 'Request' => Illuminate\Support\Facades\Request::class, - 'Response' => Illuminate\Support\Facades\Response::class, - 'Route' => Illuminate\Support\Facades\Route::class, - 'Schema' => Illuminate\Support\Facades\Schema::class, - 'Session' => Illuminate\Support\Facades\Session::class, - 'Storage' => Illuminate\Support\Facades\Storage::class, - 'URL' => Illuminate\Support\Facades\URL::class, - 'Validator' => Illuminate\Support\Facades\Validator::class, - 'View' => Illuminate\Support\Facades\View::class, + 'Password' => Illuminate\Support\Facades\Password::class, + 'Queue' => Illuminate\Support\Facades\Queue::class, + 'Redirect' => Illuminate\Support\Facades\Redirect::class, + 'Redis' => Illuminate\Support\Facades\Redis::class, + 'Request' => Illuminate\Support\Facades\Request::class, + 'Response' => Illuminate\Support\Facades\Response::class, + 'Route' => Illuminate\Support\Facades\Route::class, + 'Schema' => Illuminate\Support\Facades\Schema::class, + 'Session' => Illuminate\Support\Facades\Session::class, + 'Storage' => Illuminate\Support\Facades\Storage::class, + 'Str' => Illuminate\Support\Str::class, + 'URL' => Illuminate\Support\Facades\URL::class, + 'Validator' => Illuminate\Support\Facades\Validator::class, + 'View' => Illuminate\Support\Facades\View::class, /* LaraPress Facades */ 'Action' => LaraPress\Support\Facades\Action::class, diff --git a/src/publishes/config/mail.stub b/src/publishes/config/mail.stub index 893cb86..9aa2e97 100644 --- a/src/publishes/config/mail.stub +++ b/src/publishes/config/mail.stub @@ -4,46 +4,74 @@ return [ /* |-------------------------------------------------------------------------- - | Mail Driver + | Default Mailer |-------------------------------------------------------------------------- | - | Laravel supports both SMTP and PHP's "mail" function as drivers for the - | sending of e-mail. You may specify which one you're using throughout - | your application here. By default, Laravel is setup for SMTP mail. - | - | Supported: "smtp", "sendmail", "mailgun", "mandrill", "ses", - | "sparkpost", "log", "array" + | This option controls the default mailer that is used to send any email + | messages sent by your application. Alternative mailers may be setup + | and used as needed; however, this mailer will be used by default. | */ - 'driver' => env('MAIL_DRIVER', 'smtp'), + 'default' => env('MAIL_MAILER', 'smtp'), 'override_wordpress' => true, /* |-------------------------------------------------------------------------- - | SMTP Host Address + | Mailer Configurations |-------------------------------------------------------------------------- | - | Here you may provide the host address of the SMTP server used by your - | applications. A default option is provided that is compatible with - | the Mailgun mail service which will provide reliable deliveries. + | Here you may configure all of the mailers used by your application plus + | their respective settings. Several examples have been configured for + | you and you are free to add your own as your application requires. | - */ - - 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), - - /* - |-------------------------------------------------------------------------- - | SMTP Host Port - |-------------------------------------------------------------------------- + | Laravel supports a variety of mail "transport" drivers to be used while + | sending an e-mail. You will specify which one you are using for your + | mailers below. You are free to add additional mailers as required. | - | This is the SMTP port used by your application to deliver e-mails to - | users of the application. Like the host we have set this value to - | stay compatible with the Mailgun e-mail application by default. + | Supported: "smtp", "sendmail", "mailgun", "ses", + | "postmark", "log", "array" | */ - 'port' => env('MAIL_PORT', 587), + 'mailers' => [ + 'smtp' => [ + 'transport' => 'smtp', + 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), + 'port' => env('MAIL_PORT', 587), + 'encryption' => env('MAIL_ENCRYPTION', 'tls'), + 'username' => env('MAIL_USERNAME'), + 'password' => env('MAIL_PASSWORD'), + 'timeout' => null, + 'auth_mode' => null, + ], + + 'ses' => [ + 'transport' => 'ses', + ], + + 'mailgun' => [ + 'transport' => 'mailgun', + ], + + 'postmark' => [ + 'transport' => 'postmark', + ], + + 'sendmail' => [ + 'transport' => 'sendmail', + 'path' => '/usr/sbin/sendmail -bs', + ], + + 'log' => [ + 'transport' => 'log', + 'channel' => env('MAIL_LOG_CHANNEL'), + ], + + 'array' => [ + 'transport' => 'array', + ], + ], /* |-------------------------------------------------------------------------- @@ -61,47 +89,6 @@ return [ 'name' => env('MAIL_FROM_NAME', 'Example'), ], - /* - |-------------------------------------------------------------------------- - | E-Mail Encryption Protocol - |-------------------------------------------------------------------------- - | - | Here you may specify the encryption protocol that should be used when - | the application send e-mail messages. A sensible default using the - | transport layer security protocol should provide great security. - | - */ - - 'encryption' => env('MAIL_ENCRYPTION', 'tls'), - - /* - |-------------------------------------------------------------------------- - | SMTP Server Username - |-------------------------------------------------------------------------- - | - | If your SMTP server requires a username for authentication, you should - | set it here. This will get used to authenticate with your server on - | connection. You may also set the "password" value below this one. - | - */ - - 'username' => env('MAIL_USERNAME'), - - 'password' => env('MAIL_PASSWORD'), - - /* - |-------------------------------------------------------------------------- - | Sendmail System Path - |-------------------------------------------------------------------------- - | - | When using the "sendmail" driver to send e-mails, we will need to know - | the path to where Sendmail lives on this server. A default path has - | been provided here, which will work well on most of your systems. - | - */ - - 'sendmail' => '/usr/sbin/sendmail -bs', - /* |-------------------------------------------------------------------------- | Markdown Mail Settings From b9378563cc8fe61167cd2197b3bca86f10c7e5c6 Mon Sep 17 00:00:00 2001 From: Skyler Fenn Date: Sun, 26 Jul 2020 16:54:40 -0600 Subject: [PATCH 2/4] remove set current screen. This breaks plugins and it doesn't seem necessary --- src/LaraPress/Routing/Router.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/LaraPress/Routing/Router.php b/src/LaraPress/Routing/Router.php index b3a75f4..57bf0da 100644 --- a/src/LaraPress/Routing/Router.php +++ b/src/LaraPress/Routing/Router.php @@ -179,8 +179,6 @@ protected function addAdminMenuPage($uri, Route $route) remove_menu_page($slug); - set_current_screen($slug); - if (count($uri) == 0 && !$parentSlug) { add_menu_page($pageTitle, $menuTitle, $capability, $slug, $response, $icon, $position); } else { From 64b042fc105dcb8b1cc3ce4c031cb137a596e68f Mon Sep 17 00:00:00 2001 From: Skyler Fenn Date: Sun, 26 Jul 2020 22:49:22 -0600 Subject: [PATCH 3/4] Correct regex to match for admin routes. ## Why With Laravel 7, the route matching logic has changed. This change to the replace allows WP Admin routes like `/cms/wp-admin/admin.php?page=calendar&id=12` to match still. https://github.com/laravel/framework/commit/8b134ce09667011dec0269f0cab0de6e6d424c64#diff-6a5d29b23ff8cfe02cf063800251c12bL311 --- src/LaraPress/Routing/Matching/UriValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LaraPress/Routing/Matching/UriValidator.php b/src/LaraPress/Routing/Matching/UriValidator.php index e621d85..a78dc47 100644 --- a/src/LaraPress/Routing/Matching/UriValidator.php +++ b/src/LaraPress/Routing/Matching/UriValidator.php @@ -21,7 +21,7 @@ public function matches(Route $route, Request $request) $regex = $route->getCompiled()->getRegex(); if (str_contains($request->getRequestUri(), '/wp-admin')) { - return preg_match(str_replace('$#s', '(?:&.+)?$#s', $regex), rawurldecode($request->getRequestUri())); + return preg_match(str_replace('$}sDu', '}', $regex), rawurldecode($request->getRequestUri())); } $path = $request->path() == '/' ? '/' : '/' . $request->path(); From bb661011d3598357cb1f9a2b92c9d0027b44dcd4 Mon Sep 17 00:00:00 2001 From: Skyler Fenn Date: Sun, 26 Jul 2020 23:05:01 -0600 Subject: [PATCH 4/4] give a developer friendly error when admin routes aren't found --- src/LaraPress/Foundation/Http/Kernel.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/LaraPress/Foundation/Http/Kernel.php b/src/LaraPress/Foundation/Http/Kernel.php index 4e6415d..23a266a 100644 --- a/src/LaraPress/Foundation/Http/Kernel.php +++ b/src/LaraPress/Foundation/Http/Kernel.php @@ -6,6 +6,7 @@ use Illuminate\Foundation\Http\Kernel as HttpKernel; use Illuminate\Pipeline\Pipeline; use Illuminate\Support\Facades\Facade; +use LaraPress\Routing\Matching\UriValidator; use Symfony\Component\Debug\Exception\FatalThrowableError; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Throwable; @@ -73,7 +74,11 @@ public function handle($request) } catch (Exception $e) { if (is_admin() && $e instanceof NotFoundHttpException) { - $response = null; + $e = new \Exception(sprintf( + 'The LaraPress router could not find this route. Admin routes are matched with the %s class.', + UriValidator::class + )); + $response = $this->renderException($request, $e); } else { $this->reportException($e); $response = $this->renderException($request, $e);