forked from magento/magento2-functional-testing-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimary.php
82 lines (77 loc) · 2.62 KB
/
Primary.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Config\FileResolver;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Util\Iterator\File;
use Magento\FunctionalTestingFramework\Config\FileResolverInterface;
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
/**
* Provides the list of global configuration files.
*
* @internal
*/
class Primary implements FileResolverInterface
{
/**
* Retrieve the configuration files with given name that relate to configuration
*
* @param string $filename
* @param string $scope
* @return array
*/
public function get($filename, $scope)
{
if (!$filename) {
return [];
}
$scope = str_replace('\\', DIRECTORY_SEPARATOR, $scope);
return new File($this->getFilePaths($filename, $scope));
}
/**
* Get list of configuration files
*
* @param string $filename
* @param string $scope
* @return array
*/
private function getFilePaths($filename, $scope)
{
$paths = [];
foreach ($this->getPathPatterns($filename, $scope) as $pattern) {
$paths = array_merge($paths, glob($pattern));
}
return array_combine($paths, $paths);
}
/**
* Retrieve patterns for glob function
*
* @param string $filename
* @param string $scope
* @return array
* @throws TestFrameworkException
*/
private function getPathPatterns($filename, $scope)
{
if (substr($scope, 0, strlen(FW_BP)) === FW_BP) {
$patterns = [
$scope . DIRECTORY_SEPARATOR . $filename,
$scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $filename
];
} else {
$defaultPath = dirname(dirname(dirname(dirname(__DIR__))));
$defaultPath = str_replace('\\', DIRECTORY_SEPARATOR, $defaultPath);
$patterns = [
$defaultPath . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . $filename,
$defaultPath . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR
. $filename,
FilePathFormatter::format(FW_BP) . $scope . DIRECTORY_SEPARATOR . $filename,
FilePathFormatter::format(FW_BP) . $scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR
. $filename
];
}
return str_replace(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $patterns);
}
}