Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testFactoryThrowsExceptionOnMissingTypeSubfield()
 {
     $record = Record::factory(array('fields' => array(array('tag' => '002@', 'occurrence' => 0, 'subfields' => array()))));
 }
Exemplo n.º 3
0
 /**
  * Return true if the record is valid.
  *
  * A nested record is valid iff it and all contained records are valid.
  *
  * @see Record::isValid()
  *
  * @return boolean
  */
 public function isValid()
 {
     return parent::isValid() && !Helper::every($this->_records, function (Record $record) {
         return $record->isValid();
     });
 }
Exemplo n.º 4
0
 /**
  * Return next record in input data or FALSE if no more records.
  *
  * This function uses the Record::factory() method to create a record and
  * applies a possible filter function to the input data.
  *
  * @see Reader::setFilter()
  * @see Record::factory()
  *
  * @throws RuntimeException Error creating a record instance via factory function
  * @return Record|false
  */
 public function read()
 {
     $record = $this->next();
     if (is_array($record)) {
         $record = $this->applyFilter($record);
         if (is_array($record)) {
             try {
                 return Record::factory($record);
             } catch (Exception $e) {
                 throw new RuntimeException("Error creating record instance in Record::factory()", -1, $e);
             }
         }
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * 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();
 }
Exemplo n.º 6
0
 /**
  * Compare two local records.
  *
  * @see NestedRecord::compareRecords()
  *
  * Local records are compared by their ILN.
  *
  * @param  Record $a First record
  * @param  Record $b Second record
  * @return Comparism value
  */
 protected function compareRecords(Record $a, Record $b)
 {
     return $a->getILN() - $b->getILN();
 }