Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 public function testDelete()
 {
     $r = new AuthorityRecord();
     $r->append(new Field('003@', 0, array(new Subfield('0', 'valid'))));
     $this->assertFalse($r->isEmpty());
     $r->delete(Field::match('..../..'));
     $this->assertTrue($r->isEmpty());
 }
Exemplo n.º 3
0
 public function testDeletePropagatesDown()
 {
     $r = new LocalRecord();
     $c = new CopyRecord(array(new Field('200@', 11)));
     $r->addCopyRecord($c);
     $this->assertFalse($c->isEmpty());
     $r->delete(Field::match('200@/11'));
     $this->assertTrue($c->isEmpty());
 }
Exemplo n.º 4
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.º 5
0
 /**
  * Return fields of the record.
  *
  * @see Record::getFields()
  *
  * @param  string $selector Body of regular expression
  * @return array Fields
  */
 public function getFields($selector = null)
 {
     if ($selector === null) {
         return array_merge($this->_fields, Helper::flatten(Helper::mapMethod($this->_records, 'getFields')));
     } else {
         return $this->select(Field::match($selector));
     }
 }
Exemplo n.º 6
0
 /**
  * Return fields of the record.
  *
  * Optional argument $selector is the body of a regular expression. If set,
  * this function returns only fields whose shorthand is matched by the
  * regular expression.
  *
  * @see Field::match()
  *
  * @param  string $selector Body of regular expression
  * @return array Fields
  */
 public function getFields($selector = null)
 {
     if ($selector === null) {
         return $this->_fields;
     } else {
         return $this->select(Field::match($selector));
     }
 }
Exemplo n.º 7
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testRemoveSubfieldThrowsExceptionOnNonExistentField()
 {
     $f = new Field('003@', 0);
     $s = new Subfield('a', 'valid');
     $f->removeSubfield($s);
 }