PHP code example of ruesin / utils

1. Go to this page and download the library: Download ruesin/utils 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/ */

    

ruesin / utils example snippets


return [
    'web' => [
        'host' => '127.0.0.1',
        'port' => '3306',
        'user' => 'root',
        'pass' => 'root',
        'database' => 'web_db'
    ],
    'server' => [
        'host' => '127.0.0.2',
        'port' => '3306',
        'user' => 'ruesin',
        'pass' => 'ruesin',
        'database' => 'server_db'
    ]
];

//加载 /tmp/config 目录下的所有 php 文件,文件名作为配置数组的key
Config::loadPath('/tmp/config/');
//加载 /tmp/config/mysql.php 文件
Config::loadFile('/tmp/config/mysql.php');
/*
Config::$config = [
    'mysql' => [
        'web' => [...],
        'server' => [....],
    ]
];
*/
//将 Config::$config['mysql']['web']['user'] 的值改为 ruesin
Config::set('mysql.web.user', 'ruesin');

//获取Config::$config['mysql']['server']的值
print_r(Config::get('mysql.server'));
/*
[
    'host' => '127.0.0.2',
    'port' => '3306',
    'user' => 'ruesin',
    'pass' => 'ruesin',
    'database' => 'server_db'
]
*/


//初始化配置,log_path为日志存储目录,unique_id为日志文件唯一标识,默认为当前进程号。
Log::init(['log_path' => '/your-log-path/', 'unique_id' => '123']);

//向 /your-log-path/ruesin/default.log 文件追加写入 This is my message!
Log::msg('This is my message!', 'default', 'ruesin');

//向 /your-log-path/ruesin/info.log 文件追加写入 [2019-01-14 22:53:00] This is my info!
Log::info('This is my info!', 'info', 'ruesin');