PHP code example of felo-z / hyperf-helper

1. Go to this page and download the library: Download felo-z/hyperf-helper 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/ */

    

felo-z / hyperf-helper example snippets


info('用户登录成功', $userId);
error('签到异常', $exception, ['id' => 1]);

// 单条日志需要定位调用来源
info_bt('订单创建', $orderId);

// 或通过环境变量全局开启(见下方)

info_bt('需要定位的日志', $data);
error_bt('临时排查', $exception);

$service = app(SomeService::class);
$container = app();

$exitCode = command('migrate', ['--force' => true]);

$name = request('name', 'default');
return response(['code' => 0], 200);

$data = ['name' => 'Tom', 'age' => null, 'tags' => []];

key_filled($data, 'name');  // true
key_filled($data, 'age');   // false(值为 null)
key_filled($data, 'tags');  // false(空数组)
key_filled($data, 'email'); // false(key 不存在)

// 支持嵌套 key
key_filled($data, 'user.name');

// 环境判断(读取 APP_ENV)
app_env();   // dev / test / prod ...
is_local();  // dev、local、test、testing 返回 true
is_pro();    // prod、production 返回 true