This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
ExpressiveConfigInjector.php
98 lines (84 loc) · 2.6 KB
/
ExpressiveConfigInjector.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* @see https://github.com/zendframework/zend-component-installer for the canonical source repository
* @copyright Copyright (c) 2016-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-component-installer/blob/master/LICENSE.md New BSD License
*/
namespace Zend\ComponentInstaller\Injector;
use Zend\ComponentInstaller\ConfigDiscovery\ExpressiveConfig as ExpressiveConfigDiscovery;
use function preg_quote;
use function sprintf;
class ExpressiveConfigInjector extends AbstractInjector
{
use ConditionalDiscoveryTrait;
const DEFAULT_CONFIG_FILE = 'config/config.php';
/**
* {@inheritDoc}
*/
protected $allowedTypes = [
self::TYPE_CONFIG_PROVIDER,
];
/**
* Configuration file to update.
*
* @var string
*/
protected $configFile = self::DEFAULT_CONFIG_FILE;
/**
* Discovery class, for testing if this injector is valid for the given
* configuration.
*
* @var string
*/
protected $discoveryClass = ExpressiveConfigDiscovery::class;
/**
* Patterns and replacements to use when registering a code item.
*
* Pattern is set in constructor due to PCRE quoting issues.
*
* @var string[]
*/
protected $injectionPatterns = [
self::TYPE_CONFIG_PROVIDER => [
'pattern' => '',
'replacement' => "\$1\n %s::class,",
],
];
/**
* Pattern to use to determine if the code item is registered.
*
* Set in constructor due to PCRE quoting issues.
*
* @var string
*/
protected $isRegisteredPattern = '';
/**
* Patterns and replacements to use when removing a code item.
*
* @var string[]
*/
protected $removalPatterns = [
'pattern' => '/^\s+%s::class,\s*$/m',
'replacement' => '',
];
/**
* {@inheritDoc}
*
* Sets $isRegisteredPattern and pattern for $injectionPatterns to ensure
* proper PCRE quoting.
*/
public function __construct($projectRoot = '')
{
$this->isRegisteredPattern = '/new (?:'
. preg_quote('\\')
. '?'
. preg_quote('Zend\Expressive\ConfigManager\\')
. ')?ConfigManager\(\s*(?:array\(|\[).*\s+%s::class/s';
$this->injectionPatterns[self::TYPE_CONFIG_PROVIDER]['pattern'] = sprintf(
'/(new (?:%s?%s)?ConfigManager\(\s*(?:array\(|\[)\s*)$/m',
preg_quote('\\'),
preg_quote('Zend\Expressive\ConfigManager\\')
);
parent::__construct($projectRoot);
}
}