Пример #1
0
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException
  * @throws InvalidMARCspecException
  */
 public function __construct($subfieldspec = null)
 {
     if (is_null($subfieldspec)) {
         return;
     }
     if (!is_string($subfieldspec)) {
         throw new \InvalidArgumentException('Method only accepts string as argument. ' . gettype($subfieldspec) . ' given.');
     }
     $argLength = strlen($subfieldspec);
     if (0 === $argLength) {
         throw new InvalidMARCspecException(InvalidMARCspecException::SF . InvalidMARCspecException::MISSINGTAG, $subfieldspec);
     }
     if (1 == $argLength) {
         $subfieldspec = '$' . $subfieldspec;
     }
     if (1 < $argLength) {
         if ('-' == $subfieldspec[1]) {
             // assuming subfield range
             throw new InvalidMARCspecException(InvalidMARCspecException::SF . InvalidMARCspecException::SFRANGE, $subfieldspec);
         }
     }
     if (preg_match('/\\{.*\\}$/', $subfieldspec)) {
         throw new InvalidMARCspecException(InvalidMARCspecException::SF . InvalidMARCspecException::DETECTEDSS, $subfieldspec);
     }
     $parser = new MARCspecParser();
     $subfield = $parser->subfieldToArray($subfieldspec);
     $this->setTag($subfield['subfieldtag']);
     if (array_key_exists('index', $subfield)) {
         $_pos = MARCspec::validatePos($subfield['index']);
         $this->setIndexStartEnd($_pos[0], $_pos[1]);
     } else {
         // as of MARCspec 3.2.2 spec without index is always an abbreviation
         $this->setIndexStartEnd(0, '#');
     }
     if (array_key_exists('charpos', $subfield)) {
         $_chars = MARCspec::validatePos($subfield['charpos']);
         $this->setCharStartEnd($_chars[0], $_chars[1]);
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  *
  * @throws InvalidMARCspecException
  */
 public function __construct($fieldspec = null)
 {
     if (is_null($fieldspec)) {
         return;
     }
     $this->checkIfString($fieldspec);
     $spec = trim($fieldspec);
     $specLength = strlen($fieldspec);
     // check string length
     if (3 > $specLength) {
         throw new InvalidMARCspecException(InvalidMARCspecException::FS . InvalidMARCspecException::MINIMUM3, $fieldspec);
     }
     if (preg_match('/\\s/', $fieldspec)) {
         throw new InvalidMARCspecException(InvalidMARCspecException::FS . InvalidMARCspecException::SPACE, $fieldspec);
     }
     if ($strpos = strpos('{', $fieldspec)) {
         throw new InvalidMARCspecException(InvalidMARCspecException::FS . InvalidMARCspecException::DETECTEDSS, $fieldspec);
     }
     $parser = new MARCspecParser();
     $parser->fieldToArray($fieldspec);
     if (array_key_exists('subfields', $parser->parsed)) {
         throw new InvalidMARCspecException(InvalidMARCspecException::FS . InvalidMARCspecException::DETECTEDSF, $fieldspec);
     }
     $this->setTag($parser->field['tag']);
     if (array_key_exists('index', $parser->field)) {
         $_pos = MARCspec::validatePos($parser->field['index']);
         $this->setIndexStartEnd($_pos[0], $_pos[1]);
     } else {
         // as of MARCspec 3.2.2 spec without index is always an abbreviation
         $this->setIndexStartEnd(0, '#');
     }
     if (array_key_exists('indicators', $parser->field)) {
         $this->setIndicators($parser->field['indicators']);
     } elseif (array_key_exists('charpos', $parser->field)) {
         $_chars = MARCspec::validatePos($parser->field['charpos']);
         $this->setCharStartEnd($_chars[0], $_chars[1]);
     }
 }
Пример #3
0
 /**
  * {@inheritdoc}
  *
  * @throws InvalidMARCspecException
  */
 public function addSubfields($subfields)
 {
     if ($subfields instanceof SubfieldInterface) {
         $this->subfields[] = $subfields;
     } else {
         $this->checkIfString($subfields);
         if (2 > strlen($subfields)) {
             throw new InvalidMARCspecException(InvalidMARCspecException::SF . InvalidMARCspecException::LENGTH . InvalidSubfieldspecException::MINIMUM2, $subfields);
         }
         if ('$' !== $subfields[0]) {
             throw new InvalidMARCspecException(InvalidMARCspecException::SF . InvalidSubfieldspecException::PREFIX, $subfields);
         }
         $parser = new MARCspecParser();
         $_subfieldSpecs = $parser->matchSubfields($subfields);
         foreach ($_subfieldSpecs as $subfieldSpec) {
             $this->addSubfield($subfieldSpec);
         }
     }
 }