告別繁瑣:使用ricorocks-digital-agency/soap簡(jiǎn)化LaravelSOAP調(diào)用

在構(gòu)建企業(yè)級(jí)應(yīng)用時(shí),與遺留系統(tǒng)或外部服務(wù)進(jìn)行集成是不可避免的。SOAP (Simple Object Access Protocol) 是一種常見(jiàn)的集成技術(shù),但其固有的復(fù)雜性常常讓開(kāi)發(fā)者望而卻步。傳統(tǒng)的 php SoapClient 使用起來(lái)較為繁瑣,需要編寫(xiě)大量的 xml 處理代碼。ricorocks-digital-agency/soap 這個(gè) laravel 擴(kuò)展包的出現(xiàn),正是為了解決這個(gè)問(wèn)題。

通過(guò) composer 安裝:

composer require ricorocks-digital-agency/soap

安裝完成后,就可以開(kāi)始使用簡(jiǎn)潔的 Facade 接口了。

主要特性:

  • 簡(jiǎn)潔的 API: 使用 Soap::to() 指定 endpoint,Soap::call() 調(diào)用方法,鏈?zhǔn)秸{(diào)用讓代碼更具可讀性。
  • 靈活的參數(shù)處理: 支持?jǐn)?shù)組參數(shù),并提供 soap_node() 輔助函數(shù),方便構(gòu)建復(fù)雜的 XML 節(jié)點(diǎn)。
  • 強(qiáng)大的 Header 支持: 通過(guò) Soap::header() 輕松設(shè)置 SOAP Header,支持全局 Header 和針對(duì)特定 endpoint/action 的 Header。
  • 便捷的 Option 設(shè)置: 使用 withOptions() 自定義 SoapClient 選項(xiàng),并提供 trace()、withBasicAuth()、withDigestAuth() 等常用選項(xiàng)的快捷方法。
  • Hook 機(jī)制: 提供 beforeRequesting()、afterErroring()、afterRequesting() Hook,方便在請(qǐng)求前后執(zhí)行自定義邏輯。
  • 強(qiáng)大的 Faking 功能: 通過(guò) Soap::fake() 輕松模擬 SOAP 響應(yīng),方便進(jìn)行單元測(cè)試。
  • Ray 集成: 完美支持 Spatie 的 Ray 調(diào)試工具,方便查看 SOAP 請(qǐng)求和響應(yīng)。

示例:

use RicorocksDigitalAgencySoapFacadesSoap;  // 調(diào)用 SOAP 服務(wù) $response = Soap::to('http://example.com/service')     ->withHeaders(soap_header('Auth', 'test.com')->data(['user' => '...', 'password' => '...']))     ->call('GetUserDetails', ['id' => 123]);  // 獲取響應(yīng)數(shù)據(jù) $userDetails = $response->toArray();  // 使用 Faking 進(jìn)行測(cè)試 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 調(diào)試 ray()->showSoapRequests(); $response = Soap::to('http://example.com/service')->call('GetUserDetails', ['id' => 123]); ray()->stopShowingSoapRequests();

優(yōu)勢(shì)與實(shí)際應(yīng)用:

  • 提升開(kāi)發(fā)效率: 簡(jiǎn)潔的 API 減少了 boilerplate 代碼,讓開(kāi)發(fā)者專注于業(yè)務(wù)邏輯。
  • 增強(qiáng)代碼可讀性 鏈?zhǔn)秸{(diào)用和輔助函數(shù)使代碼更易于理解和維護(hù)。
  • 方便單元測(cè)試: 強(qiáng)大的 Faking 功能讓單元測(cè)試更加輕松。
  • 簡(jiǎn)化配置管理: 全局 Option 和 Header 設(shè)置方便管理 SOAP 客戶端配置。

在實(shí)際項(xiàng)目中,ricorocks-digital-agency/soap 可以應(yīng)用于以下場(chǎng)景:

  • 企業(yè)服務(wù)總線 (ESB) 集成: 與企業(yè)內(nèi)部的各種服務(wù)進(jìn)行集成。
  • 第三方支付平臺(tái)對(duì)接: 與銀行或第三方支付平臺(tái)進(jìn)行 SOAP 接口對(duì)接
  • 遺留系統(tǒng)遷移: 將遺留系統(tǒng)的 SOAP 接口遷移到 Laravel 應(yīng)用中。

總而言之,ricorocks-digital-agency/soap 是一個(gè)非常實(shí)用的 Laravel 擴(kuò)展包,它極大地簡(jiǎn)化了 SOAP 客戶端的開(kāi)發(fā),提升了開(kāi)發(fā)效率和代碼質(zhì)量。如果你正在 Laravel 項(xiàng)目中與 SOAP 服務(wù)打交道,那么強(qiáng)烈推薦你嘗試一下這個(gè)擴(kuò)展包。

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.

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊14 分享