src/Extractor/ContentExtractor.php
private function extractEntityFromQuery($entity, $detectEntity, $xpathExpression, \DOMNode $node, $logMessage, $returnCallback = null)
    {
        if (false === $detectEntity) {
            return false;
        }

        // we define the default callback here
        if (!\is_callable($returnCallback)) {
            $returnCallback = function ($element) {
                return trim($element);
            };
        }

        // check for given css class
        // shut up operator as there is no pre-validation possible.
        $elems = @$this->xpath->query($xpathExpression, $node);

        if (false === $elems || false === $this->hasElements($elems)) {
            return true;
        }

        $this->{$entity} = $returnCallback(
            $elems->item(0)->textContent,
            $this->{$entity}
        );
        $this->logger->info($logMessage, [$entity => $this->{$entity}]);

        // remove entity from document
        try {
            $elems->item(0)->parentNode->removeChild($elems->item(0));
        } catch (\DOMException $e) {
            // do nothing
        }

        return false;
    }
private function extractEntityFromQuery($entity, $detectEntity, $xpathExpression, \DOMNode $node, $logMessage, $returnCallback = null)
    {
        if (false === $detectEntity) {
            return false;
        }

        // we define the default callback here
        if (!\is_callable($returnCallback)) {
            $returnCallback = function ($element) {
                return trim($element);
            };
        }

        // check for given css class
        // shut up operator as there is no pre-validation possible.
        $elems = @$this->xpath->query($xpathExpression, $node);

        if (false === $elems || false === $this->hasElements($elems)) {
            return true;
        }

        $this->{$entity} = $returnCallback(
            $elems->item(0)->textContent,
            $this->{$entity}
        );
        $this->logger->info($logMessage, [$entity => $this->{$entity}]);

        // remove entity from document
        try {
            $elems->item(0)->parentNode->removeChild($elems->item(0));
        } catch (\DOMException $e) {
            // do nothing
        }

        return false;
    }
private function extractEntityFromQuery ( $ entity , $ detectEntity , $ xpathExpression , \ DOMNode $ node , $ logMessage , $ returnCallback = null ) { if ( false === $ detectEntity ) { return false ; } // we define the default callback here if ( ! \ is_callable ( $ returnCallback ) ) { $ returnCallback = function ( $ element ) { return trim ( $ element ) ; } ; } // check for given css class // shut up operator as there is no pre-validation possible. $ elems = @ $ this -> xpath -> query ( $ xpathExpression , $ node ) ; if ( false === $ elems || false === $ this -> hasElements ( $ elems ) ) { return true ; } $ this -> { $ entity } = $ returnCallback ( $ elems -> item ( 0 ) -> textContent , $ this -> { $ entity } ) ; $ this -> logger -> info ( $ logMessage , [ $ entity => $ this -> { $ entity } ] ) ; // remove entity from document try { $ elems -> item ( 0 ) -> parentNode -> removeChild ( $ elems -> item ( 0 ) ) ; } catch ( \ DOMException $ e ) { // do nothing } return false ; }
Extract entity for a given CSS class a node.

The $entity argument is used as the name of the property to set in
the current ContentExtractor instance (variable reference) and as
the name to use in log messages

Example: extractEntityFromQuery('title', $detectEntity, $xpathExpression, $node, $log, $returnCallback)
will search for expression and set the found value in $this->title

@param string   $entity          Entity to look for ('title', 'date')
@param bool     $detectEntity    Do we have to detect entity?
@param string   $xpathExpression XPath query to look for
@param \DOMNode $node            DOMNode to look into
@param string   $logMessage
@param \Closure $returnCallback  Function to cleanup the current value found

@return bool Telling if we have to detect entity again or not
Extract entity for a given CSS class a node .