wkasunsampath / laravel-vuforia
Laravel 的 Vuforia 网络服务 API
v1.1.0
2022-05-12 14:12 UTC
Requires
- php: >=7.3.0
- illuminate/support: >=8.0.0
- pear/http_request2: ^2.4.0
Requires (Dev)
- laravel/framework: ^8|^9
This package is auto-updated.
Last update: 2024-09-18 09:59:15 UTC
README
Laravel 8 & Laravel 9 的 Vuforia 网络服务 API。此包是对 panoscape/laravel-vuforia 包的改进。所有功劳应归功于原始开发者。
安装
composer require wkasunsampath/laravel-vuforia
特性
自动包发现,无需添加任何提供者或别名。
使用 Facade 容易实现
- VWS::getTargets()
- VWS::getTarget(string $id)
- VWS::updateTarget(string $id, mixed $target)
- VWS::addTarget(mixed $target)
- VWS::deleteTarget(string $id)
- VWS::getDuplicates(string $id)
- VWS::getDatabaseSummary()
- VWS::getTargetSummary(string $id)
使用数组调用
VWS::addTarget([ 'name' => 'my_new_target', 'width' => 320, 'path' => public_path('storage/IMG_2738.jpg') ]);
预检查
VWS::addTarget(['name' => '123 1']);
异常信息:"无效命名"
VWS::addTarget(['name' => '123']);
异常信息:"需要目标宽度"
VWS::addTarget(['name' => '1231', 'width' => 100, 'path' => public_path('storage/image.png')]);
异常信息:"图像太大"
图像目标类
$target = new \WKasunSampath\LaravelVuforia\Target; $target->name = 'image_01'; $target->width = 320; $target->image = file_get_contents(public_path('images/001.jpg')); //optional fields $target->metadata = 'Hello world'; $target->active = false;
包装结果
[ "status" => 201, "body" => '{"result_code":"TargetCreated","transaction_id":"xxx","target_id":"xxx"}', ]
[ "status" => 422, "body" => '{"result_code":"BadImage","transaction_id":"xxx"}', ]
可配置
您可以使用以下命令将配置文件发布到配置目录。
php artisan vendor:publish --tag=laravel_vuforia
此命令将在配置目录中生成 laravel_vuforia.php 文件。其内容如下:
[ /* |-------------------------------------------------------------- | Vuforia Web Service URLs |-------------------------------------------------------------- | | */ 'url' => [ /* |-------------------------------------------------------------- | Vuforia Web Service Targets Request URL |-------------------------------------------------------------- | | */ 'targets' => 'https://vws.vuforia.com/targets', /* |-------------------------------------------------------------- | Vuforia Web Service Duplicates Request URL |-------------------------------------------------------------- | | */ 'duplicates' => 'https://vws.vuforia.com/duplicates', /* |-------------------------------------------------------------- | Vuforia Web Service Summary Request URL |-------------------------------------------------------------- | | */ 'summary' => 'https://vws.vuforia.com/summary', ], /* |-------------------------------------------------------------- | Vuforia cloud database credentials |-------------------------------------------------------------- | | */ 'credentials' => [ /* |-------------------------------------------------------------- | Vuforia cloud database access key |-------------------------------------------------------------- | | */ "access_key" => env('VUFORIA_ACCESS_KEY'), /* |-------------------------------------------------------------- | Vuforia cloud database secret key |-------------------------------------------------------------- | | */ "secret_key" => env('VUFORIA_SECRET_KEY'), ], /* |-------------------------------------------------------------- | Max image size(unencoded) in Byte. Default is 2MB | Set to null to bypass size checking(not recommended) |-------------------------------------------------------------- | | */ 'max_image_size' => 2097152, /* |-------------------------------------------------------------- | Max metadata size(unencoded) in Byte. Default is 2MB | Set to null to bypass size checking(not recommended) |-------------------------------------------------------------- | | */ 'max_meta_size' => 2097152, /* |-------------------------------------------------------------- | Name checking rule. Default is | no spaces and may only contain: | numbers (0-9), letters (a-z), underscores ( _ ) and dashes ( - ) | Set to null to bypass name checking(not recommended) |-------------------------------------------------------------- | | */ 'naming_rule' => '/^[\w\-]+$/' ]
作业和通知
/** * Upload image to Vuforia */ abstract class VuforiaJob implements ShouldQueue { use InteractsWithQueue, Queueable, SerializesModels; /** * Execute the job. * * @param VuforiaWebService $vws * @return void */ abstract function handle(VuforiaWebService $vws); /** * The job failed to process. * * @param Exception $exception * @return void */ abstract function failed(Exception $exception); }
abstract class VuforiaNotification extends Notification { use Queueable; protected $result; /** * Create a new notification instance. * * @param mixed $result * * @return void */ public function __construct($result) { $this->result = $result; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['database']; } /** * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ public function toArray($notifiable) { return [ 'result' => $this->result ]; } }