src/SearchAPI2/ResultSetPullParser.php
public function getResultSet($cdbxml)
    {
        $items = new OfferIdentifierCollection();
        $totalItems = $cdbId = $elementName = $offerType = $resultXmlString = null;

        $resetCurrentResultValues = function () use (&$cdbId, &$elementName, &$offerType, &$resultXmlString) {
            $cdbId = null;
            $elementName = self::CDBXML_TYPE_UNKNOWN;
            $offerType = self::OFFER_TYPE_UNKNOWN;
            $resultXmlString = '';
        };

        $resetCurrentResultValues();

        $r = $this->xmlReader;
        $r->xml($cdbxml);

        while ($r->read()) {
            if ($this->xmlNodeIsNumberOfRecordsTag($r)) {
                $totalItems = new Integer((int) $r->readString());
            }

            if ($this->xmlNodeIsResultOpeningTag($r)) {
                $resultXmlString = $r->readOuterXml();
                $cdbId = $r->getAttribute('cdbid');
                $elementName = 'cdbxml.' . $r->localName;

                if ($elementName == self::CDBXML_TYPE_EVENT) {
                    $offerType = self::OFFER_TYPE_EVENT;
                }
            }

            if ($this->xmlNodeIsUdb3PlaceKeyword($r) && $elementName == self::CDBXML_TYPE_EVENT) {
                $offerType = self::OFFER_TYPE_PLACE;
            }

            if ($this->xmlNodeIsLocationCategory($r) && $elementName == self::CDBXML_TYPE_ACTOR) {
                $offerType = self::OFFER_TYPE_PLACE;
            }

            if ($this->xmlNodeIsResultClosingTag($r)) {
                if ($offerType == self::OFFER_TYPE_UNKNOWN) {
                    // Skip if we haven't been able to deduce an offer type.
                    // (Eg. actor, but without the place category.)
                    continue;
                }

                if (empty($cdbId)) {
                    // Skip if no cdbid found.
                    continue;
                }

                // Null if attribute not set, empty string if not found in the search index.
                $externalUrl = $r->getAttribute('externalurl');
                if (empty($externalUrl)) {
                    $iriGenerator = $this->fallbackIriGenerators[$offerType];
                    $externalUrl = $iriGenerator->iri($cdbId);

                    $this->logger->debug(
                        "Created fallback url for search result {$cdbId}, with cdbxml: {$resultXmlString}"
                    );
                }

                $items = $items->with(
                    new IriOfferIdentifier(
                        Url::fromNative($externalUrl),
                        $cdbId,
                        $this->getOfferTypeEnum($offerType)
                    )
                );

                $resetCurrentResultValues();
            }
        }

        return new Results($items, $totalItems);
    }
public function getResultSet($cdbxml)
    {
        $items = new OfferIdentifierCollection();
        $totalItems = $cdbId = $elementName = $offerType = $resultXmlString = null;

        $resetCurrentResultValues = function () use (&$cdbId, &$elementName, &$offerType, &$resultXmlString) {
            $cdbId = null;
            $elementName = self::CDBXML_TYPE_UNKNOWN;
            $offerType = self::OFFER_TYPE_UNKNOWN;
            $resultXmlString = '';
        };

        $resetCurrentResultValues();

        $r = $this->xmlReader;
        $r->xml($cdbxml);

        while ($r->read()) {
            if ($this->xmlNodeIsNumberOfRecordsTag($r)) {
                $totalItems = new Integer((int) $r->readString());
            }

            if ($this->xmlNodeIsResultOpeningTag($r)) {
                $resultXmlString = $r->readOuterXml();
                $cdbId = $r->getAttribute('cdbid');
                $elementName = 'cdbxml.' . $r->localName;

                if ($elementName == self::CDBXML_TYPE_EVENT) {
                    $offerType = self::OFFER_TYPE_EVENT;
                }
            }

            if ($this->xmlNodeIsUdb3PlaceKeyword($r) && $elementName == self::CDBXML_TYPE_EVENT) {
                $offerType = self::OFFER_TYPE_PLACE;
            }

            if ($this->xmlNodeIsLocationCategory($r) && $elementName == self::CDBXML_TYPE_ACTOR) {
                $offerType = self::OFFER_TYPE_PLACE;
            }

            if ($this->xmlNodeIsResultClosingTag($r)) {
                if ($offerType == self::OFFER_TYPE_UNKNOWN) {
                    // Skip if we haven't been able to deduce an offer type.
                    // (Eg. actor, but without the place category.)
                    continue;
                }

                if (empty($cdbId)) {
                    // Skip if no cdbid found.
                    continue;
                }

                // Null if attribute not set, empty string if not found in the search index.
                $externalUrl = $r->getAttribute('externalurl');
                if (empty($externalUrl)) {
                    $iriGenerator = $this->fallbackIriGenerators[$offerType];
                    $externalUrl = $iriGenerator->iri($cdbId);

                    $this->logger->debug(
                        "Created fallback url for search result {$cdbId}, with cdbxml: {$resultXmlString}"
                    );
                }

                $items = $items->with(
                    new IriOfferIdentifier(
                        Url::fromNative($externalUrl),
                        $cdbId,
                        $this->getOfferTypeEnum($offerType)
                    )
                );

                $resetCurrentResultValues();
            }
        }

        return new Results($items, $totalItems);
    }
public function getResultSet ( $ cdbxml ) { $ items = new OfferIdentifierCollection ( ) ; $ totalItems = $ cdbId = $ elementName = $ offerType = $ resultXmlString = null ; $ resetCurrentResultValues = function ( ) use ( & $ cdbId , & $ elementName , & $ offerType , & $ resultXmlString ) { $ cdbId = null ; $ elementName = self :: CDBXML_TYPE_UNKNOWN ; $ offerType = self :: OFFER_TYPE_UNKNOWN ; $ resultXmlString = '' ; } ; $ resetCurrentResultValues ( ) ; $ r = $ this -> xmlReader ; $ r -> xml ( $ cdbxml ) ; while ( $ r -> read ( ) ) { if ( $ this -> xmlNodeIsNumberOfRecordsTag ( $ r ) ) { $ totalItems = new Integer ( ( int ) $ r -> readString ( ) ) ; } if ( $ this -> xmlNodeIsResultOpeningTag ( $ r ) ) { $ resultXmlString = $ r -> readOuterXml ( ) ; $ cdbId = $ r -> getAttribute ( 'cdbid' ) ; $ elementName = 'cdbxml.' . $ r -> localName ; if ( $ elementName == self :: CDBXML_TYPE_EVENT ) { $ offerType = self :: OFFER_TYPE_EVENT ; } } if ( $ this -> xmlNodeIsUdb3PlaceKeyword ( $ r ) && $ elementName == self :: CDBXML_TYPE_EVENT ) { $ offerType = self :: OFFER_TYPE_PLACE ; } if ( $ this -> xmlNodeIsLocationCategory ( $ r ) && $ elementName == self :: CDBXML_TYPE_ACTOR ) { $ offerType = self :: OFFER_TYPE_PLACE ; } if ( $ this -> xmlNodeIsResultClosingTag ( $ r ) ) { if ( $ offerType == self :: OFFER_TYPE_UNKNOWN ) { // Skip if we haven't been able to deduce an offer type. // (Eg. actor, but without the place category.) continue ; } if ( empty ( $ cdbId ) ) { // Skip if no cdbid found. continue ; } // Null if attribute not set, empty string if not found in the search index. $ externalUrl = $ r -> getAttribute ( 'externalurl' ) ; if ( empty ( $ externalUrl ) ) { $ iriGenerator = $ this -> fallbackIriGenerators [ $ offerType ] ; $ externalUrl = $ iriGenerator -> iri ( $ cdbId ) ; $ this -> logger -> debug ( "Created fallback url for search result {$cdbId}, with cdbxml: {$resultXmlString}" ) ; } $ items = $ items -> with ( new IriOfferIdentifier ( Url :: fromNative ( $ externalUrl ) , $ cdbId , $ this -> getOfferTypeEnum ( $ offerType ) ) ) ; $ resetCurrentResultValues ( ) ; } } return new Results ( $ items , $ totalItems ) ; }
Creates a result set.

@param string $cdbxml
The CDBXML-formatted search results.

@return Results
Creates a result set .