What are the best practices for passing configuration data to PHP classes using Dependency Injection?

When passing configuration data to PHP classes using Dependency Injection, it is best practice to define the configuration data as dependencies in the class constructor. This allows for better flexibility, testability, and separation of concerns within your codebase.

class MyClass {
    private $config;

    public function __construct(array $config) {
        $this->config = $config;
    }

    public function getConfigValue($key) {
        return $this->config[$key] ?? null;
    }
}

// Usage
$config = [
    'database_host' => 'localhost',
    'database_name' => 'my_database',
    'username' => 'root',
    'password' => 'password123'
];

$myClass = new MyClass($config);
echo $myClass->getConfigValue('database_name'); // Output: my_database