Giter VIP home page Giter VIP logo

event's People

Contributors

walkor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

meystack

event's Issues

webman event EventListCommand 文件

protected function execute(InputInterface $input, OutputInterface $output) 结尾应该有个 :int 返回值 目前 composer require 的版本是 1.0.4 ,拉不到 1.0.5

增加一个has函数,修改事件支持返回参数

` /**
* @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的函数检查当前钩子是否存在

emit 函数修改

@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;
}

其他的没发现异常可以正常调用回显!可以合并后发一个版本!

是不是 composer 包管理器没发布

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.