public function parseSubfields($subfieldspec)
    {
        if (!preg_match_all('/'.$this->SUBFIELD.'/', $subfieldspec, $_subfieldMatches, PREG_SET_ORDER)) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::SFCHAR,
                $subfieldspec
            );
        }
        /*
        * For each subfield (array) do anonymous function
        * - first filter empty elements
        * - second look for subspecs
        * - match subspecs and match subTerms
        * - return everything in the array of subfields
        */
        array_walk(
            $_subfieldMatches,
            function (&$_subfield) use (&$test) {
                $_subfield = array_filter($_subfield, 'strlen');

                $test .= $_subfield['subfield'];

                if (array_key_exists('subspecs', $_subfield)) {
                    $_ss = [];

                    if (!$_subfieldSubSpecs = $this->matchSubSpecs($_subfield['subspecs'])) {
                        // TODO: raise error;
                    }

                    foreach ($_subfieldSubSpecs as $key => $_subfieldSubSpec) {
                        if (1 < count($_subfieldSubSpec)) {
                            foreach ($_subfieldSubSpec as $orSubSpec) {
                                $_or[] = $this->matchSubTerms($orSubSpec);
                            }
                            $_ss[] = $_or;
                        } else {
                            $_ss[] = $this->matchSubTerms($_subfieldSubSpec[0]);
                        }
                    }

                    $_subfield['subspecs'] = $_ss;
                }
            }
        );

        if ($test !== $subfieldspec) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::USELESS,
                $subfieldspec
            );
        }

        return $_subfieldMatches;
    }
public function parseSubfields($subfieldspec)
    {
        if (!preg_match_all('/'.$this->SUBFIELD.'/', $subfieldspec, $_subfieldMatches, PREG_SET_ORDER)) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::SFCHAR,
                $subfieldspec
            );
        }
        /*
        * For each subfield (array) do anonymous function
        * - first filter empty elements
        * - second look for subspecs
        * - match subspecs and match subTerms
        * - return everything in the array of subfields
        */
        array_walk(
            $_subfieldMatches,
            function (&$_subfield) use (&$test) {
                $_subfield = array_filter($_subfield, 'strlen');

                $test .= $_subfield['subfield'];

                if (array_key_exists('subspecs', $_subfield)) {
                    $_ss = [];

                    if (!$_subfieldSubSpecs = $this->matchSubSpecs($_subfield['subspecs'])) {
                        // TODO: raise error;
                    }

                    foreach ($_subfieldSubSpecs as $key => $_subfieldSubSpec) {
                        if (1 < count($_subfieldSubSpec)) {
                            foreach ($_subfieldSubSpec as $orSubSpec) {
                                $_or[] = $this->matchSubTerms($orSubSpec);
                            }
                            $_ss[] = $_or;
                        } else {
                            $_ss[] = $this->matchSubTerms($_subfieldSubSpec[0]);
                        }
                    }

                    $_subfield['subspecs'] = $_ss;
                }
            }
        );

        if ($test !== $subfieldspec) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::USELESS,
                $subfieldspec
            );
        }

        return $_subfieldMatches;
    }
public function parseSubfields ( $ subfieldspec ) { if ( ! preg_match_all ( '/' . $ this -> SUBFIELD . '/' , $ subfieldspec , $ _subfieldMatches , PREG_SET_ORDER ) ) { throw new InvalidMARCspecException ( InvalidMARCspecException :: SF . InvalidMARCspecException :: SFCHAR , $ subfieldspec ) ; } /*
        * For each subfield (array) do anonymous function
        * - first filter empty elements
        * - second look for subspecs
        * - match subspecs and match subTerms
        * - return everything in the array of subfields
        */ array_walk ( $ _subfieldMatches , function ( & $ _subfield ) use ( & $ test ) { $ _subfield = array_filter ( $ _subfield , 'strlen' ) ; $ test .= $ _subfield [ 'subfield' ] ; if ( array_key_exists ( 'subspecs' , $ _subfield ) ) { $ _ss = [ ] ; if ( ! $ _subfieldSubSpecs = $ this -> matchSubSpecs ( $ _subfield [ 'subspecs' ] ) ) { // TODO: raise error; } foreach ( $ _subfieldSubSpecs as $ key => $ _subfieldSubSpec ) { if ( 1 < count ( $ _subfieldSubSpec ) ) { foreach ( $ _subfieldSubSpec as $ orSubSpec ) { $ _or [ ] = $ this -> matchSubTerms ( $ orSubSpec ) ; } $ _ss [ ] = $ _or ; } else { $ _ss [ ] = $ this -> matchSubTerms ( $ _subfieldSubSpec [ 0 ] ) ; } } $ _subfield [ 'subspecs' ] = $ _ss ; } } ) ; if ( $ test !== $ subfieldspec ) { throw new InvalidMARCspecException ( InvalidMARCspecException :: SF . InvalidMARCspecException :: USELESS , $ subfieldspec ) ; } return $ _subfieldMatches ; }
Matches subfieldspecs.

@param string $subfieldspec A string of one or more subfieldspecs
Matches subfieldspecs .