boxmoe_header_banner_img

Hello! 欢迎来到悠悠畅享网!

文章导读

告别繁琐:使用ricorocks-digital-agency/soap简化LaravelSOAP调用


avatar
悠悠站长 2025年6月16日 6

在构建企业级应用时,与遗留系统或外部服务进行集成是不可避免的。SOAP (Simple Object Access Protocol) 是一种常见的集成技术,但其固有的复杂性常常让开发者望而却步。传统的 PHP SoapClient 使用起来较为繁琐,需要编写大量的 XML 处理代码。ricorocks-digital-agency/soap 这个 Laravel 扩展包的出现,正是为了解决这个问题。

通过 composer 安装:

composer require ricorocks-digital-agency/soap

安装完成后,就可以开始使用简洁的 Facade 接口了。

主要特性:

  • 简洁的 API: 使用 Soap::to() 指定 endpoint,Soap::call() 调用方法,链式调用让代码更具可读性。
  • 灵活的参数处理: 支持数组参数,并提供 soap_node() 辅助函数,方便构建复杂的 XML 节点。
  • 强大的 Header 支持: 通过 Soap::header() 轻松设置 SOAP Header,支持全局 Header 和针对特定 endpoint/action 的 Header。
  • 便捷的 Option 设置: 使用 withOptions() 自定义 SoapClient 选项,并提供 trace()、withBasicAuth()、withDigestAuth() 等常用选项的快捷方法。
  • Hook 机制: 提供 beforeRequesting()、afterErroring()、afterRequesting() Hook,方便在请求前后执行自定义逻辑。
  • 强大的 Faking 功能: 通过 Soap::fake() 轻松模拟 SOAP 响应,方便进行单元测试。
  • Ray 集成: 完美支持 Spatie 的 Ray 调试工具,方便查看 SOAP 请求和响应。

示例:

use RicorocksDigitalAgencySoapFacadesSoap;  // 调用 SOAP 服务 $response = Soap::to('http://example.com/service')     ->withHeaders(soap_header('Auth', 'test.com')->data(['user' => '...', 'password' => '...']))     ->call('GetUserDetails', ['id' => 123]);  // 获取响应数据 $userDetails = $response->toArray();  // 使用 Faking 进行测试 Soap::fake(['http://example.com/service:GetUserDetails' => ['name' => 'John Doe', 'email' => 'john@example.com']]); $response = Soap::to('http://example.com/service')->call('GetUserDetails', ['id' => 123]); $this->assertEquals('John Doe', $response['name']);  // 使用 Ray 调试 ray()->showSoapRequests(); $response = Soap::to('http://example.com/service')->call('GetUserDetails', ['id' => 123]); ray()->stopShowingSoapRequests();

优势与实际应用:

  • 提升开发效率: 简洁的 API 减少了 boilerplate 代码,让开发者专注于业务逻辑。
  • 增强代码可读性 链式调用和辅助函数使代码更易于理解和维护。
  • 方便单元测试: 强大的 Faking 功能让单元测试更加轻松。
  • 简化配置管理: 全局 Option 和 Header 设置方便管理 SOAP 客户端配置。

在实际项目中,ricorocks-digital-agency/soap 可以应用于以下场景:

  • 企业服务总线 (ESB) 集成: 与企业内部的各种服务进行集成。
  • 第三方支付平台对接: 与银行或第三方支付平台进行 SOAP 接口对接
  • 遗留系统迁移: 将遗留系统的 SOAP 接口迁移到 Laravel 应用中。

总而言之,ricorocks-digital-agency/soap 是一个非常实用的 Laravel 扩展包,它极大地简化了 SOAP 客户端的开发,提升了开发效率和代码质量。如果你正在 Laravel 项目中与 SOAP 服务打交道,那么强烈推荐你尝试一下这个扩展包。

input: intervention/image

Image handling and manipulation library with support for Laravel integration

Intervention Image Intervention Image is an open source PHP image handling and manipulation library. It provides an easier and expressive way to create, edit, and compose images. Currently supports GD Library and Imagick.

The package is bundled as a composer package for easy installation into your PHP projects. Intervention Image is designed to be framework-agnostic and works fine in any PHP framework.

Furthermore there is a Laravel Package available to integrate the library smoothly into your Laravel projects.

Documentation You can find comprehensive documentation for Intervention Image on the dedicated website.

Requirements PHP >= 8.0 GD Library (>=2.0) with FreeType support OR Imagick PHP extension (>=6.5.7) Fileinfo Extension (required to determine image type) Installation Install the latest version with Composer

composer require intervention/image If you are using Laravel, you can install the Laravel service provider with Composer

composer require intervention/image:dev-master Note: If you are using Laravel 5.x, please use the 2.x release.

Configuration (Laravel) After installing the Intervention Image package, open your Laravel config file config/app.php and add the following lines.

In the $providers array add the service providers for this package.

InterventionImageImageServiceProvider::class Add the facade of this package to the $aliases array.

‘Image’ => InterventionImageFacadesImage::class Publish Configuration (Laravel) Next, publish the config file into your application:

php artisan vendor:publish –provider=”InterventionImageImageServiceProviderLaravelRecent” Now you can find the configuration under config/image.php.

Usage Create new image instances from existing files

use InterventionImageFacadesImage;

$img = Image::make(‘public/foo.jpg’); or create new images from scratch

$img = Image::canvas(800, 600, ‘#ff0000’); resize image instance

$img->resize(320, 240); resize image instance with aspect ratio

$img->resize(320, null, function ($constraint) { $constraint->aspectRatio(); }); prevent upsizing

$img->resize(320, 240, function ($constraint) { $constraint->upsize(); }); insert a watermark

$img->insert(‘public/watermark.png’); save image in desired format

$img->save(‘path/to/image.jpg’); save image as png with different quality

$img->encode(‘png’, 75); insert a background-color

$img->background(‘#000000’); More examples and options on the website.

License Intervention Image is licensed under the MIT License.

Security Vulnerabilities If you discover a security vulnerability within Intervention Image, please send an e-mail to Oliver Vogel via security@intervention.io. All security vulnerabilities will be promptly addressed.



评论(已关闭)

评论已关闭