"Fossies" - the Fresh Open Source Software Archive

Member "drupal-9.4.5/vendor/laminas/laminas-feed/src/Reader/Extension/AbstractFeed.php" (24 Mar 2022, 2938 Bytes) of package /linux/www/drupal-9.4.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 
    3 namespace Laminas\Feed\Reader\Extension;
    4 
    5 use DOMDocument;
    6 use DOMXPath;
    7 use Laminas\Feed\Reader;
    8 
    9 abstract class AbstractFeed
   10 {
   11     /**
   12      * Parsed feed data
   13      *
   14      * @var array
   15      */
   16     protected $data = [];
   17 
   18     /**
   19      * Parsed feed data in the shape of a DOMDocument
   20      *
   21      * @var DOMDocument
   22      */
   23     protected $domDocument;
   24 
   25     /**
   26      * The base XPath query used to retrieve feed data
   27      *
   28      * @var DOMXPath
   29      */
   30     protected $xpath;
   31 
   32     /**
   33      * The XPath prefix
   34      *
   35      * @var string
   36      */
   37     protected $xpathPrefix = '';
   38 
   39     /**
   40      * Set the DOM document
   41      *
   42      * @return $this
   43      */
   44     public function setDomDocument(DOMDocument $dom)
   45     {
   46         $this->domDocument = $dom;
   47         return $this;
   48     }
   49 
   50     /**
   51      * Get the DOM
   52      *
   53      * @return DOMDocument
   54      */
   55     public function getDomDocument()
   56     {
   57         return $this->domDocument;
   58     }
   59 
   60     /**
   61      * Get the Feed's encoding
   62      *
   63      * @return string
   64      */
   65     public function getEncoding()
   66     {
   67         return $this->getDomDocument()->encoding;
   68     }
   69 
   70     /**
   71      * Set the feed type
   72      *
   73      * @param  string $type
   74      * @return $this
   75      */
   76     public function setType($type)
   77     {
   78         $this->data['type'] = $type;
   79         return $this;
   80     }
   81 
   82     /**
   83      * Get the feed type
   84      *
   85      * If null, it will attempt to autodetect the type.
   86      *
   87      * @return string
   88      */
   89     public function getType()
   90     {
   91         $type = $this->data['type'];
   92         if (null === $type) {
   93             $type = Reader\Reader::detectType($this->getDomDocument());
   94             $this->setType($type);
   95         }
   96         return $type;
   97     }
   98 
   99     /**
  100      * Return the feed as an array
  101      *
  102      * @return array
  103      */
  104     public function toArray() // untested
  105     {
  106         return $this->data;
  107     }
  108 
  109     /**
  110      * Set the XPath query
  111      *
  112      * @return $this
  113      */
  114     public function setXpath(?DOMXPath $xpath = null)
  115     {
  116         if (null === $xpath) {
  117             $this->xpath = null;
  118             return $this;
  119         }
  120 
  121         $this->xpath = $xpath;
  122         $this->registerNamespaces();
  123         return $this;
  124     }
  125 
  126     /**
  127      * Get the DOMXPath object
  128      *
  129      * @return DOMXPath
  130      */
  131     public function getXpath()
  132     {
  133         if (null === $this->xpath) {
  134             $this->setXpath(new DOMXPath($this->getDomDocument()));
  135         }
  136 
  137         return $this->xpath;
  138     }
  139 
  140     /**
  141      * Get the XPath prefix
  142      *
  143      * @return string
  144      */
  145     public function getXpathPrefix()
  146     {
  147         return $this->xpathPrefix;
  148     }
  149 
  150     /**
  151      * Set the XPath prefix
  152      *
  153      * @param string $prefix
  154      * @return void
  155      */
  156     public function setXpathPrefix($prefix)
  157     {
  158         $this->xpathPrefix = $prefix;
  159     }
  160 
  161     /**
  162      * Register the default namespaces for the current feed format
  163      */
  164     abstract protected function registerNamespaces();
  165 }