restoore / 因此
Therefore Web API集成到Laravel应用程序的集成包
Requires
- php: >=5.4
- laravel/framework: ~5.0
This package is not auto-updated.
Last update: 2024-09-14 20:09:26 UTC
README
这是一个将Therefore Webservice集成到Laravel 5的包。它包括一个ServiceProvider来注册webservice。您还可以使用外观来增加webservice的使用。
Laravel 5.x的安装
使用composer安装此包
composer require restoore/laravel-therefore
更新composer后,将ServiceProvider添加到config/app.php中的providers数组
Restoore\Therefore\ThereforeServiceProvider::class
如果您想使用外观,请在app.php中的外观中添加此内容
'Therefore' => Restoore\Therefore\Facades\Therefore::class
使用发布命令将包配置复制到本地配置
php artisan vendor:publish --provider="Restoore\Therefore\ThereforeServiceProvider" --tag="config"
使用发布命令将迁移文件复制到本地迁移文件夹
php artisan vendor:publish --provider="Restoore\Therefore\ThereforeServiceProvider" --tag="migrations"
启动迁移
php artisan migrate
配置
如果您已使用以下命令
php artisan vendor:publish --provider="Restoore\Therefore\ThereforeServiceProvider" --tag="config"
您的本地配置路径中有therefore.php文件,默认为:/config/therefore.php,如果没有,您必须创建此文件。在此文件中,您需要返回一个数组中的四个参数
- wsdl,您的therefore wsld文件的URL
- login,您的therefore账户登录名
- password;您的therefore账户密码
- file_path,您想要保存文件和缩略图的文件位置。所有文件都将保存在您的laravel公共文件夹中。例如,如果您将docs/therefore/,所有文件都将创建在public/docs/therefore/
环境
如果您想使用不同的开发环境,可以使用.env文件覆盖wsdl、login和password参数。
THEREFORE_WSDL= THEREFORE_LOGIN= THEREFORE_PASSWORD=
使用方法
现在,您可以通过PHP特质将您的模型连接到Therefore文档。首先,您必须将ThereforeTrait添加到您的模型中
use \Restoore\Therefore\ThereforeTrait;
现在,您必须配置属性以将模型绑定到Therefore文档
- $thereforeCategoryNo将包含Therefore文档中的CategoryNo
- $thereforeFieldNo将包含您想要用于链接Therefore文档和您的模型的字段id
- $thereforeSearchableField将包含您要用于链接您的模型的模型属性名称。这应该看起来像这样
//therefore use \Restoore\Therefore\ThereforeTrait; protected $thereforeCategoryNo = 8; protected $thereforeFieldNo = 92; protected $thereforeSearchableField = 'id';
在此示例中,模型id必须与Therefore文档中字段92的值相同。
检索文档和文件
现在,您可以使用函数listDocuments检索与您的模型链接的所有文档。例如
$class->refreshCacheFiles(); dd($class->listDocuments());
将为我提供示例
Collection {#545 ▼ #items: array:1 [▼ 0 => ThereforeDocument {#539 ▼ #fillable: array:7 [▼ 0 => "categoryNo" 1 => "docNo" 2 => "versionNo" 3 => "searchableField" 4 => "lastChangeTime" 5 => "title" 6 => "ctgryName" ] ... } ] }
refreshCacheFiles将检查您是否有最新版本的文档并更新数据库和文件。您可以选择不每次都使用此函数,而是让用户手动刷新文件列表。
现在,如果您想获取文档的文件
@foreach($documents as $document) @foreach($document->files as $file) ... @endforeach @endforeach
这里是有文件模型结构
ThereforeFile {#554 ▼ #fillable: array:4 [▼ 0 => "therefore_document_id" 1 => "streamNo" 2 => "fileName" 3 => "size" ] ... } ] }
ThereforeDocument和ThereforeFile的所有属性都可以通过它们的名称访问。例如
$thereforedocument->categoryNo $thereforedocument->lastChangeTime $thereforedocument->ctgryName $thereforefile->fileName $thereforefile->size
ThereforeFile模型的一些有用函数
public function getFullPath() //Get full server path public function getFileNameWithoutExtension() //Get filename without his extension public function getExtension() //Only get the extension public function deleteFromServer() //Delete file from web server public function getUrl() //Return full link of your file public function getSizeAttribute($value) //Return formatted size of your file like "16.5 Mo" or "500 ko" public function getThumbnailUrl() //Return thumbnail url and if thumbnail doesn t exist create him public function deleteThumbnail() //Delete thumbnail from web server