webman-php / event Goto Github PK
View Code? Open in Web Editor NEWwebman event plugin
License: MIT License
webman event plugin
License: MIT License
protected function execute(InputInterface $input, OutputInterface $output) 结尾应该有个 :int 返回值 目前 composer require 的版本是 1.0.4 ,拉不到 1.0.5
` /**
* @param string $name
* @return void
*/
public static function has(string $name)
{
$list = static::list();
foreach ($list as $index => $item) {
if ($item[0] == trim($name)) {
return true;
}
}
return false;
}`
` /**
* @param $event_name
* @param $data
* @return
*/
public static function emit($event_name, $data, $once = false)
{
$success_count = 0;
$callbacks = static::$eventMap[$event_name]??[];
foreach (static::$prefixEventMap as $name => $callback_items) {
if (strpos($event_name, $name) === 0) {
$callbacks = array_merge($callbacks, $callback_items);
}
}
ksort($callbacks);
$ret = [];
foreach ($callbacks as $callback) {
try {
$ret[$event_name] = $callback($data, $event_name);
$success_count++;
} catch (\Throwable $e) {
if (!static::$logger && is_callable('\support\Log::error')) {
static::$logger = Log::channel();
}
if (static::$logger) {
static::$logger->error($e);
}
continue;
}
}
if ($once && isset($ret[$event_name])) {
return $ret[$event_name];
}
return $ret;
}`
默认事件不返回钩子调用的数据,无法满足某些场景,另外返回false会终止,
增加了一个has的函数检查当前钩子是否存在
@walkor 默认的函数
public static function emit($event_name, $data, $halt = false)
{
$success_count = 0;
$listeners = static::getListeners($event_name);
$responses = [];
foreach ($listeners as $listener) {
try {
$response = $listener($data, $event_name);
} catch (\Throwable $response) { **// 这里写错了**
if (!static::$logger && is_callable('\support\Log::error')) {
static::$logger = Log::channel();
}
if (static::$logger) {
static::$logger->error($e); // **$e?**
}
continue;
}
$responses[] = $response;
if ($halt && !is_null($response)) {
return $response;
}
// 如果一个userLogin存在两个钩子
// 第一个返回false就中断执行了,
if ($response === false) {
break;
}
}
return $halt ? null : $responses;
}
其他的没发现异常可以正常调用回显!可以合并后发一个版本!
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires webman/event ^1.0.5, found webman/event[dev-main, v1.0.2, v1.0.3, v1.0.4] but it does not match the constraint.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.