naoned/oai-pmh-server-bundle

Symfony2 的扩展包,提供数据 Oai-Pmh 服务器

0.0.2 2017-03-14 10:12 UTC

This package is not auto-updated.

Last update: 2024-09-18 09:42:36 UTC


README

关于

提供数据 Oai-Pmh 服务器以供您使用。这只是一个 Oai-Pmh 服务器,您需要自己提供数据提供者。

特性

限制

  • 不支持集合列表上的恢复(通过标记)
  • 更多数据格式(目前仅支持 Dublin Core)

安装

在您的 composer.json 中需要 naoned/OaiPmhServer 包,并更新依赖项。

$ composer require naoned/OaiPmhServer:*

将 NaonedOaiPmhServerBundle 添加到应用程序的内核

    public function registerBundles()
    {
        $bundles = array(
            ...
            new Naoned\OaiPmhServer\NaonedOaiPmhServerBundle(),
            ...
        );
        ...
    }

配置

添加到您的 config.yml

naoned_oai_pmh_server:
    data_provider_service_name: naoned.oaipmh.data_provider
    count_per_load: 50

您可以选择具有恢复的列表中的记录和集合数量

添加到您的 routing.yml

naoned_oai_pmh_server:
    resource: "@NaonedOaiPmhServerBundle/Resources/config/routing.yml"
    prefix:   /oaipmh

您可以选择指向您的 Oai-Pmh 服务器的路由

添加到您的 services.yml 在您的自己的 Bundle(管理数据)中,添加一个服务以公开数据

    naoned.oaipmh.data_provider:
        class: [YOUR_VENDOR]\[YOUR_BUNDLE]\[YOUR_PATH]\[YOUR_CLASS]
        calls:
            - [ setContainer, ["@service_container"] ]

创建数据提供者

提供数据取决于您。这就是为什么您必须定义一个服务。为此,您可以在自己的端创建一个基于此示例的类

namespace [YOUR_VENDOR]\[YOUR_BUNDLE]\[YOUR_PATH];

use Naoned\OaiPmhServerBundle\DataProvider\DataProviderInterface;
use Symfony\Component\DependencyInjection\ContainerAware;

class [YOUR_CLASS] extends ContainerAware implements DataProviderInterface
{
    /**
     * @return string Repository name
     */
    public function getRepositoryName()
    {
        return 'My super Oai-Pmh Server';
    }

    /**
     * @return string Repository admin email
     */
    public function getAdminEmail()
    {
        return 'me@home.com';
    }

    /**
     * @return \DateTime|string     Repository earliest update change on data
     */
    public function getEarliestDatestamp()
    {
        return "2015-01-01";
    }

    /**
     * @param  string $identifier [description]
     * @return array
     */
    public function getRecord($identifier)
    {
        return array(
            'title'       => 'Dummy content',
            'description' => 'Some more dummy content',
            'sets'        => array('seta', 'setb'),
        );
    }

    /**
     * must return an array of arrays with keys «identifier» and «name»
     * @return array List of all sets, with identifier and name
     */
    public function getSets()
    {
        return array(
            array(
                'identifier' => 'seta',
                'name'       => 'THE set number A',
            ),
            array(
                'identifier' => 'setb',
                'name'       => 'THE set identified by B',
            )
        );
    }

    /**
     * Search for records
     * @param  String|null    $setTitle Title of wanted set
     * @param  \DateTime|null $from     Date of last change «from»
     * @param  \DataTime|null $until    Date of last change «until»
     * @return array|ArrayObject        List of items
     */
    public function getRecords($setTitle = null, \DateTime $from = null, \DataTime $until = null)
    {
        return array(
            array(
                'identifier'  => '1W1',
                'title'       => 'Dummy content 1',
                'description' => 'Some more dummy content',
                'last_change' => '2015-10-12',
                'sets'        => array('seta', 'setb'),
            ),
            array(
                'identifier'  => '1W2',
                'title'       => 'Dummy content 2',
                'description' => 'Some more dummy content',
                'last_change' => '2015-10-12',
                'sets'        => array('seta'),
            ),
            array(
                'identifier'  => '1W3',
                'title'       => 'Dummy content 3',
                'description' => 'Some more dummy content',
                'last_change' => '2015-10-12',
                'sets'        => array('seta'),
            ),
            array(
                'identifier'  => '1W4',
                'title'       => 'Dummy content 4',
                'description' => 'Some more dummy content',
                'last_change' => '2015-10-12',
                'sets'        => array('setc'),
            ),
            array(
                'identifier'  => '1W5',
                'title'       => 'Dummy content 5',
                'description' => 'Some more dummy content',
                'last_change' => '2015-10-12',
                'sets'        => array('setd'),
            ),
        );
    }

    /**
     * Tell me, this «record», in which «set» is it ?
     * @param  any   $record An item of elements furnished by getRecords method
     * @return array         List of sets, the record belong to
     */
    public function getSetsForRecord($record)
    {
        return $record['sets'];
    }

    /**
     * Transform the provided record in an array with Dublin Core, «dc_title»  style
     * @param  any   $record An item of elements furnished by getRecords method
     * @return array         Dublin core data
     */
    public static function dublinizeRecord($record)
    {
        return array(
            'dc_identifier'  => $record['identifier'],
            'dc_title'       => $record['title'],
            'dc_description' => $record['description'],
        );
    }

    /**
     * Check if sets are supported by data provider
     * @return boolean check
     */
    public function checkSupportSets()
    {
        return true;
    }

    /**
     * Get identifier of id
     * @param  any   $record An item of elements furnished by getRecords method
     * @return string        Record Id
     */
    public static function getRecordId($record)
    {
        return $record['identifier'];
    }

    /**
     * Get last change date
     * @param  any   $record An item of elements furnished by getRecords method
     * @return \DateTime|string     Record last change
     */
    public static function getRecordUpdated($record)
    {
        return $record['last_change'];
    }
}

如果您使用 Symfony >= 2.8,请使用 ContainerAwareTrait 而不是扩展 ContainerAware

namespace [YOUR_VENDOR]\[YOUR_BUNDLE]\[YOUR_PATH];

use Naoned\OaiPmhServerBundle\DataProvider\DataProviderInterface
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class [YOUR_CLASS] implements DataProviderInterface
{
    use ContainerAwareTrait;

    ...
}

当然,您必须根据任何内容实现数据检索:数据库(Sql)、映射器(Doctrine、Pomm)或任何其他数据存储(ElasticSearch …)。这就是为什么我使此类容器感知,但您可以通过设置器设置所需的服务。

此外,列表(记录和集合)可以作为 ArrayObjects 发送,以便在其他实现 \ArrayObject 的类中管理数据调用。