Skip to content

Commit

Permalink
optional patching
Browse files Browse the repository at this point in the history
  • Loading branch information
EsdertCO committed Aug 29, 2020
1 parent 847188e commit 3088af5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 31 additions & 4 deletions src/Console/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}';

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/cookies/middleware.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);

Expand Down

0 comments on commit 3088af5

Please sign in to comment.