-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from agungaprianto/add-settings-interface
add settings interface
- Loading branch information
Showing
8 changed files
with
72 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use App\Application\Settings\Settings; | ||
use App\Application\Settings\SettingsInterface; | ||
use DI\ContainerBuilder; | ||
use Monolog\Logger; | ||
|
||
return function (ContainerBuilder $containerBuilder) { | ||
|
||
// Global Settings Object | ||
$containerBuilder->addDefinitions([ | ||
'settings' => [ | ||
'displayErrorDetails' => true, // Should be set to false in production | ||
'logger' => [ | ||
'name' => 'slim-app', | ||
'path' => isset($_ENV['docker']) ? 'php://stdout' : __DIR__ . '/../logs/app.log', | ||
'level' => Logger::DEBUG, | ||
], | ||
], | ||
SettingsInterface::class => function () { | ||
return new Settings([ | ||
'displayErrorDetails' => true, // Should be set to false in production | ||
'logger' => [ | ||
'name' => 'slim-app', | ||
'path' => isset($_ENV['docker']) ? 'php://stdout' : __DIR__ . '/../logs/app.log', | ||
'level' => Logger::DEBUG, | ||
], | ||
]); | ||
} | ||
]); | ||
}; |
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
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,30 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Application\Settings; | ||
|
||
class Settings implements SettingsInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $settings; | ||
|
||
/** | ||
* Settings constructor. | ||
* @param array $settings | ||
*/ | ||
public function __construct(array $settings) | ||
{ | ||
$this->settings = $settings; | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function get(string $key = '') | ||
{ | ||
return (empty($key)) ? $this->settings : $this->settings[$key]; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Application\Settings; | ||
|
||
interface SettingsInterface | ||
{ | ||
/** | ||
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function get(string $key = ''); | ||
} |
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