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

Public Member Functions

  __construct ( $input, $numCache=10)
 
  offsetExists ( $offset)
 
  offsetGet ( $offset)
 
  offsetSet ( $offset, $value)
 
  offsetUnset ( $offset)
 

Protected Attributes

  $input
 
  $records
 
  $numRecords
 
  $cache
 
  $recordOffsets
 
  $numCache
 
  $recordClass
 

Detailed Description

Definition at line 51 of file ISO2709.php.

Constructor & Destructor Documentation

◆ __construct()

ISO2709RecordSetArray::__construct (   $input,
  $numCache = 10 
)

Definition at line 54 of file ISO2709.php.

54 {
55 if( is_string( $input ) ) $input = fopen( $input, "rb" );
56 if( !is_resource( $input ) ) throw new Exception("ISO2709RecordSetArray requires a file resource, filename, or URL to be created");
57 $this->input = $input;
58 $this->records = array();
59 $this->cache = array();
60 $this->recordOffsets = array();
61 $this->recordOffsets[0] = 0;
62 $this->numCache = $numCache;
63 $this->recordClass = "ISO2709Record";
64 }

References $input, and $numCache.

Member Function Documentation

◆ offsetExists()

ISO2709RecordSetArray::offsetExists (   $offset )

Definition at line 66 of file ISO2709.php.

66 {
67 if(!is_int($offset) or $offset < 0 or ($this->numRecords !== null and $this->numRecords <= $offset))
68 return false;
69 return $this->offsetGet( $offset ) === false;
70 }
offsetGet( $offset)
Definition: ISO2709.php:72

References offsetGet().

◆ offsetGet()

ISO2709RecordSetArray::offsetGet (   $offset )

Definition at line 72 of file ISO2709.php.

72 {
73 # Update cache
74 foreach( array_keys( $this->cache, $offset ) as $k ) { unset($this->cache[$k]); }
75 $this->cache = array_values( $this->cache );
76 array_push( $this->cache, $offset );
77 while( count( $this->cache ) > $this->numCache ) {
78 $k = array_shift( $this->cache );
79 unset( $this->records[$k] );
80 }
81 # Now get the record
82 if( !isset( $this->records[ $offset ] ) ) {
83 if( !isset( $this->recordOffsets[$offset] ) ) {
84 for( $i = $offset - 1 ; $i > 0 ; $i-- ) {
85 if( isset( $this->recordOffsets[$i] ) ) break;
86 }
87 fseek( $this->input, $this->recordOffsets[$i], SEEK_SET );
88 while( $i < $offset ) {
89 stream_get_line( $this->input, 99999, ISO2709::RecordTerminator );
90 $i++;
91 $this->recordOffsets[ $i ] = ftell( $this->input );
92 }
93 } else {
94 fseek( $this->input, $this->recordOffsets[$offset], SEEK_SET );
95 }
96 $this->records[ $offset ] = new $this->recordClass();
97 $this->records[ $offset ]->loadFromBinaryStream( $this->input );
98 if(feof($this->input)) {
99 $this->numRecords = $offset+1;
100 } else {
101 $this->recordOffsets[$offset+1] = ftell( $this->input );
102 }
103 }
104 return $this->records[ $offset ];
105 }
const RecordTerminator
Definition: ISO2709.php:121

References ISO2709\RecordTerminator.

Referenced by offsetExists().

◆ offsetSet()

ISO2709RecordSetArray::offsetSet (   $offset,
  $value 
)

Definition at line 107 of file ISO2709.php.

107 {
108 throw new Exception( "This type of record set is read-only, sorry" );
109 }

◆ offsetUnset()

ISO2709RecordSetArray::offsetUnset (   $offset )

Definition at line 111 of file ISO2709.php.

111 {
112 throw new Exception( "This type of record set is read-only, sorry" );
113 }

Member Data Documentation

◆ $cache

ISO2709RecordSetArray::$cache
protected

Definition at line 52 of file ISO2709.php.

◆ $input

ISO2709RecordSetArray::$input
protected

Definition at line 52 of file ISO2709.php.

Referenced by MARC21RecordSetArray\__construct(), and __construct().

◆ $numCache

ISO2709RecordSetArray::$numCache
protected

Definition at line 52 of file ISO2709.php.

Referenced by __construct().

◆ $numRecords

ISO2709RecordSetArray::$numRecords
protected

Definition at line 52 of file ISO2709.php.

◆ $recordClass

ISO2709RecordSetArray::$recordClass
protected

Definition at line 52 of file ISO2709.php.

◆ $recordOffsets

ISO2709RecordSetArray::$recordOffsets
protected

Definition at line 52 of file ISO2709.php.

◆ $records

ISO2709RecordSetArray::$records
protected

Definition at line 52 of file ISO2709.php.


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