Skip to content

Commit

Permalink
Create UppercaseFirstKeyFilter.php
Browse files Browse the repository at this point in the history
  • Loading branch information
josegonzalez committed Dec 25, 2015
1 parent e67f842 commit 9ad89f3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php
@@ -0,0 +1,21 @@
<?php

namespace josegonzalez\Dotenv\Filter;

class UppercaseFirstKeyFilter
{
/**
* Uppercases the first letter for all the keys for an environment to a single-depth.
*
* @param array $data Array of environment data
* @return array
*/
public function __invoke(array $environment)
{
$newEnvironment = array();
foreach ($environment as $key => $value) {
$newEnvironment[ucfirst($key)] = $value;
}
return $newEnvironment;
}
}
20 changes: 20 additions & 0 deletions tests/josegonzalez/Dotenv/LoaderTest.php
Expand Up @@ -281,6 +281,26 @@ public function testNullFilter()
), $this->Loader->toArray());
}

/**
* @covers \josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter::__invoke
*/
public function testUppercaseFirstKeyFilter()
{
$this->Loader->setFilters(array(
'josegonzalez\Dotenv\Filter\LowercaseKeyFilter',
'josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter',
));
$this->Loader->setFilepath($this->fixturePath . '.env');
$this->Loader->parse();
$this->Loader->filter();
$this->assertEquals(array(
'Foo' => 'bar',
'Bar' => 'baz',
'Spaced' => 'with spaces',
'Equals' => 'pgsql:host=localhost;dbname=test',
), $this->Loader->toArray());
}

/**
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke
* @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get
Expand Down

0 comments on commit 9ad89f3

Please sign in to comment.