如何在使用composer时仅在特定文件上制作“require”-config文件

How require config file on only on another file when use composer?

Consider have a file called "config.php" in root in this file we have some variable like $site_url :

$config = [
    // e.g (http://example.com or https://exmaple.com)
    "site_url" => "http://localhost"
];

and have a class called "DBConnect" in include folder "include/DBConnect.php" now we want use variable saved on config.php in class "DBConnect" , well write require "../config.php"; and use variable.

<?php


namespace Admin\includes;
require "../config.php";

class DBConnect
{
    //dsn : engine:Servername;DbName;charset;
    protected $engine;
    protected $servername;
    protected $dbname;
    protected $charset;



    public function __construct()
    {


    }
}
index.php
<?php
require  "vendor/autoload.php";

$tp1 = new \Admin\includes\DBConnect();

now we call getname class in index.php , when called it php return error

Warning: require(../config.php): failed to open stream....

Make path relative to current directory by using __DIR__ magic constant:

require __DIR__ . "/../config.php";