Skip to content

Commit eafd9ac

Browse files
committed
Merge pull request #23 from josegonzalez/josegonzalez-patch-1
Create UppercaseFirstKeyFilter.php
2 parents e67f842 + 9ad89f3 commit eafd9ac

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

tests/josegonzalez/Dotenv/LoaderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,26 @@ public function testNullFilter()
281281
), $this->Loader->toArray());
282282
}
283283

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+
284304
/**
285305
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke
286306
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get

0 commit comments

Comments
 (0)