示例#1
0
 public function listener(callable $listener)
 {
     $this->addListener(CallbackUtils::toReflection($listener), $listener);
     return $this;
 }
示例#2
0
 private static function pcre($func, $args)
 {
     static $messages = [PREG_INTERNAL_ERROR => 'Internal error', PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted', PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted', PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data', 5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point'];
     $res = CallbackUtils::invokeSafe($func, $args, function ($message) use($args) {
         // compile-time error, not detectable by preg_last_error
         throw new UtilsException($message . ' in pattern: ' . implode(' or ', (array) $args[0]));
     });
     if (($code = preg_last_error()) && ($res === null || !in_array($func, ['preg_filter', 'preg_replace_callback', 'preg_replace']))) {
         throw new UtilsException((isset($messages[$code]) ? $messages[$code] : 'Unknown error') . ' (pattern: ' . implode(' or ', (array) $args[0]) . ')', $code);
     }
     return $res;
 }