PHP code example of ezijing / hyperf-annotated-log

1. Go to this page and download the library: Download ezijing/hyperf-annotated-log 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/ */

    

ezijing / hyperf-annotated-log example snippets


return [
    // 配置操作者的ID
    // 登录用户信息存储在 Context下
    'user' => [
        'key' => 'user', // context的key
        'id' => 'id', // 用户的id
    ],
];

$loginUser = user(); // 获取登录信息伪代码
Context::set('annotation_log.user.key', $loginUser);



declare(strict_types=1);

namespace App\Controller;

use App\Services\UserService;
use Ezijing\HyperfAnnotatedLog\Annotations\OperationLog;
use Hyperf\Di\Annotation\Inject;

class IndexController extends AbstractController
{
    /**
     * @Inject
     * @var UserService
     */
    protected $service;

    /**
     * @OperationLog(operation="test", desc="测试")
     */
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();
        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }
}
shell
 php bin/hyperf.php vendor:publish ezijing/hyperf-annotated-log