PHP code example of buuum / config

1. Go to this page and download the library: Download buuum/config library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buuum / config example snippets


$configs = [
   'environment'  => 'local',

   'local' => [
      'host'        => 'host.dev',
      'public'      => 'httpdocs',
      'development' => true,
      'bbdd'        => [
          'database' => 'database_name',
          'host'     => '127.0.0.1',
          'username' => 'username',
          'password' => 'password'
      ]
  ],
  'prod' => [
         'host'        => 'host.com',
         'public'      => 'httpdocs',
         'development' => false,
         'bbdd'        => [
             'database' => 'database_name',
             'host'     => '127.0.0.1',
             'username' => 'username',
             'password' => 'password'
         ]
     ]

];

$autoloads = [
    "files" => ['functions.php'],
    "psr-4" => [
        "App\\Demo\\" => __DIR__."/src/Demo",
    ]
];

$config = new Config($configs, $autoloads);


$config->get('environment');
// return local
$config->get('local.host');
// return host.dev
$config->get('local.bbddd');
// return array
$config->get('local.bbdd.database);
// return database_name


class HandleError implements HandleErrorInterface
{

    private $logPath;
    private $debugMode;

    public function __construct($debugmode, $logPath = null)
    {
        $this->logPath = $logPath;
        $this->debugMode = $debugmode;
    }

    public function getDebugMode()
    {
        return $this->debugMode;
    }

    public function parseError($errtype, $errno, $errmsg, $filename, $linenum)
    {

        $err = "<errorentry>\n";
        $err .= "\t<datetime>" . date("Y-m-d H:i:s (T)") . "</datetime>\n";
        $err .= "\t<errornum>" . $errno . "</errornum>\n";
        $err .= "\t<errortype>" . $errtype . "</errortype>\n";
        $err .= "\t<errormsg>" . $errmsg . "</errormsg>\n";
        $err .= "\t<scriptname>" . $filename . "</scriptname>\n";
        $err .= "\t<scriptlinenum>" . $linenum . "</scriptlinenum>\n";

        $err .= "</errorentry>\n\n";

        error_log($err, 3, $this->logPath . "/error.log");

    }
}

$handle = new HandleError(true, __DIR__);
$config->setupErrors($handle);