1. Go to this page and download the library: Download riven/hyperf-callee 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/ */
riven / hyperf-callee example snippets
return [
Callee\ConfigProvider::class,
];
namespace App\Event;
use Callee\CalleeEvent;
use Callee\CalleeEventTrait;
enum Action: string implements CalleeEvent
{
use CalleeEventTrait;
case Create = 'create';
case Update = 'update';
case Delete = 'delete';
case Read = 'read';
}
namespace App\Service;
use App\Event\Action;
use Callee\Annotation\Callee;
class UserService
{
#[Callee(Action::Create)]
public function createUser(string $name, string $email): array
{
// 处理创建用户的逻辑
return ['id' => 1, 'name' => $name, 'email' => $email];
}
#[Callee(Action::Update, async: true)]
public function updateUser(int $id, array $data): bool
{
// 处理更新用户的逻辑
return true;
}
}
use App\Event\Action;
use App\Service\UserService;
use Callee\Annotation\Callee;
use Callee\CalleeCollector;
// 注册事件处理方法
CalleeCollector::addCallee(
[UserService::class, 'createUser'],
new Callee(Action::Create)
);
// 注册异步事件处理方法
CalleeCollector::addCallee(
[UserService::class, 'updateUser'],
new Callee(Action::Update, async: true)
);