-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Refactor ConfigGenerator to replace/set crypt key instead of append #11155
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
13daa74
Refactor ConfigGenerator to replace crypt key instead of append
renttek f50ad05
Change visibility of configDataFactory-member to private
renttek 4f3e981
Remove unnecessary/old comments
renttek 2718be3
Make ConfigDataFactory-parameter optional
renttek b517623
Refactoring of createCryptConfig
renttek 345a7f3
Introduce CryptKeyGgeneratorInterface
renttek ae06955
Remove/refactor chained null coalescing operator
renttek 43e9751
Make 'Random' optional
renttek 4b748cf
Fix Unit/Module/ConfigGeneratorTest for Setup
renttek 010097d
Refactor createCacheHostsConfig
renttek 2316cd8
Reformat some code to make it consistent
renttek c7ca261
Reformat the big array on the top
renttek eb33d60
Shorten some function calls in createDbConfig
renttek 61d9767
Remove list() to fix some tests
renttek aec956f
Put "random" parameter back in ConfigGenerator
renttek e440946
Make "random" required CryptKeyGenerator
renttek 885ecf8
Add random as constructor param in test
renttek 91ee875
Assign deprecated random parameter to property
renttek 3faf8b5
Add type hints for new interface and impementation
renttek 1fd5b0e
Add type hint for ConfigDataFactory->create()
renttek a2ae382
Add some type hints
renttek c868fa2
Add a empty string return to satisfy return hints
renttek d78ae56
Add ObjectManager to ConfigDataFactory
renttek b2146db
Refactor test after modifying factory
renttek bab5e31
Fix issues of static code checks
renttek c638fd7
Suppress warnings of long var names in testcases
renttek 62eff1d
Remove type hints and @api annotation
renttek 58aab5e
Some more fixes for static analysis
renttek e8fe7ed
Remove @SuppressWarning annotations form tests
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
42 changes: 42 additions & 0 deletions
42
lib/internal/Magento/Framework/Config/Data/ConfigDataFactory.php
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,42 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Config\Data; | ||
|
||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\ObjectManagerInterface; | ||
|
||
/** | ||
* Factory for ConfigData | ||
*/ | ||
class ConfigDataFactory | ||
{ | ||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* Factory constructor | ||
* | ||
* @param ObjectManagerInterface $objectManager | ||
*/ | ||
public function __construct(ObjectManagerInterface $objectManager) | ||
{ | ||
$this->objectManager = $objectManager; | ||
} | ||
|
||
/** | ||
* Returns a new instance of ConfigData on every call. | ||
* | ||
* @param string $fileKey | ||
* @return ConfigData | ||
*/ | ||
public function create($fileKey) | ||
{ | ||
return $this->objectManager->create(ConfigData::class, ['fileKey' => $fileKey]); | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Setup\Model; | ||
|
||
use Magento\Framework\Config\ConfigOptionsListConstants; | ||
use Magento\Framework\Math\Random; | ||
|
||
/** | ||
* Generates a crypt | ||
*/ | ||
class CryptKeyGenerator implements CryptKeyGeneratorInterface | ||
{ | ||
/** | ||
* @var Random | ||
*/ | ||
private $random; | ||
|
||
/** | ||
* CryptKeyGenerator constructor. | ||
* | ||
* @param Random $random | ||
*/ | ||
public function __construct(Random $random) | ||
{ | ||
$this->random = $random; | ||
} | ||
|
||
/** | ||
* Generates & returns a string to be used as crypt key. | ||
* | ||
* The key length is not a parameter, but an implementation detail. | ||
* | ||
* @return string | ||
* | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function generate() | ||
{ | ||
return md5($this->getRandomString()); | ||
} | ||
|
||
/** | ||
* Returns a random string. | ||
* | ||
* @return string | ||
*/ | ||
private function getRandomString() | ||
{ | ||
return $this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
setup/src/Magento/Setup/Model/CryptKeyGeneratorInterface.php
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,22 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Setup\Model; | ||
|
||
/** | ||
* Interface for crypt key generators. | ||
*/ | ||
interface CryptKeyGeneratorInterface | ||
{ | ||
/** | ||
* Generates & returns a string to be used as crypt key. | ||
* | ||
* The key length is not a parameter, but an implementation detail. | ||
* | ||
* @return string | ||
*/ | ||
public function generate(); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work, good to see this being moved out to a factory.