Skip to content

Commit

Permalink
env included
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetsafak committed Aug 30, 2024
1 parent 47bc843 commit e396aa5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RABBITMQ_HOST="localhost"
RABBITMQ_PORT="5672"
RABBITMQ_USER="guest"
RABBITMQ_PASS="guest"
6 changes: 6 additions & 0 deletions App/Helpers/general_helper.php
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<?php
if (!function_exists('env')) {
function env(string $name, mixed $default = null): mixed
{
return $_ENV[$name] ?? $default;
}
}
9 changes: 5 additions & 4 deletions App/Queues/MailQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class MailQueue extends Queue
public function __construct()
{
$adapter = AdapterFactory::create('rabbitmq', [
'host' => 'localhost',
'port' => 5672,
'username' => 'guest',
'password' => 'guest',
'host' => env("RABBITMQ_HOST", "localhost"),
'port' => env("RABBITMQ_PORT", 5672),
'username' => env("RABBITMQ_USER", "guest"),
'password' => env("RABBITMQ_PASS", "guest"),
]);

parent::__construct($adapter);
}

Expand Down
4 changes: 4 additions & 0 deletions Sys/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Sys;

use Symfony\Component\Dotenv\Dotenv;

class Application
{
public function __construct()
Expand All @@ -10,6 +12,8 @@ public function __construct()

public function boot(): self
{
is_file(ROOT_DIR . '.env') && (new Dotenv())->load(ROOT_DIR . '.env');

$helpers = glob(APP_DIR . "Helpers/*.php");
foreach ($helpers as $helper) {
if (file_exists($helper)) {
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"require": {
"php": ">=8.1",
"phpqueuemanager/php-queue-manager": "*",
"symfony/console": "^6.4"
"symfony/console": "^6.4",
"symfony/dotenv": "^6.4"
}
}

0 comments on commit e396aa5

Please sign in to comment.