File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
src/josegonzalez/Dotenv/Filter
tests/josegonzalez/Dotenv Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace josegonzalez \Dotenv \Filter ;
4
+
5
+ class UppercaseFirstKeyFilter
6
+ {
7
+ /**
8
+ * Uppercases the first letter for all the keys for an environment to a single-depth.
9
+ *
10
+ * @param array $data Array of environment data
11
+ * @return array
12
+ */
13
+ public function __invoke (array $ environment )
14
+ {
15
+ $ newEnvironment = array ();
16
+ foreach ($ environment as $ key => $ value ) {
17
+ $ newEnvironment [ucfirst ($ key )] = $ value ;
18
+ }
19
+ return $ newEnvironment ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change @@ -281,6 +281,26 @@ public function testNullFilter()
281
281
), $ this ->Loader ->toArray ());
282
282
}
283
283
284
+ /**
285
+ * @covers \josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter::__invoke
286
+ */
287
+ public function testUppercaseFirstKeyFilter ()
288
+ {
289
+ $ this ->Loader ->setFilters (array (
290
+ 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter ' ,
291
+ 'josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter ' ,
292
+ ));
293
+ $ this ->Loader ->setFilepath ($ this ->fixturePath . '.env ' );
294
+ $ this ->Loader ->parse ();
295
+ $ this ->Loader ->filter ();
296
+ $ this ->assertEquals (array (
297
+ 'Foo ' => 'bar ' ,
298
+ 'Bar ' => 'baz ' ,
299
+ 'Spaced ' => 'with spaces ' ,
300
+ 'Equals ' => 'pgsql:host=localhost;dbname=test ' ,
301
+ ), $ this ->Loader ->toArray ());
302
+ }
303
+
284
304
/**
285
305
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke
286
306
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get
You can’t perform that action at this time.
0 commit comments