Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for php8.x #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions File/MARC.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ function __construct($source, $type = self::SOURCE_FILE, $record_class = null)
}
break;

case self::SOURCE_STRING:
case self::SOURCE_STRING :
$this->type = self::SOURCE_STRING;
if ($source===null)
$this->source=[];
else
$this->source = explode(File_MARC::END_OF_RECORD, $source);

break;

default:
Expand All @@ -196,7 +200,9 @@ function nextRaw()
$record = preg_replace('/^[\\x0a\\x0d\\x00]+/', "", $record);

} elseif ($this->type == self::SOURCE_STRING) {

$record = array_shift($this->source);

}

// Exit if we are at the end of the file
Expand Down Expand Up @@ -318,9 +324,9 @@ private function _decode($text)
if (!is_numeric($offset)) {
$offset = 0;
}

if ($tag===null) $tag='';
// Check directory validity
if (!preg_match("/^[0-9A-Za-z]{3}$/", $tag)) {
if ( !preg_match("/^[0-9A-Za-z]{3}$/", $tag)) {
$marc->addWarning(File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_DIRECTORY_TAG], array("tag" => $tag)));
}
if (!preg_match("/^\d{4}$/", $len)) {
Expand Down
4 changes: 3 additions & 1 deletion File/MARC/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ function key(): int
if ($this->current() instanceof File_MARC_Field) {
return $this->current()->getTag();
} elseif ($this->current() instanceof File_MARC_Subfield) {
return $this->current()->getCode();
if (!is_int( $this->current()->getCode())) return ord($this->current()->getcode());
else
return $this->current()->getCode();
}
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion File/MARC/Subfield.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ function setPosition($pos)
function isEmpty()
{
// There is data
if (strlen($this->data)) {
if ($this->data===null) return true;
if ( strlen($this->data)) {
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions tests/marc_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ $marc_file = new File_MARC($dir . '/' . 'example.mrc');

if ($marc_record = $marc_file->next()) {
foreach ($marc_record->getFields() as $tag=>$value) {
print "$tag: ";
//print "$tag: ";
print $value->gettag().': ';
if ($value instanceof File_MARC_Control_Field) {
print $value->getData();
}
else {
foreach ($value->getSubfields() as $code=>$subdata) {
print "_$code";
print "_".$subdata->getcode();
}
}
print "\n";
Expand Down
5 changes: 3 additions & 2 deletions tests/marc_list_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ echo $list->count() . " nodes\n";
// Check key method
echo "---\n";
$list->rewind();
echo 'Key (field): ' . $list->key() . "\n";
echo 'Key (field): ' . str_pad((string)$list->key(),3,'0',STR_PAD_LEFT) . "\n";

$subfield = new File_MARC_Subfield( 'a', 'test' );
$list->prependNode( $subfield );
$list->rewind();
echo 'Key (subfield): ' . $list->key(). "\n";
// when we call key() method directly we must to use chr to get the int index as char
echo 'Key (subfield): ' . chr($list->key()). "\n";
?>
--EXPECT--
0: 002 00002
Expand Down