These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | require 'vendor/autoload.php'; |
||
4 | |||
5 | use micmania1\config\ConfigCollection; |
||
6 | use micmania1\config\Transformer\YamlTransformer; |
||
7 | use micmania1\config\Transformer\PrivateStaticTransformer; |
||
8 | use Symfony\Component\Finder\Finder; |
||
9 | |||
10 | // First thing we do is create our empty config collection |
||
11 | $collection = new ConfigCollection; |
||
12 | |||
13 | // Setup Private static transformer and pass in our collection |
||
14 | $classes = ['MyClass', 'MyOtherClass']; |
||
15 | $privateStatics = new PrivateStaticTransformer($classes, $collection); |
||
16 | |||
17 | // Setup the finder to go fetch our yaml files |
||
18 | $finder = new Finder(); |
||
19 | $finder->in('/path/to/site/*/_config') |
||
20 | ->files() |
||
21 | ->name('/\.(yml|yaml)$/'); |
||
22 | |||
23 | // Pass the finder in to your yaml transformer along with our collection |
||
24 | $yaml = new YamlTransformer('/path/to/site', $finder, $collection); |
||
25 | |||
26 | // Add some rules for only/except statements |
||
27 | $yaml->addRule('classexists', function($class) { |
||
28 | return class_exists($class); |
||
29 | }); |
||
30 | $yaml->addRule('envvarset', function($var) { |
||
31 | return getenv($var) !== FALSE; |
||
32 | }); |
||
33 | $yaml->addRule('constantdefined', function($const) { |
||
34 | return defined($const); |
||
35 | }); |
||
36 | |||
37 | // Now we do the transformation in the order of lower priority first |
||
38 | $privateStatics->transform(); |
||
39 | $yaml->transform(); |
||
40 | |||
41 | // Now our config collection has is a list of merged config items |
||
42 | var_dump($collection->all()); |
||
0 ignored issues
–
show
Security
Debugging Code
introduced
by
![]() |
|||
43 | var_dump($collection->keys()); |
||
44 | var_dump($collection->exists('configKey')); |
||
45 | var_dump($collection->get('configKey')); |
||
46 | var_dump($collection->get('configKey')->getValue()); |
||
47 | var_dump($collection->get('configKey')->getMetaData()); |
||
48 | var_dump($collection->get('configKey')->getHistory()); |
||
49 |