-
-
Notifications
You must be signed in to change notification settings - Fork 33
[Enhancement] Add ArrayFile & EnvFile Parsing, replace ConfigWriter internal logic #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
108 commits
Select commit
Hold shift + click to select a range
4c71911
Required nikic/php-parser
jaxwilko dd20a56
Added custom pretty printer for winter style configs
jaxwilko 00020fa
Added ConfigFile class for modifying configs
jaxwilko 0707951
Added class doc block
jaxwilko 45aadb7
Added doc blocks and applyed Winter code styling
jaxwilko eb76cc4
Removed debug code
jaxwilko 0d4b2e2
Added method to retrieve ast
jaxwilko 179af7c
Added ConfigFile tests
jaxwilko d75b3a8
Added additional handling for object types
jaxwilko 524561f
Added fix so single line comments do not recieve nl padding
jaxwilko 3520e88
Added array input and casting tests
jaxwilko 09eff7b
Added type casting functionality
jaxwilko 7156fec
Added env default update test
jaxwilko 4e98e46
Switched to replace nodes rather than update in place for simplicity
jaxwilko ec8d643
Added doc block for makeAstNode method
jaxwilko d3f97e1
Cleaned up switch statment
jaxwilko 31c405a
Update src/Config/ConfigFile.php
jaxwilko 581e616
Update src/Config/ConfigFile.php
jaxwilko 9904d7c
Update src/Config/ConfigFile.php
jaxwilko 6859072
Update src/Config/ConfigFile.php
jaxwilko c097187
Added descriptive comments
jaxwilko 418d6cd
Added fixes to set method to ensure types are correctly updated
jaxwilko b2fac15
Updated dot notation comment
jaxwilko 7745ad1
Added interface for config file modifiers
jaxwilko 96dba39
Added interface to ConfigFile class
jaxwilko d475c2c
Added EnvFile class and tests
jaxwilko 7fe60cc
Removed File class usage in favour of file_put_contents
jaxwilko bbae058
Commented out return types
jaxwilko f74b15a
Removed redundent line
jaxwilko d58411d
Added test comments
jaxwilko a8cf24e
Switched parser for simple interpreter
jaxwilko b0a9c70
Fixed styling issue and unparenthesized ternary issue
jaxwilko 14fd3c8
Improved EnvFile tests
jaxwilko cc439eb
Improved parsing and rendering
jaxwilko 71765a8
Added support for creating file on read and appending items to empty …
jaxwilko 7d8090a
Added constructor to enable short syntax
jaxwilko 69cd152
Added tests for recursive array creation
jaxwilko ce8f252
Added support for recursive array creation using dot notation
jaxwilko ba5ed71
Added ConfigFunction class
jaxwilko 7787df1
Added tests for adding new functions to a config
jaxwilko 51ef587
Added support for setting function calls
jaxwilko 4c421b9
Added proper class doc
jaxwilko b25b8cd
Improved function value type handling
jaxwilko 0581fc6
Added test for null insertion
jaxwilko a010a9c
Added support for null inserts
jaxwilko f9aedbe
Added double quote escaping
jaxwilko cdbf2f4
Merge branch 'develop' into wip/config-writer-replacement
jaxwilko 57a649a
Updated ApplicationExceptions to SystemExceptions
jaxwilko cda726f
Updated test to match the correct exception
jaxwilko dcef6b1
Added support for setting env() args to correct types
jaxwilko bae73fa
Added config sort tests
jaxwilko f0c9454
Added sort() method for ConfigFile
jaxwilko 110afdf
Simplified internal sorting methods
jaxwilko bf6c16e
Fixed test to be consitant across php versions (RFC: stable_sorting)
jaxwilko 4f4a00a
Switched line ending to unix style when creating empty file
jaxwilko 715abd7
Switched line ending for rendered output
jaxwilko 2532b67
Switched heredoc test samples for quoted strings
jaxwilko 1db7bfc
Removed incorrect newline at end of expected results
jaxwilko 36a4044
Reverted to heredoc and removed carriage returns from expected samples
jaxwilko 45e3058
Removed usage of PHP_EOL in favour of lf
jaxwilko 29efd28
Added class to represent const expressions
jaxwilko 87d2d9c
Fixed incorrect comment
jaxwilko 1406191
Added tests for setting arrays and const values
jaxwilko 0caba9d
Fixed incorrect method description comment
jaxwilko 1ca70f3
Added support for setting an array and const value
jaxwilko 4314dfe
Simplified key insertion logic
jaxwilko f60a0ff
Added test for numeric array keys
jaxwilko 29067a8
Fixed spelling mistake
jaxwilko c2a0aa2
Swapped out redundent if statement for assigning result of expression
jaxwilko 4f19150
Merge 1.2 into config-writer-replacement
LukeTowers 2d64825
Move config writer into Parse
LukeTowers 7c9c63b
Move ArrayFile tests out of config and into parse
LukeTowers 6f6d073
Various cleanup and code review
LukeTowers 4f43d6c
Fix test name mismatch
LukeTowers f4da8f6
PHPConst -> PHPConstant
LukeTowers 9ea747c
FileInterface -> DataFileInterface, read() -> open()
LukeTowers 5643d4d
Require PHP Codesniffer > 3.2
LukeTowers 5cfe40d
Switch back to Laravel's default logic for setting application keys
LukeTowers 57eafe4
const() -> constant()
LukeTowers 9c0057c
Improvements to the EnvFile parser
LukeTowers 5b186ac
Use Str facade instead of helper functions
LukeTowers a9fa826
Cleanup docblocks
LukeTowers 74ca4d8
Fix tests, add test case for $throwIfMissing
LukeTowers f12c2b9
Refactor ConfigWriter to use ArrayFile parser internally
LukeTowers 4a036ea
Added config test fixtures
jaxwilko ec04043
Added support for leading imports & expressions before a return stmt
jaxwilko f74bd5a
Manual merge wip/1.2 into wip/config-writer-replacement
jaxwilko 0ec5553
Moved fixtures into arrayfile dir
jaxwilko 440e1fb
Added include test to ensure parens on correct include stmts
jaxwilko c098853
Added code to check include position in ast and append parens correctly
jaxwilko 892ed2a
Simplified code by always apending parens on include/require stmts
jaxwilko cf98dcf
Merge branch 'wip/1.2' into wip/config-writer-replacement
LukeTowers 9fda6cd
Trim useless whitespace
LukeTowers 91f1dac
Added fixes for whitespace issues
jaxwilko 78bcf11
Bound lexer to ArrayFile instance
jaxwilko 573e606
Added support for lexer token parsing and additional comment handling
jaxwilko 6ee5ec3
Added non-attribute comment handling test
jaxwilko 725fb4d
Added style fixes
jaxwilko 6e0ddb3
More styling fixes in test fixture
jaxwilko 7e56951
Added fix to ConfigWriter to support passing lexer to ArrayFile instance
jaxwilko 62950e0
Added \r trim to comment test
jaxwilko 5ca79e7
Update src/Foundation/Console/KeyGenerateCommand.php
bennothommo d14374d
KeyGenerateCommand cleanup
LukeTowers b0e7b4f
Code dusting and explicit typing from review
bennothommo e6c8434
Added subitem comment test
jaxwilko 4899679
Added fix for subitems being picked up in lexer tokens
jaxwilko e15806d
Merge branch 'wip/config-writer-replacement' of github.com:wintercms/…
jaxwilko c7a5f6a
Added fix for token parsing running into comma tokens and breaking
jaxwilko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,82 +1,48 @@ | ||
| <?php namespace Winter\Storm\Foundation\Console; | ||
|
|
||
| use Illuminate\Filesystem\Filesystem; | ||
| use Illuminate\Foundation\Console\KeyGenerateCommand as KeyGenerateCommandBase; | ||
| use Winter\Storm\Parse\EnvFile; | ||
|
|
||
| class KeyGenerateCommand extends KeyGenerateCommandBase | ||
| { | ||
| /** | ||
| * Create a new key generator command. | ||
| * Write a new environment file with the given key. | ||
| * | ||
| * @param \Illuminate\Filesystem\Filesystem $files | ||
| * @param string $key | ||
| * @return void | ||
| */ | ||
| public function __construct(Filesystem $files) | ||
| protected function writeNewEnvironmentFileWith($key) | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| $this->files = $files; | ||
| $env = EnvFile::open($this->laravel->environmentFilePath()); | ||
| $env->set('APP_KEY', $key); | ||
| $env->write(); | ||
| } | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| * Confirm before proceeding with the action. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function handle() | ||
| { | ||
| $key = $this->generateRandomKey(); | ||
|
|
||
| if ($this->option('show')) { | ||
| return $this->line('<comment>'.$key.'</comment>'); | ||
| } | ||
|
|
||
| // Next, we will replace the application key in the config file so it is | ||
| // automatically setup for this developer. This key gets generated using a | ||
| // secure random byte generator and is later base64 encoded for storage. | ||
| if (!$this->setKeyInConfigFile($key)) { | ||
| return; | ||
| } | ||
|
|
||
| $this->laravel['config']['app.key'] = $key; | ||
|
|
||
| $this->info("Application key [$key] set successfully."); | ||
| } | ||
|
|
||
| /** | ||
| * Set the application key in the config file. | ||
| * This method only asks for confirmation in production. | ||
| * | ||
| * @param string $key | ||
| * @param string $warning | ||
| * @param \Closure|bool|null $callback | ||
| * @return bool | ||
| */ | ||
| protected function setKeyInConfigFile($key) | ||
| public function confirmToProceed($warning = 'Application In Production!', $callback = null) | ||
| { | ||
| if (!$this->confirmToProceed()) { | ||
| return false; | ||
| if ($this->hasOption('force') && $this->option('force')) { | ||
| return true; | ||
| } | ||
|
|
||
| $currentKey = $this->laravel['config']['app.key']; | ||
| $this->alert('An application key is already set!'); | ||
|
|
||
| list($path, $contents) = $this->getKeyFile(); | ||
| $confirmed = $this->confirm('Do you really wish to run this command?'); | ||
|
|
||
| $contents = str_replace($currentKey, $key, $contents); | ||
| if (!$confirmed) { | ||
| $this->comment('Command Canceled!'); | ||
|
|
||
| $this->files->put($path, $contents); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Get the key file and contents. | ||
| * | ||
| * @return array | ||
| */ | ||
| protected function getKeyFile() | ||
| { | ||
| $env = $this->option('env') ? $this->option('env').'/' : ''; | ||
|
|
||
| $contents = $this->files->get($path = $this->laravel['path.config']."/{$env}app.php"); | ||
|
|
||
| return [$path, $contents]; | ||
| } | ||
| } | ||
This file contains hidden or 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,24 @@ | ||
| <?php namespace Winter\Storm\Parse\Contracts; | ||
|
|
||
| interface DataFileInterface | ||
| { | ||
| /** | ||
| * Return a new instance of `DataFileInterface` ready for modification of the provided filepath. | ||
| */ | ||
| public static function open(string $filePath): static; | ||
|
|
||
| /** | ||
| * Set a property within the data. | ||
| */ | ||
| public function set(string|array $key, $value = null): static; | ||
|
|
||
| /** | ||
| * Write the current data to a file | ||
| */ | ||
| public function write(?string $filePath = null): void; | ||
|
|
||
| /** | ||
| * Get the printed data | ||
| */ | ||
| public function render(): string; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.