Grima  2018-08
Whispering into Alma's ear
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
ISO2709Record Class Reference
Inheritance diagram for ISO2709Record:
MARC21Record

Public Member Functions

  __construct ()
 
  isTagValid ( $tag)
 
  assertTagValid ( $tag)
 
  isTagRepeatable ( $tag)
 
  assertTagRepeatable ( $tag)
 
  tagOrder ( $a, $b)
 
  assertTagOrder ( $a, $b)
 
  exception ( $string)
 
  loadFromBinaryStream ( $filehandle)
 
  setLeader ( $string)
 
  loadFromBinaryString ( $string, $fuzzy=true)
 
  DataNotInDirectory ()
 
  loadFromString ( $string)
 
  ParseBinaryField ( $tag, $data, $directoryEntry)
 
  AppendFieldBinary ( $tag, $data, $directoryEntry=array(), $reorder=false)
 
  CheckField ( $field)
 
  AppendField ( $field, $reorder=false)
 
  removeField ( $field)
 
  delFields ( $tag)
 
  getFields ( $tag)
 
  getTagPattern ( $patt)
 
  AsBinaryString ()
 
  AsMnemonicString ( $leader_tag="LDR", $field_initiator="=", $tag_terminator=" ", $identifier_initiator="\, $field_terminator="\\", $record_terminator="\\", $space_replacer=" ")
 

Public Attributes

  $leader
 
  $fields
 
  $exceptions
 
  $raw
 
  $indicatorLength
 

Protected Member Functions

  set_default ( $name, $value)
 

Protected Attributes

  $identifierLength
 
  $defaults
 

Private Member Functions

  checkString ( $name, $trueValue, $string, $start=0, $length=false, $default=false)
 

Detailed Description

Definition at line 129 of file ISO2709.php.

Constructor & Destructor Documentation

◆ __construct()

ISO2709Record::__construct ( )

Definition at line 143 of file ISO2709.php.

143  {
144  $this->set_default( "identifierLength", 0 ); // required, so if not available disable subfields
145  $this->set_default( "indicatorLength", 0 ); // advisory only
146  $this->set_default( "lengthOfLengthOfField", 4 ); // required, but no real default; use MARC21
147  $this->set_default( "lengthOfStartingCharacterPosition", 5 ); // required, but no real default; use MARC21
148  $this->set_default( "lengthOfImplementationDefined", 0 ); // required, it seems like 0 is the only sensible value; use MARC21
149  $this->leader = "";
150  $this->fields = array();
151  $this->exceptions = array();
152  }
set_default( $name, $value)
Definition: ISO2709.php:138

Member Function Documentation

◆ AppendField()

ISO2709Record::AppendField (   $field,
  $reorder = false 
)

Definition at line 435 of file ISO2709.php.

435  {
436  $this->checkField( $field );
437  $field->record = $this;
438 
439  # Check for valid ordering
440  $numTags = count( $this->fields );
441  if( $numTags > 0 ) {
442  if( $reorder === false ) {
443  $lastTag = $this->fields[ $numTags - 1 ]->tag;
444  #$this->assertTagOrder( $lastTag, $field->tag );
445  $appendAfter = $numTags;
446  } else {
447  for( $i = $numTags - 1 ; $i >= 0 ; $i-- ) {
448  $lastTag = $this->fields[ $i ]->tag;
449  if( $this->tagOrder( $lastTag, $field->tag ) <= 0 ) {
450  #print "Append {$field->tag} after $lastTag \n";
451  break;
452  }
453  #print "Do not {$field->tag} after $lastTag \n";
454  }
455  $appendAfter = $i;
456  }
457  } else { $appendAfter = -1; }
458 
459  array_splice( $this->fields, $appendAfter+1, 0, array( $field ) );
460  }
tagOrder( $a, $b)
Definition: ISO2709.php:196

◆ AppendFieldBinary()

ISO2709Record::AppendFieldBinary (   $tag,
  $data,
  $directoryEntry = array(),
  $reorder = false 
)

Definition at line 412 of file ISO2709.php.

412  {
413  $field = $this->ParseBinaryField( $tag, $data, $directoryEntry );
414  $this->AppendField( $field, $reorder );
415  }
AppendField( $field, $reorder=false)
Definition: ISO2709.php:435
ParseBinaryField( $tag, $data, $directoryEntry)
Definition: ISO2709.php:384

◆ AsBinaryString()

ISO2709Record::AsBinaryString ( )

Definition at line 497 of file ISO2709.php.

References ISO2709\FieldTerminator, ISO2709\RecordTerminator, and ISO2709\SubfieldInitiator.

497  {
498  // We now ignore the leader as much as possible
499  $indicatorLength = $this->indicatorLength; // advisory, we will write corrupt files if requested
501  $lengthOfLengthOfField = $this->checkString( "Length of Length-Of-Field portion of directory entry", false, $this->leader, 20, 1, $this->defaults["lengthOfLengthOfField"] );
502  $lengthOfStartingCharacterPosition = $this->checkString( "Length of Starting-Character-Position portion of directory entry", false, $this->leader, 21, 1, $this->defaults["lengthOfStartingCharacterPosition"] );
503  $lengthOfImplementationDefined = $this->checkString( "Length of Implementation-Defined portion of directory entry", false, $this->leader, 22, 1, $this->defaults["lengthOfImplementationDefined"] );
504  $lengthOfDirectoryEntry = 3 + $lengthOfLengthOfField + $lengthOfStartingCharacterPosition + $lengthOfImplementationDefined;
505 
506  $directory = "";
507  $data = "";
508  $baseAddressOfData = 24 + $lengthOfDirectoryEntry * count( $this->fields ) + 1;
509  foreach( $this->fields as $v ) {
510  $tag = $v->tag;
511  $start = strlen( $data );
512  $data .= $v->indicators;
513  foreach( $v->subfields as $vv ) {
514  $data .= ISO2709::SubfieldInitiator . $vv->identifier . $vv->data;
515  }
516  $data .= $v->data;
517  $data .= ISO2709::FieldTerminator;
518  $length = strlen($data) - $start;
519  $impdef = $v->directoryEntry[3];
520  $directory .= sprintf(
521  "%3.3s" .
522  "%0{$lengthOfLengthOfField}.{$lengthOfLengthOfField}d" .
523  "%0{$lengthOfStartingCharacterPosition}.{$lengthOfStartingCharacterPosition}d" .
524  "%{$lengthOfImplementationDefined}.{$lengthOfImplementationDefined}s",
525  $tag, $length, $start, $impdef );
526  }
527  $directory .= ISO2709::FieldTerminator;
528  $data .= ISO2709::RecordTerminator;
529  $recordLength = $baseAddressOfData + strlen($data);
530  $leader = sprintf("%05.5d%1.1s%4.4s%1.1d%1.1d%05.5d%3.3s%1.1d%1.1d%1.1d%1.1s",
531  $recordLength, substr( $this->leader, 5, 1 ),
532  substr( $this->leader, 6, 4), $indicatorLength,
533  $identifierLength, $baseAddressOfData, substr( $this->leader, 17, 3 ),
534  $lengthOfLengthOfField,
535  $lengthOfStartingCharacterPosition,
536  $lengthOfImplementationDefined, substr( $this->leader, 23, 1 ) );
537  $this->leader = $leader;
538  $ret = $leader . $directory . $data;
539  assert( strlen( $leader ) + strlen( $directory ) === $baseAddressOfData );
540  assert( strlen( $ret ) === $recordLength );
541  return $ret;
542  }
$identifierLength
Definition: ISO2709.php:134
const RecordTerminator
Definition: ISO2709.php:121
const FieldTerminator
Definition: ISO2709.php:122
checkString( $name, $trueValue, $string, $start=0, $length=false, $default=false)
Definition: ISO2709.php:238
const SubfieldInitiator
Definition: ISO2709.php:123
$indicatorLength
Definition: ISO2709.php:134

◆ AsMnemonicString()

ISO2709Record::AsMnemonicString (   $leader_tag = "LDR",
  $field_initiator = "=",
  $tag_terminator = "  ",
  $identifier_initiator = "\$",
  $field_terminator = "\r\n",
  $record_terminator = "\r\n",
  $space_replacer = " " 
)

Definition at line 550 of file ISO2709.php.

558  {
559  $ret = array();
560  $ret[] = sprintf( "%s%3.3s%s%s%s%s%s", $field_initiator, $leader_tag,
561  $tag_terminator, "", "", $this->leader, $field_terminator );
562  foreach( $this->fields as $v ) {
563  $ret[] = $v->AsMnemonicString( $field_initiator,$tag_terminator,$identifier_initiator,$field_terminator, $space_replacer );
564  }
565  foreach( $this->exceptions as $v ) {
566  $ret[] = sprintf( "%s%3.3s%s%s%s%s%s", $field_initiator, "XXX",
567  $tag_terminator, "xx", "\$x$v", "", $field_terminator );
568  }
569  return implode( $ret ) . $record_terminator;
570  }

◆ assertTagOrder()

ISO2709Record::assertTagOrder (   $a,
  $b 
)

Definition at line 209 of file ISO2709.php.

209  {
210  if( self::tagOrder( $a, $b ) > 0 )
211  $this->exception("ISO2709 4.1: Field 001 is first, followed by 00* in any order, followed by all other tags; hence '$a' cannot precede '$b'");
212  else if( $this->tagOrder( $a, $b ) > 0 )
213  $this->exception("Unknown: '$a' is not supposed to precede '$b'");
214  }
exception( $string)
Definition: ISO2709.php:216
tagOrder( $a, $b)
Definition: ISO2709.php:196

◆ assertTagRepeatable()

ISO2709Record::assertTagRepeatable (   $tag )

Definition at line 181 of file ISO2709.php.

181  {
182  if( !self::isTagRepeatable( $tag ) ) {
183  $this->exception("ISO2709 4.5.1: 001 refers to the record identifier field, which is not repeatable (4.1c)");
184  return false;
185  }
186  if( !$this->isTagRepeatable( $tag ) ) {
187  $this->exception("Unknown: Tag '$tag' is not repeatable.");
188  return false;
189  }
190  return true;
191  }
exception( $string)
Definition: ISO2709.php:216
isTagRepeatable( $tag)
Definition: ISO2709.php:177

◆ assertTagValid()

ISO2709Record::assertTagValid (   $tag )

Definition at line 164 of file ISO2709.php.

164  {
165  if( !self::isTagValid( $tag ) ) {
166  $this->exception("ISO2709 4.5.1: Tags must be alphanumeric, using only one case, and must be 3 bytes long. Thus '$tag' is not allowed.");
167  return false;
168  }
169  if( !$this->isTagValid( $tag ) ) {
170  $this->exception("Unknown: Invalid tag '$tag'");
171  return false;
172  }
173  return true;
174  }
isTagValid( $tag)
Definition: ISO2709.php:160
exception( $string)
Definition: ISO2709.php:216

◆ CheckField()

ISO2709Record::CheckField (   $field )

Definition at line 417 of file ISO2709.php.

417  {
418  if( substr( $field->tag, 0, 2 ) === "00" ) {
419  if( $field->indicators !== "" )
420  $this->exception("ISO2709 4.5.4: Control fields have no indicators, but field '{$field->tag}' has indicators '{$field->indicators}'");
421  if( count( $field->subfields ) > 0 )
422  $this->exception("ISO2709 4.5.4: Control fields have no subfields, but field '{$field->tag}' has " . count( $field->subfields) . " subfields");
423  } else {
424  if( strlen( $field->indicators ) != $this->indicatorLength )
425  $this->exception("ISO2709 4.5.4d: Field '{$field->tag}' has indicators '{$field->indicators}' of the wrong length (specified length is {$this->indicatorLength})");
426  foreach( $field->subfields as $subfield ) {
427  if( strlen( $subfield->identifier ) + 1 != $this->identifierLength )
428  $this->exception("ISO2709: Field '{$field->tag}' has subfield '\${$subfield->identifier}' but that is not the right length of a subfield identifier.");
429  }
430  if( $field->data !== "" and $this->indicatorLength > 0 )
431  $this->exception("ISO2709 4.5.4: Field '{$field->tag}' has data, but should only have subfields");
432  }
433  }
exception( $string)
Definition: ISO2709.php:216

◆ checkString()

ISO2709Record::checkString (   $name,
  $trueValue,
  $string,
  $start = 0,
  $length = false,
  $default = false 
)
private

Definition at line 238 of file ISO2709.php.

238  {
239  $string = ( $length === false ) ? substr( $string, $start ) : substr( $string, $start, $length );
240  if( is_int( $trueValue ) ) {
241  if( !ctype_digit( $string ) or intval( $string ) !== $trueValue )
242  $this->exception(
243  "ISO2709: Value '$string' for \"$name\" does not match computed value '$trueValue'" );
244  } else {
245  if( !ctype_digit( $string ) )
246  $this->exception(
247  "ISO2709: Value '$string' for \"$name\" is not numeric" );
248  }
249  return ctype_digit($string)?intval( $string ):$default;
250  }
exception( $string)
Definition: ISO2709.php:216

◆ DataNotInDirectory()

ISO2709Record::DataNotInDirectory ( )

Definition at line 334 of file ISO2709.php.

References ISO2709\FieldTerminator, and ISO2709\RecordTerminator.

334  {
335  $string = $this->raw;
336  $recordLength = strpos( $string, ISO2709::RecordTerminator ) + 1;
337  $baseAddressOfData = strpos( $string, ISO2709::FieldTerminator )+1;
338  $lengthOfLengthOfField = $this->checkString( "Length of Length-Of-Field portion of directory entry", false, $this->leader, 20, 1, $this->defaults["lengthOfLengthOfField"] );
339  $lengthOfStartingCharacterPosition = $this->checkString( "Length of Starting-Character-Position portion of directory entry", false, $this->leader, 21, 1, $this->defaults["lengthOfStartingCharacterPosition"] );
340  $lengthOfImplementationDefined = $this->checkString( "Length of Implementation-Defined portion of directory entry", false, $this->leader, 22, 1, $this->defaults["lengthOfImplementationDefined"] );
341  $lengthOfDirectoryEntry = 3 + $lengthOfLengthOfField + $lengthOfStartingCharacterPosition + $lengthOfImplementationDefined;
342 
343  $map = str_repeat( "?", $recordLength );
344  for( $i = 24 ; $i+$lengthOfDirectoryEntry+1 <= $baseAddressOfData ; $i+= $lengthOfDirectoryEntry ) {
345  $tag = substr( $string, $i, 3 );
346  $off = intval( substr( $string, $i+3+$lengthOfLengthOfField, $lengthOfStartingCharacterPosition ) );
347  $off = strrpos( substr( $string, 0, $baseAddressOfData + $off ), ISO2709::FieldTerminator ) - $baseAddressOfData + 1;
348 
349  $calclen = 0;
350  $maxFieldLen = intval( "1" .str_repeat( $lengthOfLengthOfField, "0" ) ) - 1;
351  while( substr( $string, $i+3, $lengthOfLengthOfField ) === "000" ) {
352  $i += $lengthOfDirectoryEntry;
353  $calclen += $maxFieldLen;
354  }
355  $len = $calclen + intval( substr( $string, $i+3, $lengthOfLengthOfField ) );
356 
357  for( $j = 0 ; $j < $len ; $j++ ) {
358  $map[$baseAddressOfData+$off+$j] = " ";
359  }
360  $map = substr_replace( $map, $tag, $baseAddressOfData+$off );
361  $map[$baseAddressOfData+$off+$len-1] = "t";
362  }
363  for( $i = 0 ; $i < $recordLength ; $i++ ) {
364  if( $i < 24 ) $map[$i] = "l";
365  else if( $i+1 < $baseAddressOfData ) $map[$i] = "d";
366  else if( $string[$i] == ISO2709::FieldTerminator ) {
367  if($map[$i] != "t") $map[$i]="#";
368  else $map[$i] = "T";
369  }
370  }
371  print $map."\n";
372  }
const RecordTerminator
Definition: ISO2709.php:121
const FieldTerminator
Definition: ISO2709.php:122
checkString( $name, $trueValue, $string, $start=0, $length=false, $default=false)
Definition: ISO2709.php:238

◆ delFields()

ISO2709Record::delFields (   $tag )

Definition at line 469 of file ISO2709.php.

469  {
470  foreach( $this->fields as $k => $v ) {
471  if( $v->tag === $tag ) unset( $this->fields[$k] );
472  }
473  $this->fields = array_values( $this->fields );
474  }

◆ exception()

ISO2709Record::exception (   $string )

Definition at line 216 of file ISO2709.php.

216  {
217  $this->exceptions[] = $string;
218  }

◆ getFields()

ISO2709Record::getFields (   $tag )

Definition at line 476 of file ISO2709.php.

476  {
477  $ret = array();
478  foreach( $this->fields as $v ) {
479  if( $v->tag === $tag ) $ret[] = $v;
480  }
481  return $ret;
482  }

◆ getTagPattern()

ISO2709Record::getTagPattern (   $patt )

Definition at line 484 of file ISO2709.php.

484  {
485  $ret = array();
486  foreach( $this->fields as $v ) {
487  if( preg_match("/$patt/", $v->tag ) ) $ret[] = $v;
488  }
489  return $ret;
490  }

◆ isTagRepeatable()

ISO2709Record::isTagRepeatable (   $tag )

Definition at line 177 of file ISO2709.php.

177  {
178  return ($tag !== "001");
179  }

◆ isTagValid()

ISO2709Record::isTagValid (   $tag )

Definition at line 160 of file ISO2709.php.

160  {
161  return ($tag !== "000") && is_string( $tag ) && ( preg_match('/^[0-9A-Z]{3}$/',$tag) || preg_match('/^[0-9a-z]{3}$/',$tag) );
162  }

◆ loadFromBinaryStream()

ISO2709Record::loadFromBinaryStream (   $filehandle )

Definition at line 225 of file ISO2709.php.

References ISO2709\RecordTerminator.

225  {
226  $peek = stream_get_line( $filehandle, 99999, ISO2709::RecordTerminator );
227  if( $peek ) $peek .= ISO2709::RecordTerminator;
228  else return false;
229  /*
230  $peek = fread( $filehandle, 5 );
231  if( $peek === false ) return false;
232  if( ! ctype_digit( $peek ) ) return false;
233  $peek .= fread( $filehandle, intval( $peek ) - 5 );
234  */
235  return $this->loadFromBinaryString( $peek );
236  }
const RecordTerminator
Definition: ISO2709.php:121
loadFromBinaryString( $string, $fuzzy=true)
Definition: ISO2709.php:258

◆ loadFromBinaryString()

ISO2709Record::loadFromBinaryString (   $string,
  $fuzzy = true 
)

Definition at line 258 of file ISO2709.php.

References ISO2709\FieldTerminator, and ISO2709\RecordTerminator.

258  {
259  $this->leader = substr( $string, 0, 24 );
260  $this->fields = array();
261  $this->exceptions = array();
262  $this->raw = $string;
263 
264  // We now ignore the leader as much as possible
265  $recordLength = strpos( $string, ISO2709::RecordTerminator ) + 1;
266  $baseAddressOfData = strpos( $string, ISO2709::FieldTerminator )+1;
267 
268  $this->checkString( "Record Length", $recordLength, $this->leader, 0, 5 );
269  $indicatorLength = $this->checkString( "Indicator Length", false, $this->leader, 10, 1, $this->defaults["indicatorLength"] );
270  $identifierLength = $this->checkString( "Identifier Length", false, $this->leader, 11, 1, $this->defaults["identifierLength"] );
271  $this->checkString( "Base Address of Data", $baseAddressOfData, $this->leader, 12, 5 );
272  $lengthOfLengthOfField = $this->checkString( "Length of Length-Of-Field portion of directory entry", false, $this->leader, 20, 1, $this->defaults["lengthOfLengthOfField"] );
273  $lengthOfStartingCharacterPosition = $this->checkString( "Length of Starting-Character-Position portion of directory entry", false, $this->leader, 21, 1, $this->defaults["lengthOfStartingCharacterPosition"] );
274  $lengthOfImplementationDefined = $this->checkString( "Length of Implementation-Defined portion of directory entry", false, $this->leader, 22, 1, $this->defaults["lengthOfImplementationDefined"] );
275  if( "$lengthOfLengthOfField$lengthOfStartingCharacterPosition$lengthOfImplementationDefined" !== "450" ) {
276  $this->exception( "MARC21: $lengthOfLengthOfField$lengthOfStartingCharacterPosition$lengthOfImplementationDefined != 450" );
277  $lengthOfLengthOfField = 4;
278  $lengthOfStartingCharacterPosition = 5;
279  $lengthOfImplementationDefined = 0;
280  }
281 
282  $this->indicatorLength = $indicatorLength; // advisory only
283  $this->identifierLength = $identifierLength; // required
284 
285  $lengthOfDirectoryEntry = 3 + $lengthOfLengthOfField + $lengthOfStartingCharacterPosition + $lengthOfImplementationDefined;
286 
287  if( 0 != ( ( $baseAddressOfData-25) % $lengthOfDirectoryEntry ) )
288  $this->exception( "ISO2709 4.4.1: Directory does not end on directory entry boundary ".
289  "(Directory is ". ($baseAddressOfData-25)." bytes long, " .
290  "each entry is 3 + $lengthOfLengthOfField + $lengthOfStartingCharacterPosition + $lengthOfImplementationDefined = $lengthOfDirectoryEntry bytes long, " .
291  "leaving " . (($baseAddressOfData-25)%$lengthOfDirectoryEntry) . " bytes leftover)" );
292 
293  // now read the directory
294  $fieldTypeMode = 0;
295  $lastTag = false;
296  for( $i = 24 ; $i+$lengthOfDirectoryEntry+1 <= $baseAddressOfData ; $i+= $lengthOfDirectoryEntry ) {
297  $tag = substr( $string, $i, 3 );
298 
299  $off = $this->checkString( "Start of field '$tag'", false, $string, $i+3+$lengthOfLengthOfField, $lengthOfStartingCharacterPosition );
300  if( $baseAddressOfData + $off > strlen($string) ) {
301  $off = substr( $string, $i+3+$lengthOfLengthOfField, $lengthOfStartingCharacterPosition );
302  $this->exception( "ISO2709: Offset '$off' of field '$tag' is beyond end of string. Losing this field." );
303  continue;
304  }
305  if( $string[ $baseAddressOfData + $off - 1 ] !== ISO2709::FieldTerminator ) {
306  $this->exception( "Jack: Data for field '$tag' does not immediately follow a field terminator" );
307  $off = strrpos( substr( $string, 0, $baseAddressOfData + $off ), ISO2709::FieldTerminator ) - $baseAddressOfData + 1;
308  }
309  $len = strpos( $string, ISO2709::FieldTerminator, $baseAddressOfData + $off ) - ( $baseAddressOfData + $off - 1);
310  $imp = substr( $string, $i + 3 + $lengthOfLengthOfField + $lengthOfStartingCharacterPosition, $lengthOfImplementationDefined );
311 
312  $maxFieldLen = intval( "1" .str_repeat( $lengthOfLengthOfField, "0" ) ) - 1;
313  $calclen = 0;
314  while( substr( $string, $i+3, $lengthOfLengthOfField ) === "000" ) {
315  $calclen += $maxFieldLen;
316  $i += $lengthOfDirectoryEntry;
317  $newTag = substr( $string, $i, 3 );
318  if( $tag !== $newTag ) {
319  $this->exception("ISO2709 4.4.4: When the recorded field length is 0, each following directory entry refers to the same field. However, we went from '$tag' to '$newTag'.");
320  $i -= $lengthOfDirectoryEntry;
321  break;
322  }
323  }
324  $this->checkString( "Length of field '$tag'", $len-$calclen, $string, $i+3, $lengthOfLengthOfField );
325 
326 
327  // read in the field
328  $data = substr( $string, $baseAddressOfData + $off, $len - 1 );
329  $this->AppendFieldBinary( $tag, $data, array( $tag, $len, $off, $imp ) );
330  }
331  return true;
332  }
$identifierLength
Definition: ISO2709.php:134
const RecordTerminator
Definition: ISO2709.php:121
const FieldTerminator
Definition: ISO2709.php:122
checkString( $name, $trueValue, $string, $start=0, $length=false, $default=false)
Definition: ISO2709.php:238
$indicatorLength
Definition: ISO2709.php:134
AppendFieldBinary( $tag, $data, $directoryEntry=array(), $reorder=false)
Definition: ISO2709.php:412
exception( $string)
Definition: ISO2709.php:216

◆ loadFromString()

ISO2709Record::loadFromString (   $string )

Definition at line 374 of file ISO2709.php.

374  {
375  return $this->loadFromBinaryString( $string );
376  }
loadFromBinaryString( $string, $fuzzy=true)
Definition: ISO2709.php:258

◆ ParseBinaryField()

ISO2709Record::ParseBinaryField (   $tag,
  $data,
  $directoryEntry 
)

Definition at line 384 of file ISO2709.php.

References ISO2709\SubfieldInitiator.

384  {
385  # Check for valid tag
386  $this->assertTagValid($tag);
387 
388  # Strip out indicators and subfields, handling bad data
389  # If there is a subfield identifier initiator, then everything before it is the indicators
390  # Otherwise the indicators are precisely the first indicatorLength bytes
391  if( false !== ( $subfieldStart = strpos( $data, ISO2709::SubfieldInitiator ) ) ) {
392  $indicators = substr( $data, 0, $subfieldStart );
393  $subfields = explode( ISO2709::SubfieldInitiator, substr( $data, $subfieldStart+1 ) );
394  foreach( $subfields as $k => $v ) {
395  $identifier = substr( $v, 0, $this->identifierLength - 1);
396  $subdata = substr( $v, $this->identifierLength-1 );
397  $subfields[$k] = new ISO2709Subfield( $identifier, $subdata );
398  }
399  $data = "";
400  } else {
401  if( substr( $tag, 0, 2 ) !== "00" ) {
402  $indicators = substr( $data, 0, $this->indicatorLength );
403  $data = substr( $data, $this->indicatorLength );
404  } else {
405  $indicators = "";
406  }
407  $subfields = array();
408  }
409  return new ISO2709Field( $tag, $data, $indicators, $subfields, $directoryEntry, $this );
410  }
const SubfieldInitiator
Definition: ISO2709.php:123
assertTagValid( $tag)
Definition: ISO2709.php:164

◆ removeField()

ISO2709Record::removeField (   $field )

Definition at line 462 of file ISO2709.php.

462  {
463  foreach( $this->fields as $k => $v ) {
464  if( $v === $field ) unset( $this->fields[$k] );
465  }
466  $this->fields = array_values( $this->fields );
467  }

◆ set_default()

ISO2709Record::set_default (   $name,
  $value 
)
protected

Definition at line 138 of file ISO2709.php.

138  {
139  if( !isset( $this->defaults ) ) $this->defaults=array();
140  if( !isset( $this->defaults[$name] ) ) $this->defaults[$name] = $value;
141  }

◆ setLeader()

ISO2709Record::setLeader (   $string )

Definition at line 252 of file ISO2709.php.

252  {
253  $this->leader = $string;
254  $this->indicatorLength = $this->checkString( "Indicator Length", false, $this->leader, 10, 1, $this->defaults["indicatorLength"] );
255  $this->identifierLength = $this->checkString( "Identifier Length", false, $this->leader, 11, 1, $this->defaults["identifierLength"] );
256  }
checkString( $name, $trueValue, $string, $start=0, $length=false, $default=false)
Definition: ISO2709.php:238

◆ tagOrder()

ISO2709Record::tagOrder (   $a,
  $b 
)

Definition at line 196 of file ISO2709.php.

196  {
197  if(!$this->isTagValid($a) || !$this->isTagValid($b)) return 0;
198  if( $a === $b ) return 0;
199  if( $a === "001" ) return -1;
200  if( $b === "001" ) return +1;
201  $a = substr( $a, 0, 2 );
202  $b = substr( $b, 0, 2 );
203  if( $a === $b ) return 0;
204  if( $a === "00" ) return -1;
205  if( $b === "00" ) return +1;
206  return 0;
207  }
isTagValid( $tag)
Definition: ISO2709.php:160

Member Data Documentation

◆ $defaults

ISO2709Record::$defaults
protected

Definition at line 136 of file ISO2709.php.

◆ $exceptions

ISO2709Record::$exceptions

Definition at line 132 of file ISO2709.php.

◆ $fields

ISO2709Record::$fields

Definition at line 131 of file ISO2709.php.

◆ $identifierLength

ISO2709Record::$identifierLength
protected

Definition at line 134 of file ISO2709.php.

◆ $indicatorLength

ISO2709Record::$indicatorLength

Definition at line 134 of file ISO2709.php.

◆ $leader

ISO2709Record::$leader

Definition at line 130 of file ISO2709.php.

◆ $raw

ISO2709Record::$raw

Definition at line 133 of file ISO2709.php.


The documentation for this class was generated from the following file: