AddPayloadBodyPlugin.php 888 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Artful\Plugin;
  4. use Closure;
  5. use Yansongda\Artful\Contract\PluginInterface;
  6. use Yansongda\Artful\Exception\InvalidParamsException;
  7. use Yansongda\Artful\Logger;
  8. use Yansongda\Artful\Rocket;
  9. use function Yansongda\Artful\filter_params;
  10. use function Yansongda\Artful\get_packer;
  11. class AddPayloadBodyPlugin implements PluginInterface
  12. {
  13. /**
  14. * @throws InvalidParamsException
  15. */
  16. public function assembly(Rocket $rocket, Closure $next): Rocket
  17. {
  18. Logger::debug('[AddPayloadBodyPlugin] 插件开始装载', ['rocket' => $rocket]);
  19. $packer = get_packer($rocket->getPacker());
  20. $rocket->mergePayload(['_body' => $packer->pack(filter_params($rocket->getPayload()))]);
  21. Logger::info('[AddPayloadBodyPlugin] 插件装载完毕', ['rocket' => $rocket]);
  22. return $next($rocket);
  23. }
  24. }