-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace PHLAK\Config\Loaders; | ||
|
||
use PHLAK\Config\Exceptions\InvalidFileException; | ||
use Yosymfony\Toml\Toml as TomlParser; | ||
use Yosymfony\Toml\Exception\ParseException; | ||
|
||
class Toml extends Loader | ||
{ | ||
/** | ||
* Retrieve the contents of a .toml file and convert it to an array of | ||
* configuration options. | ||
* | ||
* @return array Array of configuration options | ||
*/ | ||
public function getArray() | ||
{ | ||
try { | ||
$parsed = TomlParser::ParseFile($this->context); | ||
} catch (ParseException $e) { | ||
throw new InvalidFileException($e->getMessage()); | ||
} | ||
|
||
// if (! is_array($parsed)) { | ||
// throw new InvalidFileException('Unable to parse invalid TOML file at ' . $this->context); | ||
// } | ||
|
||
return $parsed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace PHLAK\Config\Tests; | ||
|
||
use PHLAK\Config\Config; | ||
use PHLAK\Config\Exceptions\InvalidFileException; | ||
use PHLAK\Config\Tests\Traits\Initializable; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TomlTest extends TestCase | ||
{ | ||
use Initializable; | ||
|
||
public function setUp() | ||
{ | ||
$this->validConfig = __DIR__ . '/files/toml/config.toml'; | ||
$this->invalidConfig = __DIR__ . '/files/toml/invalid.toml'; | ||
} | ||
|
||
public function test_it_throws_an_exception_when_initializing_a_toml_file_without_an_array() | ||
{ | ||
$this->expectException(InvalidFileException::class); | ||
|
||
new Config(__DIR__ . '/files/toml/bad.toml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I'm a valid YAML file but don't contain an array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
driver = 'mysql' | ||
|
||
[drivers.sqlite] | ||
database = 'database.sqlite' | ||
prefix = '' | ||
|
||
[drivers.mysql] | ||
host = 'localhost' | ||
database = 'blog' | ||
username = 'blogger' | ||
password = 'hunter2' | ||
charset = 'utf8' | ||
prefix = '' | ||
|
||
[drivers.pgsql] | ||
host = 'localhost' | ||
database = 'blog' | ||
username = 'blogger' | ||
password = 'hunter2' | ||
charset = 'utf8' | ||
prefix = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
asdf: asdf: asdf |