indiana-university/iukb-api-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

indiana-university/iukb-api-php

Composer 安装命令:

composer require indiana-university/iukb-api-php

包简介

A set of classes to pull documents from the IU knowledge base into your application

README 文档

README

A set of classes to pull documents from the IU knowledge base into your PHP application

Requirements

Usage

To instantiate the KB class, you must simply give it a provider. This is an instance of a class which will pull KB data from somewhere and feed it into the main KB class. There are currently three different providers, however, one of them is simply an intermediary class to provide caching. The two actual data providers are Filesystem and Web.

Filesystem

The Filesystem class is used for testing purposes, but could be used to provide caching in a different way from the way it is implemented in the caching class. For example, if you need to alter the content of the KB docs before displaying them. You could save the result some where on disk and load it through the Filesystem provider.

require(__dir__ . '/vendor/autoload.php');

use \Edu\Iu\Uits\KnowledgeBase\Provider\Filesystem\Filesystem;

$provider = new Filesystem(__dir__ . '/kbCache/');

Web

The Web class is used to load data from the Knowledge Base REST API. It requires credentials to authenticate to the REST API.

require(__dir__ . '/vendor/autoload.php');

use \Edu\Iu\Uits\KnowledgeBase\Provider\Web\Web;

$provider = new Web('https://rest.kb.iu.edu', 'username', 'password');

Instantiating the KB class

require(__dir__ . '/vendor/autoload.php');

use \Edu\Iu\Uits\KnowledgeBase\KnowledgeBase;
use \Edu\Iu\Uits\KnowledgeBase\Provider\Web\Web;

$provider = new Web('https://rest.kb.iu.edu', 'username', 'password');

$kb = new KnowledgeBase($provider);

Caching

In previous versions caching was built into the main class, but the resulting implementation was quite messy. It also forced users to use a cache even if they did not want to. Caching is now provided by a separate intermediate provider.

The cache class requires a provider, a cache object, and a TTL. The default time for the TTL is 3600 seconds.

Also note that the Caching provider will also cache search results. It will always refresh the search result cache after the TTL though as there is no way to check if the search results have changed.

require(__dir__ . '/vendor/autoload.php');

use \Doctrine\Common\Cache\ApcuCache;
use \Edu\Iu\Uits\KnowledgeBase\KnowledgeBase;
use \Edu\Iu\Uits\KnowledgeBase\Provider\{
    Caching\Caching,
    Web\Web,
};

$kb_provider = new Web('https://rest.kb.iu.edu', 'username', 'password');
$cache = new ApucCache();
$provider = new Caching($kb_provider, $cache);

$kb = new KnowledgeBase($provider);

Fetching a document

$doc = $kb->getDocument('rest');
echo $doc->getContent();

Searching the KB

$search = $kb->getSearch('outlook');
foreach ($search->getResults() as $result) {
    echo "[{$result->getDocid()}] {$result->getTitle()}" . PHP_EOL;
}

Contributing

Contributions are welcome in the form of a github pull request. Note, for consistency sake, please run composer check and composer run-tests on any code you wish to contribute to this project and fix and resolve any issues found.

统计信息

  • 总下载量: 64
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-06-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固