使用了twig模板,在event事件中将data放入队列,然后消费队列从取出data数据,放入 view("templte",$data)中,消费的时候就会报错。初步判断是不是 $app对象为空。
$key = "$plugin-$request->app";
private function getShareHtml(array $data): ?string {
$data['year'] = Carbon::parse($data['created_at'])->year;
$data['month'] = Carbon::parse($data['created_at'])->month;
$data['day'] = Carbon::parse($data['created_at'])->day;
$data['time'] = Carbon::parse($data['created_at'])->format('H:i');
return raw_view('share/managerNews', $data)->rawBody();
}
"Attempt to read property \"app\" on null"
#0 /var/www/jjrlvling/vendor/workerman/webman-framework/src/support/view/Twig.php(69): {closure}()
#1 /var/www/jjrlvling/support/helpers.php(202): support\\view\\Twig::render()
#2 /var/www/jjrlvling/app/service/WeiBoService.php(116): view()
#3 /var/www/jjrlvling/app/service/WeiBoService.php(90): App\\service\\WeiBoService->getShareHtml()
#4 /var/www/jjrlvling/app/queue/redis/slow/ShareWeiboSend.php(33): App\\service\\WeiBoService->makeScreenShot()
#5 /var/www/jjrlvling/vendor/workerman/redis-queue/src/Client.php(220): App\\queue\\redis\\slow\\ShareWeiboSend->consume()
#6 /var/www/jjrlvling/vendor/workerman/redis/src/Client.php(422): Workerman\\RedisQueue\\Client->Workerman\\RedisQueue\\{closure}()
#7 /var/www/jjrlvling/vendor/workerman/workerman/Connection/TcpConnection.php(646): Workerman\\Redis\\Client->Workerman\\Redis\\{closure}()
#8 [internal function]: Workerman\\Connection\\TcpConnection->baseRead()
#9 /var/www/jjrlvling/vendor/workerman/workerman/Events/Event.php(193): EventBase->loop()
#10 /var/www/jjrlvling/vendor/workerman/workerman/Worker.php(1629): Workerman\\Events\\Event->loop()
#11 /var/www/jjrlvling/vendor/workerman/workerman/Worker.php(1423): Workerman\\Worker::forkOneWorkerForLinux()
#12 /var/www/jjrlvling/vendor/workerman/workerman/Worker.php(1397): Workerman\\Worker::forkWorkersForLinux()
#13 /var/www/jjrlvling/vendor/workerman/workerman/Worker.php(560): Workerman\\Worker::forkWorkers()
#14 /var/www/jjrlvling/vendor/workerman/webman-framework/src/support/App.php(131): Workerman\\Worker::runAll()
#15 /var/www/jjrlvling/start.php(4): support\\App::run()
#16 {main}"} []
先手动把本地
改成
下个版本兼容
$key = "$plugin-$request?->app"; 我改成这样了