diff --git a/README.md b/README.md index 7277904..b22e17e 100644 --- a/README.md +++ b/README.md @@ -81,14 +81,20 @@ or add the following to your composer.json file and run `composer update`. Patch some basic things you might not like about laravel. Supports the patching of the following things: - - Language tags + - Language - Replaces a language tag with another language tag for all languages. - Htaccess - Adds security things to the default htaccess. See the config for the options. - - Cookies + - Cookie - Adds a prefix to the cookies. - Config - Replace config values. + ##### Arguments + - Sections - An array of sections to patch. The allowed sections are: + - language + - htaccess + - cookie + - config #### Publish - ##### publish:config diff --git a/src/Console/Patch.php b/src/Console/Patch.php index 3f8d16e..95415f2 100644 --- a/src/Console/Patch.php +++ b/src/Console/Patch.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Str; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; class Patch extends Command @@ -26,6 +27,7 @@ class Patch extends Command protected $description = 'Patch laravel'; protected $signature = 'patch + {sections?* : Only run specific sections of the patch} {--f|force : Overwrite any existing files}'; /** @@ -39,16 +41,34 @@ public function handle() Before doing so please check your config and read the documentation on patching.'); if ($start) { - $this->handleLanguagePatching(); - $this->handleConfigPatching(); - $this->handleCookiePatching(); - $this->handleHtaccessPatching(); + if ($this->shouldRun('language')) { + $this->handleLanguagePatching(); + } + if ($this->shouldRun('config')) { + $this->handleConfigPatching(); + } + if ($this->shouldRun('cookie')) { + $this->handleCookiePatching(); + } + if ($this->shouldRun('htaccess')) { + $this->handleHtaccessPatching(); + } $this->info('Successfully patched Laravel :)'); $this->info('Please make sure to always validate the patches done.'); } } + private function shouldRun($name) + { + if (empty($this->argument('sections')) || + \in_array($name, $this->argument('sections'))) { + return true; + } + + return false; + } + private function handleLanguagePatching() { foreach (\config('laravel-stubs.patch.language_tags') as $tag => $replacement) { @@ -222,6 +242,13 @@ private function creatDirectoryAndSaveFile($path, $content, $name) } } + protected function getArguments() + { + return [ + ['sections', InputArgument::IS_ARRAY, 'Only run specific sections of the patch'], + ]; + } + protected function getOptions() { return [ diff --git a/src/stubs/cookies/middleware.stub b/src/stubs/cookies/middleware.stub index 1ba85b9..b567243 100644 --- a/src/stubs/cookies/middleware.stub +++ b/src/stubs/cookies/middleware.stub @@ -33,7 +33,7 @@ $response->headers->setCookie( new Cookie( config('session.cookie_prefix').'XSRF-TOKEN', $request->session()->token(), $this->availableAt(60 * $config['lifetime']), - $config['path'], $config['domain'], $config['secure'], false, false, $config['same_site'] ?? null + $config['path'], $config['domain'], $config['secure'], true, false, $config['same_site'] ?? null ) );