forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into MAGETWO-52577
- Loading branch information
Showing
78 changed files
with
2,892 additions
and
522 deletions.
There are no files selected for viewing
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
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
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
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,80 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Config\Model\Config\Parser; | ||
|
||
use Magento\Config\Model\Placeholder\Environment; | ||
use Magento\Config\Model\Placeholder\PlaceholderInterface; | ||
use Magento\Framework\App\Config\CommentParserInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Exception\FileSystemException; | ||
use Magento\Framework\Filesystem; | ||
|
||
/** | ||
* Class Comment. It is used to parse config paths from comment section. | ||
*/ | ||
class Comment implements CommentParserInterface | ||
{ | ||
/** | ||
* @var Filesystem | ||
*/ | ||
private $filesystem; | ||
|
||
/** | ||
* @var PlaceholderInterface | ||
*/ | ||
private $placeholder; | ||
|
||
/** | ||
* @param Filesystem $filesystem | ||
* @param PlaceholderInterface $placeholder | ||
*/ | ||
public function __construct( | ||
Filesystem $filesystem, | ||
PlaceholderInterface $placeholder | ||
) { | ||
$this->filesystem = $filesystem; | ||
$this->placeholder = $placeholder; | ||
} | ||
|
||
/** | ||
* Retrieves config paths from comment section of the file. | ||
* Example of comment: | ||
* * CONFIG__DEFAULT__SOME__CONF__PATH_ONE | ||
* * CONFIG__DEFAULT__SOME__CONF__PATH_TWO | ||
* This method will return: | ||
* array( | ||
* 'CONFIG__DEFAULT__SOME__CONF__PATH_ONE' => 'some/conf/path_one', | ||
* 'CONFIG__DEFAULT__SOME__CONF__PATH_TWO' => 'some/conf/path_two' | ||
* ); | ||
* | ||
* @param string $fileName | ||
* @return array | ||
* @throws FileSystemException | ||
*/ | ||
public function execute($fileName) | ||
{ | ||
$fileContent = $this->filesystem | ||
->getDirectoryRead(DirectoryList::CONFIG) | ||
->readFile($fileName); | ||
|
||
$pattern = sprintf('/\s+\*\s+(?P<placeholder>%s.*?)\s/', preg_quote(Environment::PREFIX)); | ||
preg_match_all($pattern, $fileContent, $matches); | ||
|
||
if (!isset($matches['placeholder'])) { | ||
return []; | ||
} | ||
|
||
$configs = []; | ||
foreach ($matches['placeholder'] as $placeholder) { | ||
$path = $this->placeholder->restore($placeholder); | ||
$path = preg_replace('/^' . ScopeConfigInterface::SCOPE_TYPE_DEFAULT . '\//', '', $path); | ||
$configs[$placeholder] = $path; | ||
} | ||
|
||
return $configs; | ||
} | ||
} |
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
80 changes: 80 additions & 0 deletions
80
app/code/Magento/Config/Test/Unit/Model/Config/Parser/CommentTest.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,80 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Config\Test\Unit\Model\Config\Parser; | ||
|
||
use Magento\Config\Model\Config\Parser\Comment; | ||
use Magento\Config\Model\Placeholder\PlaceholderInterface; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Filesystem; | ||
use Magento\Framework\Filesystem\Directory\ReadInterface; | ||
use PHPUnit_Framework_MockObject_MockObject as MockObject; | ||
|
||
class CommentTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var PlaceholderInterface|MockObject | ||
*/ | ||
private $placeholderMock; | ||
|
||
/** | ||
* @var Filesystem|MockObject | ||
*/ | ||
private $fileSystemMock; | ||
|
||
/** | ||
* @var Comment | ||
*/ | ||
private $model; | ||
|
||
protected function setUp() | ||
{ | ||
$this->placeholderMock = $this->getMockBuilder(PlaceholderInterface::class) | ||
->disableOriginalConstructor() | ||
->getMockForAbstractClass(); | ||
$this->fileSystemMock = $this->getMockBuilder(Filesystem::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->model = new Comment( | ||
$this->fileSystemMock, | ||
$this->placeholderMock | ||
); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$fileName = 'config.local.php'; | ||
$directoryReadMock = $this->getMockBuilder(ReadInterface::class) | ||
->disableOriginalConstructor() | ||
->getMockForAbstractClass(); | ||
$directoryReadMock->expects($this->once()) | ||
->method('readFile') | ||
->with($fileName) | ||
->willReturn(file_get_contents(__DIR__ . '/../_files/' . $fileName)); | ||
$this->fileSystemMock->expects($this->once()) | ||
->method('getDirectoryRead') | ||
->with(DirectoryList::CONFIG) | ||
->willReturn($directoryReadMock); | ||
$this->placeholderMock->expects($this->any()) | ||
->method('restore') | ||
->withConsecutive( | ||
['CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD'], | ||
['CONFIG__DEFAULT__SOME__PAYMENT__TOKEN'] | ||
) | ||
->willReturnOnConsecutiveCalls( | ||
'some/payment/password', | ||
'some/payment/token' | ||
); | ||
|
||
$this->assertEquals( | ||
$this->model->execute($fileName), | ||
[ | ||
'CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD' => 'some/payment/password', | ||
'CONFIG__DEFAULT__SOME__PAYMENT__TOKEN' => 'some/payment/token' | ||
] | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/code/Magento/Config/Test/Unit/Model/Config/_files/config.local.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,24 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
return [ | ||
'scopes' => [ | ||
'websites' => [ | ||
'admin' => [ | ||
'website_id' => '0' | ||
], | ||
], | ||
], | ||
/** | ||
* The configuration file doesn't contain sensitive data for security reasons. | ||
* Sensitive data can be stored in the following environment variables: | ||
* CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD for some/payment/password | ||
*/ | ||
'system' => [] | ||
/** | ||
* CONFIG__DEFAULT__SOME__PAYMENT__TOKEN for some/payment/token | ||
* test phrase CONFIG__DEFAULT__SOME__PAYMENT__TOKEN for some/payment/token | ||
*/ | ||
]; |
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
68 changes: 68 additions & 0 deletions
68
app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/CollectorFactory.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,68 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Deploy\Console\Command\App\SensitiveConfigSet; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\ObjectManagerInterface; | ||
|
||
/** | ||
* Class CollectorFactory creates instance of CollectorInterface. | ||
*/ | ||
class CollectorFactory | ||
{ | ||
/**#@+ | ||
* Constant for collector types. | ||
*/ | ||
const TYPE_INTERACTIVE = 'interactive'; | ||
const TYPE_SIMPLE = 'simple'; | ||
/**#@-*/ | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $types; | ||
|
||
/** | ||
* @param ObjectManagerInterface $objectManager | ||
* @param array $types | ||
*/ | ||
public function __construct( | ||
ObjectManagerInterface $objectManager, | ||
array $types = [] | ||
) { | ||
$this->objectManager = $objectManager; | ||
$this->types = $types; | ||
} | ||
|
||
/** | ||
* Create instance of CollectorInterface by given type. | ||
* | ||
* @param string $type | ||
* @return CollectorInterface | ||
* @throws LocalizedException If collector type not exist in registered types array. | ||
*/ | ||
public function create($type) | ||
{ | ||
if (!isset($this->types[$type])) { | ||
throw new LocalizedException(__('Class for type "%1" was not declared', $type)); | ||
} | ||
|
||
$object = $this->objectManager->create($this->types[$type]); | ||
|
||
if (!$object instanceof CollectorInterface) { | ||
throw new LocalizedException( | ||
__('%1 does not implement %2', get_class($object), CollectorInterface::class) | ||
); | ||
} | ||
|
||
return $object; | ||
} | ||
} |
Oops, something went wrong.