Commit 447806cc authored by David Maus's avatar David Maus
Browse files

Adjust directory structure for package delivery via Composer

Also includes cosmetic fixes wrt coding-style.
parent 2e0658fb
.build *~
dist \#*
.tmp .\#*
nbproject
review
vendor
\#*#
.#*#
TAGS TAGS
ChangeLog
vendor
review
build
syntax: glob
.build
.dist
nbproject
review
tmp
vendor
\#*#
.#*#
TAGS
<project name="local" default="help">
<target name="help">
<echo message="This component has no local build targets." />
</target>
</project>
<!-- vim: set tabstop=2 shiftwidth=2 expandtab: -->
project.name=PicaRecord
project.channel=hab20.hab.de/service/pear
project.majorVersion=0
project.minorVersion=4
project.patchLevel=0
project.snapshot=false
component.type=php-library
component.version=11
This diff is collapsed.
{
"name": "hab/pica-record",
"description": "Object oriented interface to Pica+ records, fields, and subfields",
"type": "library",
"license": "GPL-3.0+",
"authors": [
{
"name": "David Maus",
"email": "maus@hab.de",
"role": "Developer"
}
],
"support": {
"email": "maus@hab.de"
}
}
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.9.1" version="2.0"
xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd
http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
<name>${project.name}</name>
<channel>${project.channel}</channel>
<summary>Object oriented interface to Pica+ records</summary>
<description>
PicaRecord provides an object oriented interface to Pica+ records, fields, and subfields.
</description>
<lead>
<name>David Maus</name>
<user>dmaus</user>
<email>maus@hab.de</email>
<active>yes</active>
</lead>
<date>${build.date}</date>
<time>${build.time}</time>
<version>
<release>${project.version}</release>
<api>${project.majorVersion}.${project.minorVersion}</api>
</version>
<stability>
<release>${project.stability}</release>
<api>stable</api>
</stability>
<license>GNU General Public License v3</license>
<notes>
The PicaRecord package does not provide the means to read or write Pica+ records. In order to do so you need to install the packages PicaReader and PicaWriter that are available via this PEAR channel, too.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
${contents}
</dir>
</contents>
<dependencies>
<required>
<php>
<min>5.3.0</min>
</php>
<pearinstaller>
<min>1.9.4</min>
</pearinstaller>
<package>
<name>Autoloader</name>
<channel>pear.phix-project.org</channel>
<min>3.0.0</min>
<max>3.999.9999</max>
</package>
</required>
</dependencies>
<phprelease />
<changelog>
<release>
<version>
<release>0.4.0</release>
<api>0.4</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2013-01-10</date>
<license>GNU General Public License v3</license>
<notes>
* allow empty subfield values (031N $6)
</notes>
</release>
<release>
<version>
<release>0.3.2</release>
<api>0.3</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2013-01-10</date>
<license>GNU General Public License v3</license>
<notes>
* remove hard dependency to Autoloader
</notes>
</release>
<release>
<version>
<release>0.3.1</release>
<api>0.3</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2012-04-17</date>
<license>GNU General Public License v3</license>
<notes>
* fix getFields() with selector in NestedRecord
</notes>
</release>
<release>
<version>
<release>0.3.0</release>
<api>0.3</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2012-03-05</date>
<license>GNU General Public License v3</license>
<notes>
* PicaRecord is now E_STRICT compliant
* add Record::getFirstMatchingField(), return first field matching a selector
* add Field::getNthSubfield(), return the nth subfield with a specified code
</notes>
</release>
<release>
<version>
<release>0.2.0</release>
<api>0.2</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2012-02-17</date>
<license>GNU General Public License v3</license>
<notes>
* add Record::getMaximumOccurrenceOf(), return maximum occurrence value of field identified by tag
* fix the inline documentation
</notes>
</release>
<release>
<version>
<release>0.1.0</release>
<api>0.1</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2012-02-15</date>
<license>GNU General Public License v3</license>
<notes>
Initial release.
</notes>
</release>
</changelog>
</package>
<!-- vim: set tabstop=2 shiftwidth=2 expandtab: -->
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="tests/bootstrap.php" strict="true">
<testsuites>
<testsuite name="Unit Tests">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">vendor</directory>
<directory suffix=".php">tests</directory>
</blacklist>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">bin</directory>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="review/code-coverage"/>
</logging>
</phpunit>
<?xml version="1.0"?>
<phpunit bootstrap="src/tests/unit-tests/bootstrap.php">
<testsuites>
<testsuite name="Unit Tests">
<directory suffix="Test.php">src/tests/unit-tests</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">vendor</directory>
<directory suffix=".php">src/tests</directory>
</blacklist>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/bin</directory>
<directory suffix=".php">src/php</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="review/code-coverage"/>
<log type="coverage-clover" target="review/logs/phpunit.xml"/>
<log type="json" target="review/logs/phpunit.json"/>
<log type="tap" target="review/logs/phpunit.tap"/>
<log type="junit" target="review/logs/phpunit-junit.xml"/>
<log type="testdox-html" target="review/testdox.html"/>
<log type="testdox-text" target="review/testdox.txt"/>
</logging>
</phpunit>
<!-- vim: set tabstop=4 shiftwidth=4 expandtab: -->
<?php
/**
* Pica+ AuthorityRecord.
*
* This file is part of PicaRecord.
*
* PicaRecord is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PicaRecord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PicaRecord. If not, see <http://www.gnu.org/licenses/>.
*
* @package PicaRecord
* @author David Maus <maus@hab.de>
* @copyright Copyright (c) 2012, 2013 by Herzog August Bibliothek Wolfenbüttel
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3
*/
namespace HAB\Pica\Record;
use InvalidArgumentException;
class AuthorityRecord extends Record
{
/**
* Append a field to the record.
*
* @see Record::append()
*
* @throws InvalidArgumentException Field level other than 0
* @throws InvalidArgumentException Field already in record
*
* @param Field $field Field to append
* @return void
*/
public function append (Field $field)
{
if ($field->getLevel() !== 0) {
throw new InvalidArgumentException("Invalid field level {$field->getLevel()}");
}
return parent::append($field);
}
/**
* Return the Pica production number (record identifier).
*
* @return string|null Pica production number or NULL if none exists
*/
public function getPPN ()
{
$ppnField = $this->getFirstMatchingField('003@/00');
if ($ppnField) {
$ppnSubfield = $ppnField->getNthSubfield('0', 0);
if ($ppnSubfield) {
return $ppnSubfield->getValue();
}
}
return null;
}
/**
* Set the Pica production number.
*
* Create a field 003@/00 if necessary.
*
* @param string $ppn Pica production number
* @return void
*/
public function setPPN ($ppn)
{
$ppnField = $this->getFirstMatchingField('003@/00');
if ($ppnField) {
$ppnSubfield = $ppnField->getNthSubfield('0', 0);
if ($ppnSubfield) {
$ppnSubfield->setValue($ppn);
} else {
$ppnField->append(new Subfield('0', $ppn));
}
} else {
$this->append(new Field('003@', 0, array(new Subfield('0', $ppn))));
}
}
/**
* Return TRUE if the record is valid.
*
* A valid authority record MUST have exactly one valid PPN field
* (003@/00$0) and exactly one type field (002@/0$0) with a type indicator
* `T'.
*
* @see AuthorityRecord::checkPPN();
* @see AuthorityRecord::checkType();
*
* @return boolean TRUE if the record is valid
*/
public function isValid ()
{
return parent::isValid() && $this->checkPPN() && $this->checkType();
}
/**
* Return true if the record has exactly one PPN field (003@/00) with a
* subfield $0.
*
* @return boolean True if the record has a valid PPN field
*/
protected function checkPPN ()
{
$ppnField = $this->getFields('003@/00');
if (count($ppnField) === 1) {
$ppnSubfield = reset($ppnField)->getNthSubfield('0', 0);
if ($ppnSubfield) {
return true;
}
}
return false;
}
/**
* Return true if the record has exactly one type field (002@/00) with a
* subfield $0 whose first character is `T'.
*
* @return boolean True if the record has a valid type field
*/
protected function checkType ()
{
$typeField = $this->getFields('002@/00');
if (count($typeField) === 1) {
$typeSubfield = reset($typeField)->getNthSubfield('0', 0);
if ($typeSubfield) {
$typeCode = $typeSubfield->getValue();
if ($typeCode === 'T') {
return true;
}
}
}
}
}
\ No newline at end of file
<?php
/**
* Pica+ CopyRecord.
*
* This file is part of PicaRecord.
*
* PicaRecord is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PicaRecord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PicaRecord. If not, see <http://www.gnu.org/licenses/>.
*
* @package PicaRecord
* @author David Maus <maus@hab.de>
* @copyright Copyright (c) 2012, 2013 by Herzog August Bibliothek Wolfenbüttel
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3
*/
namespace HAB\Pica\Record;
use InvalidArgumentException;
class CopyRecord extends Record
{
/**
* The item number.
*
* @var integer
*/
protected $_itemNumber;
/**
* Append a field to the copy record.
*
* You can only append field of level 2 to a copy record.
*
* @see Record::append()
*
* @throws InvalidArgumentException Field level other than 2
* @throws InvalidArgumentException Item number mismatch
* @throws InvalidArgumentException Field already in record
*
* @param Field $field Field to append
* @return void
*/
public function append (Field $field)
{
if ($field->getLevel() !== 2) {
throw new InvalidArgumentException("Invalid field level: {$field->getLevel()}");
}
if ($this->getItemNumber() === null) {
$this->setItemNumber($field->getOccurrence());
}
If ($field->getOccurrence() != $this->getItemNumber()) {
throw new InvalidArgumentException("Item number mismatch: {$this->getItemNumber()}, {$field->getOccurrence()}");
}
return parent::append($field);
}
/**
* Return the item number.
*
* @return integer|null Item number
*/
public function getItemNumber ()
{
return $this->_itemNumber;
}
/**
* Set the item number.
*
* @param integer $itemNumber Item number
* @return void
*/
protected function setItemNumber ($itemNumber)
{
$this->_itemNumber = (int)$itemNumber;
}
/**
* Return the exemplar production number (EPN).
*
* @return string Exemplar production number
*/
public function getEPN ()
{
$epnField = $this->getFirstMatchingField('203@');
if ($epnField) {
$epnSubfield = $epnField->getNthSubfield('0', 0);
if ($epnSubfield) {
return $epnSubfield->getValue();
}
}
return null;
}
/**
* Set the exemplar production number (EPN).
*
* Create a field 203@ if necessary.
*
* @param string $epn Exemplar production number
* @return void
*/
public function setEPN ($epn)
{
$epnField = $this->getFirstMatchingField('203@');
if ($epnField) {
$epnSubfield = $epnField->getNthSubfield('0', 0);
if ($epnSubfield) {
$epnSubfield->setValue($epn);
} else {
$epnField->append(new Subfield('0', $epn));
}
} else {
$this->append(new Field('203@', $this->getItemNumber(), array(new Subfield('0', $epn))));
}
}
/**
* Set the containing local record.
*
* @param LocalRecord $record Local record
* @return void
*/
public function setLocalRecord (LocalRecord $record)
{
$this->unsetLocalRecord();
if (!$record->containsCopyRecord($this)) {
$record->addCopyRecord($this);
}
$this->_parent = $record;
}
/**
* Unset the containing local record.
*
* @return void
*/
public function unsetLocalRecord ()
{
if ($this->_parent) {
if ($this->_parent->containsCopyRecord($this)) {
$this->_parent->removeCopyRecord($this);
}
$this->_parent = null;
}
}
/**
* Return the containing local record.
*
* @return LocalRecord|null
*/
public function getLocalRecord ()
{
return $this->_parent;
}
}
\ No newline at end of file
<?php
/**
* Pica+ Field.
*
* This file is part of PicaRecord.
*
* PicaRecord is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PicaRecord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PicaRecord. If not, see <http://www.gnu.org/licenses/>.
*
* @package PicaRecord
* @author David Maus <maus@hab.de>
* @copyright Copyright (c) 2012, 2013 by Herzog August Bibliothek Wolfenbüttel
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3
*/
namespace HAB\Pica\Record;
use InvalidArgumentException;
class Field
{
/**
* Regular expression matching a valid Pica+ field tag.
*
* @var string
*/
const TAG_RE = '|^[012][0-9]{2}[A-Z@]$|D';
/**
* Return TRUE if argument is a valid field tag.
*
* @param mixed $arg Variable to check