光二极管 / layer-pimcore-rest-api
用于通过REST API访问pimcore的Laminas模块
Requires
- php: >=7.1
- laminas/laminas-http: ~2.5
- netresearch/jsonmapper: ^4.0
Suggests
- laminas/laminas-cache: Using Laminas cache to minimize REST API calls
This package is auto-updated.
Last update: 2024-09-05 00:48:26 UTC
README
Laminas模块,通过REST API访问pimcore。
安装
此模块使用composer安装。有关composer文档,请参阅 getcomposer.org。
php composer.phar require leuchtdiode/pimcore-rest-api
然后,将 PimcoreRestApi
添加到您的 config/application.config.php
文件中。
使用方法
当前包含以下功能
- 通过ID检索文档
- 通过路径检索文档
- 搜索文档
- 用于打印文档纯文本的视图助手
设置
为了使用API,您必须在应用程序中指定配置集 pimcoreRestApi
(例如,在 config/autoload/local.php
中)
您必须设置以下参数
host
:您的pimcore API所在的主机(例如,cms.company.com)ssl
:默认为false。将其设置为true将通过SSL请求API。(例如,https://cms.company.com)apiKey
:您在pimcore中为您用户生成的API密钥
例如
<?php $config = [ ... 'pimcoreRestApi' => [ 'host' => 'cms.company.com', 'ssl' => false, 'apiKey' => '1233298asd89as9das89d9as9d8as89da9sd98as9dad', ], ... ];
服务
我们建议不要直接使用API,而是通过服务定位器使用该模块提供的服务。目前,只包含一个文档服务。
您可以使用服务定位器中的 PimcoreRestApi\Service\Documents
来检索文档
- 通过ID获取单个文档
getById($documentId)
- 通过路径获取单个文档
getByPath($documentPath)
- 通过路径获取所有文档
getAllByPath($path)
视图助手
该模块还提供用于显示给定文档路径纯文本的视图助手。
PraDocument
在您的视图中调用 $this->praDocument()
可以获取文档视图助手的实例,该助手目前提供以下方法
打印路径的文本
$this->praDocument()->printTextForPath($path)
此方法尝试通过其路径获取文档,搜索其所有WYSIWYG元素,将它们连接起来并输出文本。如果无法获取文档或找到WYSIWYG元素,则返回 null
。
缓存
为了最小化通过REST API调用外部pimcore系统,我们建议设置由 laminas-cache 提供的存储缓存。
该模块已经实现了缓存。您只需通知它。
设置很简单,只需在服务定位器中定义一个工厂,该工厂返回一个 Laminas\Cache\Storage\StorageInterface
,键为 PimcoreRestApi\StorageCache
。
同步内容到本地系统
您可以使用 PimcoreRestApi\Service\ConfigSynchronizing
将特定的CMS路径同步到您的本地系统。内容同步可以有多种策略。方法 synchronize($rootPath)
从配置中加载策略并执行同步。 $rootPath
是您想要同步的CMS中的根路径及其所有子路径。
目前,只有FileSystemStrategy。您必须在配置文件中指定您想要使用的策略。使用数组键 synchronizing
。
文件系统
以下是FileSystem策略的示例配置。
'synchronizing' => [
'type' => 'fileSystem',
'directory' => 'data/pimcoreRestApi'
]