Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/Configuration/EnvConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ class EnvConfiguration extends Configuration
*/
public function create(Loader $config): void
{
$this->container->bind('env', function () use ($config) {
Env::configure($config['app.env_file'] ?? null);
Env::configure($config->getPath('.env.json') ?? null);

$event = Env::getInstance();
$event = Env::getInstance();

$this->container->instance('env', $event);
});
$this->container->instance('env', $event);
}

/**
* @inheritdoc
*/
public function run(): void
{
// $this->container->make('env');
//
}
}
38 changes: 33 additions & 5 deletions src/Configuration/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Loader implements ArrayAccess
*/
protected string $base_path;

/**
* @var string
*/
protected string $config_path;

/**
* @var bool
*/
Expand Down Expand Up @@ -56,6 +61,7 @@ class Loader implements ArrayAccess
private function __construct(string $base_path)
{
$this->base_path = $base_path;
$this->config_path = $base_path . DIRECTORY_SEPARATOR . 'config';
$this->config = new Arraydotify([]);
}

Expand Down Expand Up @@ -85,6 +91,17 @@ public function isCli(): bool
return php_sapi_name() == 'cli';
}

/**
* Get the base path
*
* @param string $filename
* @return string
*/
public function getPath(string $filename): string
{
return $this->base_path . DIRECTORY_SEPARATOR . $filename;
}

/**
* Get the base path
*
Expand All @@ -95,6 +112,19 @@ public function getBasePath(): string
return $this->base_path;
}

/**
* Set the configuration path
*
* @param string $path
* @return Loader
*/
public function withConfigPath(string $path): Loader
{
$this->config_path = $path;

return $this;
}

/**
* Middleware collection
*
Expand Down Expand Up @@ -177,9 +207,7 @@ public function boot(): Loader
$container = Capsule::getInstance();

// Load the env configuration first
$env_config = $this->createConfiguration(EnvConfiguration::class, $container);

$env_config->run();
$this->createConfiguration(EnvConfiguration::class, $container);

// Load the .env or .env.json file
$this->loadConfigFiles();
Expand All @@ -193,7 +221,7 @@ public function boot(): Loader
// Load configurations
$this->runConfirmations($loaded_configurations);

// Load load events
// Load events
$this->loadEvents();

// Set the load as booted
Expand Down Expand Up @@ -284,7 +312,7 @@ private function loadConfigFiles(): void
/**
* We load all Bow configuration
*/
$glob = glob($this->base_path . '/**.php');
$glob = glob($this->config_path . '/**.php');

$config = [];

Expand Down
22 changes: 13 additions & 9 deletions src/Notifier/Adapters/SmsChannelAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SmsChannelAdapter implements ChannelAdapterInterface
public function __construct()
{
$config = config('notifier.sms');
$this->setting = $config['setting'] ?? [];
$this->setting = $config;
$this->sms_provider = $config['provider'] ?? 'callisto';
}

Expand Down Expand Up @@ -77,10 +77,11 @@ public function send(Model $context, Notifier $notifier): void
private function sendWithTwilio(Model $context, Notifier $notifier): void
{
$data = $notifier->toSms($context);
$config = $this->setting['twilio'] ?? [];

$account_sid = $this->setting['account_sid'] ?? null;
$auth_token = $this->setting['auth_token'] ?? null;
$this->from_number = $this->setting['from'] ?? null;
$account_sid = $config['account_sid'] ?? null;
$auth_token = $config['auth_token'] ?? null;
$this->from_number = $config['from'] ?? null;

if (!$account_sid || !$auth_token || !$this->from_number) {
throw new InvalidArgumentException('Twilio credentials are required');
Expand Down Expand Up @@ -110,17 +111,20 @@ private function sendWithTwilio(Model $context, Notifier $notifier): void
*/
private function sendWithCallisto(Model $context, Notifier $notifier): void
{
$access_key = $this->setting['access_key'] ?? null;
$access_secret = $this->setting['access_secret'] ?? null;
$notify_url = $this->setting['notify_url'] ?? null;
$config = $this->setting['callisto'] ?? [];

$access_key = $config['access_key'] ?? null;
$access_secret = $config['access_secret'] ?? null;
$notify_url = $config['notify_url'] ?? null;
$sender = $config['sender'] ?? null;

if (!$access_key || !$access_secret) {
throw new InvalidArgumentException('Callisto credentials are required');
}

$data = $notifier->toSms($context);

if (!isset($data['to']) || !isset($data['message']) || !isset($data['sender'])) {
if (!isset($data['to']) || !isset($data['message'])) {
throw new InvalidArgumentException('The phone number and notifier are required');
}

Expand All @@ -133,7 +137,7 @@ private function sendWithCallisto(Model $context, Notifier $notifier): void
$payload = [
'to' => (array) $data['to'],
'message' => $data['message'],
'sender' => $data['sender'],
'sender' => $data['sender'] ?? $sender,
];

if ($data['notify_url']) {
Expand Down
4 changes: 4 additions & 0 deletions src/Support/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public function __construct(string $filename)
*/
public static function configure(string $filename)
{
if (static::$instance !== null) {
return;
}

if (!file_exists($filename)) {
throw new InvalidArgumentException(
"The application environment file [.env.json] cannot be empty or is not define."
Expand Down
2 changes: 1 addition & 1 deletion tests/Config/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function test_invoke_method()
public function test_get_base_path()
{
$basePath = $this->config->getBasePath();
$this->assertEquals(__DIR__ . '/stubs/config', $basePath);
$this->assertEquals(__DIR__ . '/stubs', $basePath);
$this->assertIsString($basePath);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Config/TestingConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public static function getConfig(): ConfigurationLoader
{
Env::configure(__DIR__ . '/stubs/env.json');

return KernelTesting::configure(__DIR__ . '/stubs/config')->boot();
return KernelTesting::configure(__DIR__ . '/stubs')->withConfigPath(__DIR__ . '/stubs/config')->boot();
}
}
Loading
Loading