ck/php-marcspec

基于PHP的MARCspec解析器和验证器

2.0.3 2017-12-12 08:18 UTC

This package is auto-updated.

Last update: 2024-09-15 20:20:33 UTC


README

Build Status

PHP MARCspec解析器和验证器。

有关目前支持的MARCspec - 一个通用的MARC记录路径语言的版本,请参阅http://marcspec.github.io/

安装

可以通过使用composer来安装。只需运行

composer require ck/php-marcspec

PHP-MARCspec需要PHP 5.4或更高版本。

用法

<?php

require("vendor/autoload.php");

use CK\MARCspec\MARCspec;
use CK\MARCspec\Field;
use CK\MARCspec\Subfield;
use CK\MARCspec\ComparisonString;
use CK\MARCspec\SubSpec;

// parse and access MARCspec like an array
$fixed = new MARCspec('007[0]/1-8{/0=\a}');

$fixed['field'];                                                   // CK\MARCspec\FieldInterface
echo $fixed['field']['tag'];                                       // '007'
echo $fixed['field']['charStart'];                                 // 1
echo $fixed['field']['charEnd'];                                   // 8
echo $fixed['field']['charLength'];                                // 8
$fixed['field']['subSpecs'][0]['leftSubTerm'];                     // CK\MARCspec\MARCspecInterface
echo $fixed['field']['subSpecs'][0]['leftSubTerm'];                // '007[0]/0'
echo $fixed['field']['subSpecs'][0]['operator'];                   // '='
$fixed['field']['subSpecs'][0]['rightSubTerm'];                    // CK\MARCspec\ComparisonStringInterface
echo $fixed['field']['subSpecs'][0]['rightSubTerm'];               // '\a'
echo $fixed['field']['subSpecs'][0]['rightSubTerm']['comparable']; // 'a'
$fixed;                                                            // CK\MARCspec\MARCspecInterface
echo $fixed;                                                       // '007[0]/1-8{007[0]/0=\a}'

$variable = new MARCspec('245^1');

echo $variable['field']['tag'];          // '245'
echo $variable['indicator'];             // CK\MARCspec\IndicatorInterface
echo $variable['indicator']['position']; // '1'
$variable;                               // CK\MARCspec\MARCspecInterface
echo $variable;                          // '245^1'

$complex = new MARCspec('020$a{$q[0]~\pbk}{$c/0=\€|$c/0=\$}');

echo $complex['field']['tag'];        // '020'
$complex['subfields'];                // Array
$complex['subfields'][0]['tag'];      // CK\MARCspec\SubfieldInterface
echo $complex['subfields'][0]['tag']; // 'a'

$complex['a'][0]['subSpecs'][0]['leftSubTerm'];                     // CK\MARCspec\MARCspecInterface
echo $complex['a'][0]['subSpecs'][0]['leftSubTerm'];                // '020$q[0]'
echo $complex['a'][0]['subSpecs'][0]['operator'];                   // '~'
$complex['a'][0]['subSpecs'][0]['rightSubTerm'];                    // CK\MARCspec\ComparisonStringInterface
echo $complex['a'][0]['subSpecs'][0]['rightSubTerm']['comparable']; // 'pbk'

echo $complex['a'][0]['subSpecs'][1][0]['leftSubTerm'];                       // '020$c/0'
echo $complex['a'][0]['subSpecs'][1][0]['leftSubTerm']['c'][0]['charStart'];  // 0
echo $complex['a'][0]['subSpecs'][1][0]['leftSubTerm']['c'][0]['charEnd'];    // 0
echo $complex['a'][0]['subSpecs'][1][0]['leftSubTerm']['c'][0]['charLength']; // 1
echo $complex['a'][0]['subSpecs'][1][0]['operator'];                          // '='
echo $complex['a'][0]['subSpecs'][1][0]['rightSubTerm']['comparable'];        // '€'

echo $complex['a'][0]['subSpecs'][1][1]['leftSubTerm'];                       // '020$c/0'
echo $complex['a'][0]['subSpecs'][1][1]['leftSubTerm']['c'][0]['charStart'];  // 0
echo $complex['a'][0]['subSpecs'][1][1]['leftSubTerm']['c'][0]['charEnd'];    // 0
echo $complex['a'][0]['subSpecs'][1][1]['leftSubTerm']['c'][0]['charLength']; // 1
echo $complex['a'][0]['subSpecs'][1][1]['operator'];                          // '='
echo $complex['a'][0]['subSpecs'][1][1]['rightSubTerm']['comparable'];        // '$'

// creating MARCspec

// creating a new Field
$Field = new Field('...');

// creating a new MARCspec by setting the Field
$MARCspec = MARCspec::setField($Field);

// creating a new Subfield
$Subfield = new Subfield('a');

// adding the Subfield to the MARCspec
$MARCspec->addSubfields($Subfield);

// creating instances of MARCspec and ComparisonString
$LeftSubTerm = new MARCspec('...$a/#');
$RightSubTerm = new ComparisonString(',');

// creating a new SubSpec with instances above and an operator '='
$SubSpec = new SubSpec($LeftSubTerm,'=',$RightSubTerm);

// adding the SubSpec to the Subfield
$Subfield['subSpecs'] = $SubSpec;

// whole MARCspec
echo $MARCspec; // '...[0]$a{...$a/#-#=\,}' 

ArrayAccess与方法

MARCspec可以通过以下偏移量或对应的方法(请参阅源代码以了解所有方法的文档)进行访问,就像一个不可变的数组。

MARCspec实例

字段实例

子字段实例

指示符实例

比较字符串实例

子规范实例